Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # Script uses track's on air name saved in /tmp/nowplaying.log' by my "Python radio title
- # parser" - http://pastebin.com/1tZRnQgD
- use HTML::TreeBuilder::XPath;
- use LWP::UserAgent;
- use URI::Encode;
- open FILE, "/tmp/nowplaying.log" or die $!;
- my $track_name = <FILE>;
- print "Now on air: $track_name\n";
- $track_name =~ s/\ /+/g;
- my $uri = URI::Encode->new( { encode_reserved => 0 } );
- my $ua = LWP::UserAgent->new(agent => "Mozilla/5.0");
- my $req = HTTP::Request->new(GET => 'https://www.google.com.ua/search?hl=en&q='.$track_name);
- my $res = $ua->request($req);
- my $tree = HTML::TreeBuilder::XPath->new_from_content($res->content);
- foreach my $titles ($tree->findnodes(q{//li/table/tr/td/h3/a})) {
- $i++;
- #print "\n+++ $i Tile: ";
- #print $titles->as_text;
- $title[$i] = $titles->as_text;
- }
- $i=0;
- foreach my $times ($tree->findnodes(q{//li/table/tr/td/div/a/div[not (img)]})) {
- $i++;
- #print " Time: ";
- #print $times->as_text;
- $timer = $times->as_text;
- @timer = split(/ /, $timer);
- $time[$i] = $timer[1];
- }
- $i=0;
- foreach my $links ($tree->findnodes(q{//li/table/tr/td/h3/a/@href})) {
- $i++;
- $link_raw = $links->getValue;
- $link_dec = $uri->decode($link_raw);
- @link_dec = split(/\?v=/,$link_dec);
- @link_dec = split(/&sa/,$link_dec[1]);
- print $link_dec[0];
- $link[$i] = "http://www.youtube.com/watch?v=".$link_dec[0];
- }
- $i=0;
- $tree->delete;
- print "\n0 -> Open in browser for searching...\n";
- foreach (@title){
- $i++;
- if ($title[$i]){
- print "\n$i -> $title[$i], $time[$i]\n $link[$i] \n";
- }
- }
- print "\nSelect number of track to download:\n";
- $select = <STDIN>;
- chomp ($select);
- if ($select eq "0") {
- system('/usr/bin/google-chrome --user-data-dir=/home/admin/ "https://www.google.com.ua/search?hl=en&q='.$track_name.'" 2>/dev/null');
- exit;
- }
- if (!$select or $select >= $i or $select !~ m/\d/ ){
- print "\nWrong number. Exiting...\n";
- exit;
- } else {
- system('cd /ftp && /usr/sbin/youtube-dl -t --extract-audio --audio-format=mp3 '.$link[$select]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement