Scripts to rename avi files from TV Shows

If you got a lot of ill-named files like: $ ls S01E03.The.Sopranos.S01E03.Denial.Anger.Acceptance.avi The.Sopranos.1x04.Meadowlands.avi The.Sopranos.S01E01.The.Sopranos.avi The.Sopranos.S01E02.46.Long.avi The.Sopranos.S01E06.Pax.Soprana.avi The_Sopranos.105.College.avi that your divx player can’t sort properly and you want to end up with something like: $ ls 1x01.avi 1x02.avi 1x03.avi 1x04.avi 1x05.avi 1x06.avi you can use the following script in this way: cd /path/to/avi/files ../script.sh|sh and if you want to do the same thing to srt files then: cd /path/to/srt/files ../script.sh srt|sh As an example the script will normalize any of the following patterns S01E03, 103,1x03, or just 03 to 1x03. ...

July 5, 2007

Perl RSS server for the Sony PSP

I created this little perl program that creates an RSS feed from a set of video files (.mp4). This is useful to wirelessly transfer files to the PSP. The files will be saved in the VIDEO folder of the PSP. You’ll need to install MP4::Info and HTTP::Daemon from CPAN first. #!/usr/bin/perl -w # this small program starts a http daeomon listening on port 1111 and provides a RSS feed # to all .mp4 files stored in the 'videos' folder. # This program is intended to transfer movie files via wireless. Using the sony psp RSS feed utility # 1. Start the server with ./rssstandaloneserver.pl # 2. Copy some video files on videos subfolder # 3. Point you PSP browser to the http://<address> :<port>/ and the psp browser will display a page to # 1. subscribe to the feed. # 4. Go to Psp~~<span style="text-align:right;">Network</span>~~>RSS Channel and select the new feed # 5. A list of items should appear and pressing X will download the video files to your VIDEO folder # on the PSP memory stick # Please note that depending of your firmware and the encoder you used on your files PSP may refuse # to play those files from the VIDEO folder. The VIDEO folder is not just like the MP_ROOT/100ANV01 # folder, it behaves a different way. So please first check and transfer some of your files via USB to the # VIDEO folder and check that the PSP is able to play them from there. # If you encode your files using the Media Manager for PSP software then those files will work in any folder. # If you use 3GP encoder and QVGA MPEG-4 then those also will work in the VIDEO folder. but if you use # another resolution or AVC codec then it won't work. use HTTP::Daemon; use HTTP::Status; use XML::RSS; use MP4::Info; use File::stat; use Time::localtime; use URI::Escape; use Encode; use LWP::MediaTypes; #configuration my $feedtitle = "Perl Video Feed"; my $feeddesc = "ecerulm perl video feed"; my $hostname = "192.168.1.3"; my $port = 1111; my $debug = 1; #end of configuration my $rootaddr="http://" . $hostname . ":" . $port; my $ct = "video/m4v"; LWP::MediaTypes::add_type($ct => qw(mp4 MP4)); my $d = HTTP::Daemon->new(LocalPort => $port) || die; print "Please contact me at: <URL:", $d->url, ">\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { my $url = URI::Escape::uri_unescape($r~~<span style="text-align:right;">url</span>~~>path); print $r->method . " " . "$url\n" if $debug; if ($r->method eq 'GET' and $url eq "/") { print "sending index.htm\n"; $c->send_file_response("index.htm"); } elsif ($url eq "/index.rss") { print "generating RSS content\n"; my $rss = new XML::RSS (version => '2.0'); $rss->channel(title => $feedtitle, link => $rootaddr, description => $feeddesc, ); $rss->image(title => 'Perl video feed', url => $rootaddr . "/images/feedimage.jpg", link => $rootaddr, width => 88, height => 115, description => 'feed logo' ); # videos my `fileList = <videos/*.MP4>; foreach $file (`fileList) { my $tag = get_mp4tag($file) or die "No TAG info"; $date_string = ctime(stat($file)->mtime); #my $enclosurelink = "http://192.168.1.3:1111/" . URI::Escape::uri_escape_utf8($file); my $enclosurelink = $rootaddr . "/" . URI::Escape::uri_escape_utf8($tag->{NAM}) . ".MP4"; #my $enclosurelink =~ s/videos%2F/videos\//; $rss~~<span style="text-align:right;">add_item(title => $tag</span>~~>{NAM}, enclosure => { url=>$enclosurelink, type=>$ct, }, description => $tag->{NAM}, pubDate=>$date_string ); } # or save it to a file my $rs = new HTTP::Response(RC_OK); $rs->header('Content-type', "application/rss+xml"); $rs~~<span style="text-align:right;">content($rss</span>~~>as_string) if $r->method eq 'GET'; $c->send_response($rs); print "RSS content sent\n" if $debug; } elsif (-e "." . $url) { print "the $url maps directly to a file in the filesystem\n" if $debug; if ($r->method eq 'GET') { print "sending " . $r->method . " " . $url . "\n"; $c~~<span style="text-align:right;">send_file_response("." . $url) if $r</span>~~>method eq 'GET'; } else { print "sending HEAD " . $url . "\n"; $c->send_basic_header; print $c "Content-type: $ct\n\n"; } } else { print "$url doesn't map to file directly. We assume the url is the movie title\n" if $debug; my $t = $url; $t = Encode::decode("UTF-8", $t); $t = substr($t,1,-4); #remove the ".mp4" part. print "looking for a file with movie title: $t\n" if $debug; my `files = <videos/*.MP4>; my $found = 0; foreach $f (`files) { my $tag = get_mp4tag($f) or next; if ($tag->{NAM} eq $t) { print "sending " . $f . " file\n"; $c->send_file_response($f); $found = 1; last; } } unless ($found) { print "cannot find " . $url . " using method " . $r->method . "\n"; $c->send_error(RC_NOT_FOUND); } } } $c->close; undef($c); } The code is also available as a gist

March 10, 2007