Compare commits
2 Commits
e3a184aa63
...
088fdb2b16
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
088fdb2b16 | ||
|
|
2c81a2c3de |
@@ -11,6 +11,7 @@ use HTTP::Cookies;
|
||||
use Digest::SHA qw(sha1_hex);
|
||||
use Time::HiRes qw(time);
|
||||
use Unicode::Normalize;
|
||||
use Encode 'encode_utf8', 'is_utf8';
|
||||
use locale;
|
||||
|
||||
use YTMusicAPI::Constants qw(YTM_DOMAIN USER_AGENT);
|
||||
@@ -47,7 +48,9 @@ sub get_visitor_id {
|
||||
my $visitor_id = "";
|
||||
|
||||
if (@matches) {
|
||||
my $ytcfg = decode_json( $matches[0] );
|
||||
my $encoded_match =
|
||||
is_utf8( $matches[0] ) ? encode_utf8( $matches[0] ) : $matches[0];
|
||||
my $ytcfg = decode_json($encoded_match);
|
||||
$visitor_id = $ytcfg->{"VISITOR_DATA"} // "";
|
||||
}
|
||||
|
||||
|
||||
45
YTMusicAPI/Mixins/BrowsingMixin.pm
Normal file
45
YTMusicAPI/Mixins/BrowsingMixin.pm
Normal file
@@ -0,0 +1,45 @@
|
||||
package YTMusicAPI::Mixins::BrowsingMixin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
use YTMusicAPI::Helpers;
|
||||
use YTMusicAPI::Navigation;
|
||||
use YTMusicAPI::Parsers::Browsing;
|
||||
use YTMusicAPI::Continuations;
|
||||
|
||||
sub get_song {
|
||||
my ( $self, $video_id, $signature_timestamp ) = @_;
|
||||
|
||||
my $endpoint = "player";
|
||||
if ( !$signature_timestamp ) {
|
||||
$signature_timestamp = time() - 1;
|
||||
}
|
||||
|
||||
my $params = {
|
||||
"playbackContext" => {
|
||||
"contentPlaybackContext" =>
|
||||
{ "signatureTimestamp" => $signature_timestamp }
|
||||
},
|
||||
"video_id" => $video_id,
|
||||
};
|
||||
|
||||
my $response = $self->_send_request( $endpoint, $params );
|
||||
my @keys = (
|
||||
"videoDetails", "playabilityStatus",
|
||||
"streamingData", "microformat",
|
||||
"playbackTracking"
|
||||
);
|
||||
|
||||
foreach my $k ( keys %$response ) {
|
||||
unless ( grep { $_ eq $k } @keys ) {
|
||||
delete $response->{$k};
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -6,6 +6,7 @@ use warnings;
|
||||
use Moose;
|
||||
|
||||
with
|
||||
'YTMusicAPI::Mixins::BrowsingMixin',
|
||||
'YTMusicAPI::Mixins::SearchMixin',
|
||||
'YTMusicAPI::Mixins::PlaylistMixin';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user