#!/usr/bin/perl # # musicdbclient.pl v0.0.4 - View or edit/update music database # Copyright (C) 2005, 2009 Stian Skjæveland # # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # use strict; use Term::ANSIColor; my $configfile="$ENV{'HOME'}/.musicdbrc"; my $count=0; my ($listfile, $texteditor, $uploadcmd, $main_option, $filelength, $bandname, $albumtitle, $yearofrelease, $genre, $other, $i, $search, @filelines, @configure_lines ); if (! -e $configfile) { print "$0: $configfile: not found! Now starting configuration.\n"; &start_configuration(); } &main_menu(); sub main_menu() { print colored ['black on_white'], "Menu for MusicDB client"; print color 'reset'; print "\n\n V VIEW - View and search database\n E EDIT AND UPLOAD - Edit and update database\n Q QUIT - Leaves the client\n"; print "\nWhich option would you like? [menu] "; chomp($main_option=); if ($main_option=~/[Vv]/) { &main_view(); } elsif ($main_option=~/[Ee]/) { &main_edit(); } elsif ($main_option=~/[Qq]/) { die("$0: has quit.\n"); } else { &main_menu(); } } sub main_view() { open(CONFIGFILE, "<$configfile") || die("$0: $configfile: $!\n"); @configure_lines=; chomp($listfile=substr($configure_lines[0], 9)); open (LISTFILE, "<$listfile"); $filelength=@filelines=; print "Search for (leave empty for viewing the whole database): "; chomp($search=); $search=lc($search); print "\nSearching for $search in $listfile:\n\n"; for ($i=0; $i<$filelength; $i++) { if (!($search)) { ($bandname, $albumtitle, $yearofrelease, $genre, $other)=split('@', $filelines[$i]); print "$bandname - $albumtitle - $yearofrelease - $genre $other"; $count+=1; } elsif (lc($filelines[$i])=~/$search/) { ($bandname, $albumtitle, $yearofrelease, $genre, $other)=split('@', $filelines[$i]); print "$bandname - $albumtitle - $yearofrelease - $genre $other"; $count+=1; } } print "\n$count match(es) of total $filelength\n\nHit any key to return to main menu.\n"; $count=0; $_=; close(LISTFILE); close(CONFIGFILE); &main_menu(); } sub main_edit() { open(CONFIGFILE, "<$configfile") || die("$0: $configfile: $!\n"); @configure_lines=; chomp($listfile=substr($configure_lines[0], 9)); chomp($texteditor=substr($configure_lines[1], 11)); chomp($uploadcmd=substr($configure_lines[2], 10)); print "$0: Entering stage 1... Modify items-list\n"; sleep 1; system("$texteditor $listfile"); print "$0: Entering stage 2... Show how many items that currently exists\n"; sleep 1; open (LISTFILE, "<$listfile"); $filelength=@filelines=; close(LISTFILES); print "$0: $listfile now has $filelength items\n"; print "$0: Entering stage 3... Upload $listfile\n"; sleep 1; system("$uploadcmd"); print "\n$0: all done.\n\nHit any key to return to main menu.\n"; $_=; &main_menu(); } sub start_configuration() { my @configure_data; print "Type the full path of your listfile, e.g. '/home/user/var/list.txt': "; chomp($listfile=); print "Type your favourite text-editor, e.g. 'nano': "; chomp($texteditor=); print "Type your upload command, e.g.: 'scp /home/user/var/list.txt user\@domain:~/doc/var/': "; chomp($uploadcmd=); @configure_data=("listfile=$listfile\n", "texteditor=$texteditor\n", "uploadcmd=$uploadcmd\n" ); open(CONFIGFILE, ">$configfile") || die("$0: $configfile: $!\n"); print CONFIGFILE @configure_data; close(CONFIGFILE); }