Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Script for DVD Watchers
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2508
Location: Silver City, NM

PostPosted: Fri Nov 12, 2010 6:58 pm    Post subject: Script for DVD Watchers Reply with quote

I watch a lot of dvds and I almost always like to open the IMDb page for the movie I'm watching to find out more about the actors, the director, filming locations, etc.

The following script will launch an IMDb search for any dvds that are inserted in my drives (/dev/sr0 and /dev/sr1). It depends upon the title of the movie showing up as the disk label for the removable media device it is in. Most dvds and blurays do this correctly but there is a significant fraction that do not. Still, this is so easy to use (I've got it connected to a button on my desktop) that I find it extremely convenient even though it sometimes fails. I even use it to see if I've still got a dvd or bluray inside one of the drives. YMMVG.

imdb-disc:
Code:
#!/usr/bin/perl

my $dir = "/dev/disk/by-label";
my @labels = glob("$dir/*");
for my $label (@labels) {
    -l $label or next;
    my $dest = readlink($label);
    $dest =~ m{/sr\d+$} or next;
    $label =~ s{.*/}{};
    $label =~ s/_/ /g;
    exec("imdb", $label);
    print "$label\n";
}

It relies on the following two helper scripts.

imdb:
Code:
#!/bin/bash
url="http://www.imdb.com/find?s=all&q="
args=$(url-encode "$@")
firefox "$url$args" &> /dev/null
disown &> /dev/null
exit 0


url-encode:
Code:
#!/usr/bin/perl
#
# URL encodes all input args, with a few tricks
#
# Usage inside a bash script (the quotes around $@ are required):
#   
#    args=$(url-encode "$@")
#
#    args=$(url-encode `xclip -o`)


for (@ARGV) {
    s/^\s+|\s+$//;              # remove leading/trailing whitespace (ws)
    m/\s/ and $_ = qq{"$_"};    # interior ws => quote the string

    # Escape wacky characters
    s{([^-.~\w\s'/i$!*()])}{sprintf("%%%02X", ord($1))}seg;

    # Convert whitespace to plus signs
    s/\s+/+/g;
}
# "Return" (via print) one big string
print join "+",  @ARGV;
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum