script/imdb-title.pl untested

filter: Statementstmt 0.0% 0 / 79 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 119 CC 2 SCAR 11.5
CC
2
Cov
0%
DumpTitle
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.1
1 #!/usr/local/bin/perl
2  
3 use strict;
4 use Getopt::Long;
5  
6 use IMDB::Local;
7 use IMDB::Local::Title;
8 use IMDB::Local::QualifierType ':types';
9  
10 my ($opt_help,
11 $opt_imdbDir,
12 $opt_import,
13 $opt_quiet,
14 $opt_download);
15 my $opt_title;
16 my $opt_format='csv';
17  
18 GetOptions('help' => \$opt_help,
19 'imdbdir=s' => \$opt_imdbDir,
20 'import=s' => \$opt_import,
21 'quiet' => \$opt_quiet,
22 'title=s' => \$opt_title,
23 'format=s' => \$opt_format,
24 ) or usage(0);
25  
26 if ( $opt_help ) {
27 die "no usage implemented";
28 }
29  
30 if ( ! defined($opt_imdbDir) ) {
31 die "imdbdir flag is required";
32 }
33  
34 $opt_quiet=(defined($opt_quiet));
35  
36 # lets put list files below the imdbDir
37 my $listsDir="$opt_imdbDir/lists";
38  
39 my $db=new IMDB::Local::DB(database=>"$opt_imdbDir/imdb.db");
40 if ( !$db->connect() ) {
41 die "moviedb connect failed:$DBI::errstr";
42 }
43  
44 my $searchableTItle=$db->makeSearchableTitle($opt_title);
45 print "searching for $searchableTItle\n";
46  
47 sub DumpTitle($)
48 {
49 my ($t)=@_;
50  
51 #my $ind=" " x $index;
52 print $t->toText();
53
54 if ( $t->QualifierType->Name eq 'tv_series' ) {
55 #print "getting episodes..\n";
56
57 my $n=0;
58 for my $e ($t->getEpisodes()) {
59 $n++;
60 print "=====Episode #$n:\n";
61 $e->populateAll();
62 for (split("\n", $e->toText())) {
63 print "\t".$_."\n";
64 }
65 #print $e->toText();
66 }
67 }
68 }
69  
70 my @list=IMDB::Local::Title::findBySearchableTitle($db, $searchableTItle, IMDB::Local::QualifierType::TV_SERIES); # any type
71 if ( @list ) {
72 print "===== TV SERIES =====\n";
73 }
74 for my $i (@list) {
75  
76 if ( $opt_format eq 'detailed' ) {
77 print "===============================: Title $i\n";
78  
79 my $t=IMDB::Local::Title::findByTitleID($db, $i);
80 $t->populateAll();
81 DumpTitle($t);
82 }
83 elsif ( $opt_format eq 'csv' ) {
84 print "===============================: Title $i\n";
85  
86 my $t=IMDB::Local::Title::findByTitleID($db, $i);
87  
88 $t->populateAll();
89 print $t->toText();
90  
91 if ( $t->QualifierTypeID == IMDB::Local::QualifierType::TV_SERIES ) {
92 print "----------------------------------------\n";
93 my $res=$db->select2Matrix("select SearchTitle,Title,Series,Episode,AirDate from Titles where ParentID=$i order by Series,Episode");
94 if ( $res ) {
95 for my $h (@$res) {
96 print " ".join(',', @$h)."\n";
97 }
98 }
99 }
100 }
101
102 }
103  
104  
105 @list=IMDB::Local::Title::findBySearchableTitle($db, $searchableTItle, IMDB::Local::QualifierType::MOVIE); # any type
106 if ( @list ) {
107 print "===== MOVIES =====\n";
108 }
109 for my $i (@list) {
110  
111 if ( $opt_format eq 'detailed' ) {
112 print "===============================: Title $i\n";
113  
114 my $t=IMDB::Local::Title::findByTitleID($db, $i);
115 $t->populateAll();
116 DumpTitle($t);
117 }
118 elsif ( $opt_format eq 'csv' ) {
119 print "===============================: Title $i\n";
120  
121 my $t=IMDB::Local::Title::findByTitleID($db, $i);
122  
123 $t->populateAll();
124 print $t->toText();
125  
126 if ( $t->QualifierTypeID == IMDB::Local::QualifierType::TV_SERIES ) {
127 print "----------------------------------------\n";
128 my $res=$db->select2Matrix("select SearchTitle,Title,Series,Episode,AirDate from Titles where ParentID=$i order by Series,Episode");
129 if ( $res ) {
130 for my $h (@$res) {
131 print " ".join(',', @$h)."\n";
132 }
133 }
134 }
135 }
136
137 }
138  
139 exit(0);