#!/usr/bin/perl # # playgoear.pl # A Perl Player for GoEar # (C) Alvaro Marin, , 24 Jun 2007 # # # Redistributable under the terms of the GPL - see # # # playgoear is a command line interface to access # to mp3 streams of goear.com without the flash player # of it's web. # With playgoear and using the username and password # of goear.com, you can listen the songs of your # favorite list on your machine without the web browser # and you can use the randomly playing mode, continuosly...etc. # Now you can download your favorite music too! # # playgoear.pl uses mplayer to play mp3 streams! # # # v0.4 - 26 Mar 2008 - Added checks to see if required Perl modules are installed # # v0.3 - 16 Jul 2007 - Added to mplayer the buffer/cache option to # avoid interrupts when the song is played. # # Added "i" option to see the information of a song: # # Song number to listen or option: i 40 # # Title: Iron Lion Zion - Bob Marley # URL: http://www.goear.com/listen.php?v=f67de6b # MP3: http://www.goear.com/files/sst/ace162817a76f1701daca2a245e4b9ca.mp3 # # v0.2 - 27 Jun 2007 - Added support to download the mp3 file with # "d N" command where "N" is the number of the song. # For example: # # ... # 17: I Should Have Known Better - The Skatalites # r) Play Randomly # c) Play Continuosly # d) Download: "d 5" downloads the 5th song # "d ALL" downloads all the favorite list # e) Exit # Song number to listen or option: d 17 # Downloading "I Should Have Known Better - The Skatalites" in background... # # This option uses wget command to download it and stores # the mp3 file in the directory where playgoear.pl is executed. # # v0.1 - 24 Jun 2007 - First release :) # # ########################################## # Put here your GoEar's user and password: my $goear_user = "username"; my $goear_pass = "password"; ########################################## use Switch; use warnings; eval 'use LWP::UserAgent'; if ($@) { print "ERROR: LWP::UserAgent Perl module is required!\n"; print "Install it executing: \n perl -MCPAN -e 'install LWP::UserAgent'\n"; exit; } eval 'use HTTP::Request'; if ($@) { print "ERROR: HTTP::Request Perl module is required!\n"; print "Install it executing: \n perl -MCPAN -e 'install HTTP::Request'\n"; exit; } eval 'use HTTP::Cookies'; if ($@) { print "ERROR: HTTP::Cookies Perl module is required!\n"; print "Install it executing: \n perl -MCPAN -e 'install HTTP::Cookies'\n"; exit; } eval 'use DBI'; if ($@) { print "ERROR: DBI Perl module is required!\n"; print "Install it executing: \n perl -MCPAN -e 'install DBI'\n"; exit; } eval 'use DBD::SQLite'; if ($@) { print "ERROR: DBD::SQLite Perl module is required!\n"; print "Install it executing: \n perl -MCPAN -e 'install DBD::SQLite'\n"; exit; } my $mplayer="nice -20 mplayer -really-quiet -cache 1024 -cache-min 80"; my $download=""; foreach $argnum (0 .. $#ARGV) { switch ($ARGV[$argnum]) { case "-h" { print "\nplaygoear.pl - A Perl Player for GoEar.com - v0.3\n"; print " Alvaro Marin, , 16 Jul 2007\n\n"; print "Usage: ./playgoear.pl [-d|-s]\n"; print " -d : download the favorite list using user and password\n"; print " configured in the first lines of playgoear.pl.\n"; print " -s : use the saved favorite list and don't connect to GoEar.com.\n\n"; print "playgoear.pl uses mplayer to play the mp3 streams, so install it :)\n\n"; exit; } case "-d" { $download = "y"; } case "-s" { $download = "n"; } } } # We store the favorite list and the location of each song my $dbfile = ".goear.db"; my $dbh; # Capture signals to close database $SIG{'INT' } = 'interrupt'; $SIG{'QUIT'} = 'interrupt'; $SIG{'HUP' } = 'interrupt'; $SIG{'TRAP'} = 'interrupt'; $SIG{'ABRT'} = 'interrupt'; $SIG{'STOP'} = 'interrupt'; sub interrupt { my($signal)=@_; print "Ok, now exiting...\n"; $dbh->disconnect; print "Bye bye...\n"; exit(1); } # Is .goear.db file created? if ( ! -f ".goear.db"){ print "Creating .goear.db...\n"; $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","", {}) or die("ERROR creating .goear.db file. Check permissions or disk space.\n"); $dbh->do("CREATE TABLE songs (id INTEGER AUTO_INCREMENT PRIMARY KEY, goear_id VARCHAR(10), title VARCHAR(200), path varchar(200))"); print "Good, .goear.db has been created. Connected.\n"; } else { $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","", {}) or die("ERROR opening .goear.db file. Check permissions or disk space.\n"); print "Good, .goear.db exists. Connected.\n"; } # if has been passed an option if ($download eq "" ){ print "Do you want to download again the favorite list? (y/n): "; $download=; chomp($download); } # we have to connecto to goear.com and download the favorite list if ($download eq "y") { print "Connecting to GoEar.com with username \"".$goear_user."\" and downloading the favorite list...\n"; my $sth = $dbh->prepare("DELETE from songs where 1=1"); $sth->execute(); my $goear_url = "http://www.goear.com/loged.php"; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4)"); my $referer = "http://www.goear.com/login.php"; $ua->cookie_jar( HTTP::Cookies->new( 'file' => '/tmp/cookies.lwp', 'autosave' => 1, )); my $req = HTTP::Request->new(POST => 'http://www.goear.com/loged.php'); $req->content_type('application/x-www-form-urlencoded'); $req->content("user=$goear_user&pwd=$goear_pass"); my $res = $ua->request($req); my $goear_favorites = "http://www.goear.com/members/myFavorites.php"; my $response = $ua->get( $goear_favorites ); if ($response->is_success) { my @lines = split ("\n",$response->content); $sth = $dbh->prepare("INSERT INTO songs (id,goear_id,title,path) values (?,?,?,?)"); $i=0; foreach (@lines){ if ( /listen\.php/){ my @lines2=split("href",$_); foreach (@lines2){ if ( /listen\.php\?v=([0-9a-zA-Z]{7})>(.*)\<\/a\>/){ $url_aux="http://www.goear.com/files/sst/secm$1.xml"; $response = $ua->get( "$url_aux"); @lines = split ("\n",$response->content); $goear_id=$1; $goear_title=$2; foreach (@lines){ if ( /path="(.*)" bild=/ ){ $sth->execute("$i","$goear_id","$goear_title","$1"); $i++; } } } } } } $sth->finish; } else { die $response->status_line; } } my %songs; while (1){ my $sth2 = $dbh->prepare("select * from songs"); $sth2->execute(); while(my ($id,$goear_id,$goear_title,$goear_path) = $sth2->fetchrow) { print "$id: ".$goear_title."\n"; if ( ! $songs{$goear_title} ) { $songs{$goear_title}=$goear_path; } } if (keys(%songs) == 0){ print "\nThere are no songs in favorite list. Go to www.goear.com, \n"; print "login with your user and password and add some songs to it.\n\n"; exit; } print "r) Play Randomly\n"; print "c) Play Continuosly\n"; print "d) Download: \"d 5\" downloads the 5th song.\n \"d ALL\" downloads all the favorite list\n"; print "i) Show song information \"i 5\"\n"; print "e) Exit\n"; print "Song number to listen or option: "; $listen_id=; chomp($listen_id); switch ($listen_id){ case /^[Ee]$/ { print "Bye bye...\n"; exit; } case /^[0-9]+$/ { $sth2 = $dbh->prepare("select title,path from songs where id=?"); $sth2->execute($listen_id); my ($song_title,$song_path) = $sth2->fetchrow_array(); $sth2->finish; print "[+] Playing (press \"q\" to skip): ".$listen_id." - ".$song_title."\n"; `$mplayer $song_path`; } case /^[Rr]$/ { print "Playing Randomly (press \"Ctrl+c\" to exit)...\n"; #foreach $song ( keys(%songs) ){ # print "SONG: $song -> ".$songs{$song}."\n"; #} my @keys = keys %songs; while (1){ $random=$keys[int(rand(keys(%songs)))]; print "[+] Playing (press \"q\" to skip): ".$random."\n"; `$mplayer $songs{$random}`; } } case /^[Cc]$/ { print "Play Continuosly (press \"Ctrl+c\" to exit)...\n"; while (1){ $sth2 = $dbh->prepare("select title,path from songs"); $sth2->execute(); while( ($goear_title,$goear_path) = $sth2->fetchrow) { print "[+] Playing (press \"q\" to skip): $goear_title \n"; `$mplayer $goear_path`; } $sth2->finish; } } case /^[Dd] ([0-9]+|ALL)$/ { $listen_id =~ /^[Dd] (([0-9]+|ALL))$/; my $aux=$1; if ($1=~/[0-9]+/){ $sth2 = $dbh->prepare("select title,path from songs where id=?"); $sth2->execute($aux); my ($song_title,$song_path) = $sth2->fetchrow_array(); print "Downloading \"$song_title\" in background...\n\n"; `wget $song_path -b --quiet -o /dev/null -O \"$song_title.mp3\"`; $sth2->finish; } elsif ($1 eq "ALL"){ $sth2 = $dbh->prepare("select title,path from songs"); $sth2->execute(); while ( ($song_title,$song_path) = $sth2->fetchrow_array()) { print "Downloading \"$song_title\" in background...\n"; `wget $song_path -b --quiet -o /dev/null -O \"$song_title.mp3\"`; } print "\n"; $sth2->finish; } } case /^[iI] ([0-9]+)$/ { $listen_id =~ /^[iI] ([0-9]+)$/; $sth2 = $dbh->prepare("select goear_id,title,path from songs where id=?"); $sth2->execute($1); ($goear_id,$song_title,$song_path) = $sth2->fetchrow_array(); print "\n\n Title: $song_title\n"; print " URL: http://www.goear.com/listen.php?v=$goear_id\n"; print " MP3: $song_path\n\n"; print "Press ENTER to continue...\n"; my $wait=; } else { print "Bad option...\n"; } } } $dbh->disconnect; exit;