Tip_managing_your_jamendo_collection_or_your_mp3_album_collection_with_covers
The dependencies
- audacious 1.4.2 with dbus
- perl > 5.8.0 (for encode)
- an UTF8 system
- gtk2-perl
- File::Spec
- File::Find
how to use the script
- point the following variable to the place where your mp3/ogg are stored...
our $JAMENDO = '/STORAGE/p2p';
- start audacious before starting this script
The script
#!/usr/bin/perl # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. use strict; use warnings; ####################################variables to modify################################################## # our $JAMENDO = '/STORAGE/p2p'; our $JAMENDO = '/home/gentux/deluge'; #our $JAMENDO = '/mnt/NFS/directories'; # our $mode = "delete";#delete or append available our $repeat = "no";#yes or no available ######################################################################################################### our $play = "no"; #for the append mode...go to the added tracks to play them imediately or let the playlist continuing normally yes or no available use Exception::Class; use Gtk2 '-init' ; use Glib qw/TRUE FALSE/; use Gtk2::SimpleList; use File::Spec; use File::Find (); use Encode; use Net::DBus; #needed for audacious # use Error qw(:try); my @display; our $bus = Net::DBus->find; our $audacious = $bus->get_service("org.mpris.audacious"); our $root = $audacious->get_object("/"); our $TrackList = $audacious->get_object("/TrackList"); our $Player = $audacious->get_object("/Player"); opendir(DIR, $JAMENDO) or die "can’t opendir $JAMENDO: $!"; our @files = readdir(DIR); @files = File::Spec->no_upwards( @files ); # remoove the . and the .. # @files = sort @files; @files = sort {uc($a) cmp uc($b)} @files; closedir DIR; my $file; foreach $file (@files) { if (-d "$JAMENDO/$file"){ chomp $file; $file = decode("utf8", $file); push (@display,$file); } else{print "$file is not a directory\n";} } sub gui_quit{ Gtk2->main_quit; } sub remove_tracks { my $numbers_of_tracks = $TrackList->GetLength; print "$numbers_of_tracks \n"; my $i = 0; for $i (0..$numbers_of_tracks){ $TrackList->DelTrack(0); print "deleting track 0: for the $i time and the numbers of track is $numbers_of_tracks \n"; $i++; } } sub quit {Gtk2->main_quit;} my $window = Gtk2::Window->new ('toplevel');; $window->signal_connect (delete_event => \&gui_quit ); my $table = Gtk2::Table->new (2,2 ,FALSE); $window->add($table); my $sw = Gtk2::ScrolledWindow->new (undef, undef); $sw->set_shadow_type ('etched-out'); $sw->set_policy ('automatic', 'automatic'); $sw->set_size_request (300, 300); $sw->set_border_width(5); my $button_launch = Gtk2::Button->new("Play"); my $button_add = Gtk2::Button->new("Add to Playlist"); my $button_quit = Gtk2::Button->new("Quit"); $button_quit->signal_connect("clicked" => \&quit); our $slist = Gtk2::SimpleList->new ( 'Cover' => 'pixbuf', 'name' => 'text'); $table->attach($button_quit,0,1,1,2,[qw(fill)],[qw()],undef,undef); $table->attach($button_launch,2,3,1,2,[qw(fill)],[qw()],undef,undef); $table->attach($button_add,1,2,1,2,[qw(fill)],[qw()],undef,undef); $table->attach_defaults($sw,0,3,0,1); $sw->add($slist); $button_launch->signal_connect("clicked" => \&play_playlist); $button_add->signal_connect("clicked" => \&add_to_playlist); my $i; for $i (0..$#display) { if (-d "$JAMENDO/$display[$i]"){ chdir "$JAMENDO/$display[$i]" or die "can't chdir to $JAMENDO/$display[$i]"; # Set the variable $File::Find::dont_use_nlink if you're using AFS, # since AFS cheats. # for the convenience of &wanted calls, including -eval statements: use vars qw/*name *dir *prune/; *name = decode("utf8",*File::Find::name); *dir = *File::Find::dir; *prune = *File::Find::prune; # Traverse desired filesystems File::Find::find({wanted => \&wanted}, "./"); our $pixbuf; our $cover; $name = shift; sub wanted { $cover = shift; # $name = shift; my ($dev,$ino,$mode,$nlink,$uid,$gid); (($dev,$ino,$mode,$nlink,$uid,$gid) = ($_)) && ( ($_) = decode("utf8", $_)) && /^.*\.jpg\z/si && ( ($cover =decode("utf8", $name))) && # try { eval { ($pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_size ("$cover",100,100) ) }; # } } push @{$slist->{data}} , ([$pixbuf,$display[$i]]); $pixbuf = shift; chdir ".."; } # else{ # # print @display[$i]; # my $del = splice(@display,$i,1); # print "$del\n"; # } } my $j; for $j (0..$#display){ print "#$display[$j]#\n"; } sub play_playlist { #old system witout dbus...can only append tracks... # # my ($slist) = @_; # my @selection = $slist->get_selected_indices; # # print "@selection a ete selectione\n"; # print "launching @display[@selection]\n"; # system "audacious","-H", "--enqueue", "$JAMENDO/@display[@selection]", "--display=:0.0"; # new system with dbus my @selection = $slist->get_selected_indices; print "launching @display[@selection]\n"; remove_tracks(); $TrackList->AddTrack("$JAMENDO/@display[@selection]",0); $Player->Play; if ($repeat eq "yes"){ $Player->Repeat(1); } elsif ($repeat eq "no") { $Player->Repeat(0); } else { print 'error...incorrect $repeat',"\n"; } } sub add_to_playlist { my @selection = $slist->get_selected_indices; print "launching @display[@selection]\n"; # system "audacious","-H", "--enqueue", "$JAMENDO/@display[@selection]", "--display=:0.0"; #do not take in account where we are inside the playlist... print "append mode entered\n"; my $numbers_of_tracks = $TrackList->GetLength; my $current_track = $TrackList->GetCurrentTrack; print "we have $numbers_of_tracks tracks into the playlist\n"; if ($play eq "yes"){ $TrackList->AddTrack("$JAMENDO/@display[@selection]",0); my $i; my $loop = $numbers_of_tracks - $current_track; for $i (1..$loop){ $Player->Next; print "for loop number $i\n"; $i++; } $Player->Play; } elsif ($play eq "no") { $TrackList->AddTrack("$JAMENDO/@display[@selection]",0); } else { print 'error...incorrect $play',"\n"; } if ($repeat eq "yes"){ $Player->Repeat(1); } elsif ($repeat eq "no") { $Player->Repeat(0); } else { print 'error...incorrect $repeat',"\n"; } } $window->show_all; Gtk2->main;
Last modified: Sun, 08 Jun 2008 16:16:00 +1000 Hits: 2,869
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should be using interactive floor plans and real estate agent tools.
