| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Getopt::Long; | ||
| 7 | use Pod::Usage; | ||
| 8 | |||
| 9 | use IO::All -utf8; | ||
| 10 | use FilmAffinity::Movie; | ||
| 11 | |||
| 12 | =head1 NAME - filmaffinity-get-movie-info.pl | ||
| 13 | |||
| 14 | get information from filmaffinity about a film and print them in JSON formt | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | ./filmaffinity-get-movie-info.pl --id=123456 | ||
| 19 | |||
| 20 | ./filmaffinity-get-movie-info.pl --id=123456 --delay=2 | ||
| 21 | |||
| 22 | ./filmaffinity-get-movie-info.pl --id=932476 --output=/home/william/matrix.json | ||
| 23 | |||
| 24 | =head1 ARGUMENTS | ||
| 25 | |||
| 26 | =over 2 | ||
| 27 | |||
| 28 | =item --id=932476 | ||
| 29 | |||
| 30 | movie id from filmaffinity | ||
| 31 | |||
| 32 | =back | ||
| 33 | |||
| 34 | =head1 OPTIONS | ||
| 35 | |||
| 36 | =over 2 | ||
| 37 | |||
| 38 | =item --delay=3 | ||
| 39 | |||
| 40 | delay between requests | ||
| 41 | |||
| 42 | =item --output=/home/william/matrix.json | ||
| 43 | |||
| 44 | output json file | ||
| 45 | |||
| 46 | =back | ||
| 47 | |||
| 48 | =cut | ||
| 49 | |||
| 50 | my ( $movieID, $delay, $output, $help ); | ||
| 51 | |||
| 52 | GetOptions( | ||
| 53 | "id=i" => \$movieID, | ||
| 54 | "delay=i" => \$delay, | ||
| 55 | "output=s" => \$output, | ||
| 56 | "help" => \$help, | ||
| 57 | ) | ||
| 58 | || pod2usage(2); | ||
| 59 | |||
| 60 | if ( $help || !$movieID ) { | ||
| 61 | pod2usage(1); | ||
| 62 | exit(0); | ||
| 63 | } | ||
| 64 | |||
| 65 | my $movie = FilmAffinity::Movie->new( | ||
| 66 | id => $movieID, | ||
| 67 | delay => $delay || 5, | ||
| 68 | ); | ||
| 69 | |||
| 70 | $movie->parse(); | ||
| 71 | |||
| 72 | my $json = $movie->toJSON(); | ||
| 73 | $output ? $json > io($output) : print $json; | ||
| 74 | |||
| 75 | =head1 AUTHOR | ||
| 76 | |||
| 77 | William Belle, C<< <william.belle at gmail.com> >> | ||
| 78 | |||
| 79 | =head1 SEE ALSO | ||
| 80 | |||
| 81 | L<http://www.filmaffinity.com> | ||
| 82 | |||
| 83 | =head1 LICENSE AND COPYRIGHT | ||
| 84 | |||
| 85 | Copyright 2013 William Belle. | ||
| 86 | |||
| 87 | This program is free software; you can redistribute it and/or modify it | ||
| 88 | under the terms of either: the GNU General Public License as published | ||
| 89 | by the Free Software Foundation; or the Artistic License. | ||
| 90 | |||
| 91 | See http://dev.perl.org/licenses/ for more information. | ||
| 92 | |||
| 93 | =cut |