summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xvideoadd.pl129
-rw-r--r--videodb.rc3
2 files changed, 121 insertions, 11 deletions
diff --git a/videoadd.pl b/videoadd.pl
index b1ebb0f..99926d6 100755
--- a/videoadd.pl
+++ b/videoadd.pl
@@ -1,5 +1,14 @@
#!/usr/bin/perl -w
+# This program is free software. It comes without any warranty, to the
+# extent permitted by applicable law. You can redistribute it and/or
+# modify it under the terms of the Do What The Fuck You Want To Public
+# License, Version 2, as published by Sam Hocevar.
+# See http://sam.zoy.org/wtfpl/COPYING for more details.
+
+
+$VERSION = "0.1, 17 February 2012";
+
use Getopt::Long qw/:config noauto_abbrev nogetopt_compat no_ignore_case
permute bundling auto_version auto_help/;
use Pod::Usage;
@@ -39,17 +48,122 @@ $config{url} =~ s/\/*$//;
################################################################################
-# videoadd [--seen] [--dont-sort] [--search=(title|imdbid)]
-# [-o title=...] [ -o year=...]
-# file
+=head1 NAME
+
+videoadd.pl - add movies to your collection
+
+=head1 SYNOPSIS
+
+B<videoadd.pl> [B<-s>] [B<-i> I<crit>] [B<-o> I<key=value>...]
+[B<--ignore-db>] [B<--dont-sort>] [B<-q>] I<filename>
+
+=head1 DISCLAIMER
+
+Your collection is assumed to have the following structure: two
+folders, I<DIRECTORS> and I<MOVIES>, that have the same parent.
+I<DIRECTORS> contains one subdirectory for each director, and each movie
+lies (B<as a regular file>) in the subdirectory of its director.
+The folder I<MOVIES> contains symlinks - one for each movie - that target
+to I<../DIRECTORS/director_of_the_movie/movie>.
+The behavior of B<videoadd.pl> is NOT specified if your collection does
+not verify these conventions!
+
+ |- ...
+ |- DIRECTORS
+ | |- director1
+ | |- |- movie11
+ | | `- movie12
+ | |- director2/
+ | `- ...
+ `- MOVIES
+ |- movie11 -> ../DIRECTORS/director1/movie1
+ |- movie12 -> ../DIRECTORS/director1/movie2
+ `- ...
+
+=head1 DESCRIPTION
+
+B<videoadd.pl> add the given movie to your collection. Various data such
+as the movie length, the A/V codecs, etc. are read from the metadata of
+the movie. One can fetch other data (e.g., year, director, cast, etc.)
+from IMDB (option B<-i>). If there is a clash (e.g., language) the metadata
+take precedence.
+The database is then updated with the new movie (unless B<--ignore-db>
+is set), which in turn is put in the right place of the above hierarchy
+(unless B<--dont-sort> is set).
+
+=head1 OPTIONS
+
+=over 8
+
+=item B<-s>, B<--seen>
+
+Mark the movie as seen for the I<userid> of the configuration file.
+
+=item B<--ignore-db>
+
+Do not connect to the database, hence do not update it with the new
+movie. Note that it may break the sanity of your collection.
+
+=item B<--dont-sort>
+
+Do not put the new movie in I<DIRECTORS/director/movie>, with a
+symlink I<MOVIES/movie> -> I<DIRECTORS/director/movie>.
+Note that it may break the sanity of your collection.
+
+=item B<-i> I<crit>, B<--imdb=>I<crit>
+
+Search for the given criterion (e.g., a movie title or an IMDB ID) on
+IMDB. The retrieved data (such as year, director, cast, etc.) will be
+added to the database (unless overriden by B<-o> I<key=value>).
+
+=item B<-o> I<key=value>
+
+Override data with the I<value> provided.
+I<key> is one of I<title>, I<language >, I<imdbid>, I<year>, I<imgurl>,
+I<director>, I<actors>, I<country>, I<plot>, I<rating>, I<istv>.
+
+=item B<-q>, B<--quiet>
+
+Do not print the final URL for the freshly added movie.
+
+=back
+
+=head1 CONFIGURATION
+
+B<videodb-check> reads its database configuration from the file
+I<$HOME/.videodb.rc>. This file has to be the content of a Perl hash
+e.g.,
+
+ videodir => catdir($HOME,'video'),
+ driver => 'mysql',
+ database => 'videodb',
+ hostname => '127.0.0.1',
+ user => 'username',
+ port => 3306,
+ password => '******',
+ videodata => "videodb_videodata",
+ imdb => 'akas.imdb.com',
+ url => 'https://videodb.example.org',
+ userid => 1
+
+=head1 REQUIREMENTS
+
+The imported modules are available on CPAN. See the source for details.
+
+=head1 AUTHOR
+
+Copyright 2012 Guilhem Moulin. See the source for copying conditions.
+
+=cut
+
################################################################################
my $ignoredb_flag;
my $sort_flag = 1;
my %options;
-GetOptions( #"seen" => sub { $options{seen} = 1 }
- "s|search=s"=> sub { $imdb{crit} = $_[1] }
+GetOptions( #"s|seen" => sub { $options{seen} = 1 }
+ "i|imdb=s"=> sub { $imdb{crit} = $_[1] }
# , "u|update=s"=> update id/filename
, "o=s" => sub { my ($k,$v) = split /=/, $_[1], 2;
$options{lc $k} = $v; }
@@ -95,12 +209,7 @@ if (defined $imdb{crit}) {
my $movie;
do {
- # Bug, see https://rt.cpan.org/Public/Bug/Display.html?id=71429
- open my $STDOUT, '>&', \*STDOUT or die "Can't dup: $!";
- open STDOUT, '>', '/dev/null' or die "Cannot open `/dev/null': $!";
$movie = new IMDB::Film(%imdb);
- close STDOUT or die "Can't close";
- open STDOUT, '>>&', $STDOUT or die "Cannot open: $!";
die "Something wrong happened: " .$movie->error. "\n"
unless $movie->status;
diff --git a/videodb.rc b/videodb.rc
index 150b09d..19405b2 100644
--- a/videodb.rc
+++ b/videodb.rc
@@ -16,4 +16,5 @@ dbi_misc => { mysql_ssl => 1
password => '******',
videodata => "videodb_videodata",
imdb => 'akas.imdb.com',
-url => 'https://videodb.example.org'
+url => 'https://videodb.example.org',
+userid => 1