@@ -49,7 +49,7 @@ package mythtv::recordings;
4949 print " Loading MythTV recording info.\n " ;
5050
5151 # Query variables we'll use below
52- my ($sh , $sh2 , $sh3 , $q , $q2 , $q3 );
52+ my ($sh , $sh2 , $sh3 , $sh4 , $ q , $q2 , $q3 , $q4 );
5353
5454 # Find the directory where the recordings are located
5555 $q = " SELECT data FROM settings WHERE value='RecordFilePrefix' AND hostname=?" ;
@@ -62,76 +62,83 @@ package mythtv::recordings;
6262
6363 # Grab all of the video filenames
6464 opendir (DIR, $video_dir ) or die " Can't open $video_dir : $! \n\n " ;
65- @Files = grep /\.nuv$/ , readdir (DIR);
65+ @Files = grep /\.(?:mpg| nuv) $/ , readdir (DIR);
6666 closedir DIR;
6767 die " No recordings found!\n\n " unless (@Files );
6868
6969 # Parse out the record data for each file
70- $q = " SELECT title, subtitle, description, hostname, cutlist FROM recorded WHERE chanid=? AND starttime=? AND endtime=? " ;
71- $q2 = " SELECT mark FROM recordedmarkup WHERE chanid=? AND starttime=? AND type=6 ORDER BY mark DESC LIMIT 1 " ;
72- $q3 = " SELECT mark FROM recordedmarkup WHERE chanid=? AND starttime=? AND type=9 ORDER BY mark DESC LIMIT 1" ;
70+ $q = ' SELECT * FROM recorded WHERE basename=? ' ;
71+ $q2 = ' SELECT * FROM recorded WHERE chanid=? AND starttime=?' ;
72+ $q3 = ' SELECT type, mark FROM recordedmarkup WHERE chanid=? AND starttime=? AND type=6 ORDER BY type ASC, mark DESC LIMIT 1' ;
7373
7474 $sh = $dbh -> prepare($q );
7575 $sh2 = $dbh -> prepare($q2 );
7676 $sh3 = $dbh -> prepare($q3 );
7777
7878 my $count ;
7979 foreach my $file (@Files ) {
80- next unless ($file =~ / \. nuv$ / );
80+ next unless ($file =~ / \. (?:mpg| nuv) $ / );
8181 next if ($file =~ / ^ringbuf/ );
8282 $count ++;
83- # Print a progress dot
83+ # Info hash
84+ my %info ;
85+ # Print the progress indicator
8486 print " \r " , sprintf (' %.0f' , 100 * ($count / @Files )), ' % ' ;
85- # Pull out the various parts that make up the filename
86- my ($channel ,
87- $syear , $smonth , $sday , $shour , $sminute , $ssecond ,
88- $eyear , $emonth , $eday , $ehour , $eminute , $esecond ) = $file =~/ ^([a-z0-9]+)_(....)(..)(..)(..)(..)(..)_(....)(..)(..)(..)(..)(..)\. nuv$ /i ;
89- # Found a bad filename?
90- unless ($channel ) {
91- print " Unknown filename format: $file \n " ;
92- next ;
87+ # New db format? (no errors, since this query will break with mythtv < .19)
88+ $sh -> execute($file );
89+ %info = %{$sh -> fetchrow_hashref};
90+ # Nope
91+ unless ($info {' chanid' }) {
92+ # Pull out the various parts that make up the filename
93+ my ($channel , $starttime ) = $file =~/ ^(\d +)_(\d {14})[_\. ]/i ;
94+ # Found a bad filename?
95+ unless ($channel ) {
96+ print " Unknown filename format: $file \n " ;
97+ next ;
98+ }
99+ # Execute the query
100+ $sh2 -> execute($channel , $starttime )
101+ or die " Could not execute ($q ): $! \n\n " ;
102+ %info = %{$sh2 -> fetchrow_hashref};
93103 }
94- # Execute the query
95- $sh -> execute($channel , " $syear$smonth$sday$shour$sminute$ssecond " , " $eyear$emonth$eday$ehour$eminute$esecond " )
96- or die " Could not execute ($q ): $! \n\n " ;
97- my ($show , $episode , $description , $show_hostname , $cutlist ) = $sh -> fetchrow_array;
98104 # Skip shows without cutlists?
99- next if (arg(' require_cutlist' ) && !$cutlist );
105+ next if (arg(' require_cutlist' ) && !$info { ' cutlist' } );
100106 # Unknown file - someday we should report this
101- next unless ($show );
102- $sh2 -> execute($channel , " $syear$smonth$sday$shour$sminute$ssecond " )
103- or die " Could not execute ($q2 ): $! \n\n " ;
104- my ($lastgop ) = $sh2 -> fetchrow_array;
105- my $goptype = 6;
106-
107- if ( !$lastgop ) {
108- $sh3 -> execute($channel , " $syear$smonth$sday$shour$sminute$ssecond " )
109- or die " Could not execute ($q3 ): $! \n\n " ;
110- ($lastgop ) = $sh3 -> fetchrow_array;
111- $goptype = 9;
112- }
107+ next unless ($info {' chanid' });
108+ # Pull out GOP info for mpeg files
109+ $sh3 -> execute($info {' chanid' }, $info {' starttime' })
110+ or die " Could not execute ($q3 ): $! \n\n " ;
111+ ($info {' goptype' }, $info {' lastgop' }) = $sh3 -> fetchrow_array;
112+ # Cleanup
113+ $info {' starttime_sep' } = $info {' starttime' };
114+ $info {' starttime_sep' } =~ s /\D +/ -/ sg ;
115+ $info {' starttime' } =~ tr / 0-9// cd;
116+ $info {' endtime' } =~ tr / 0-9// cd;
113117 # Defaults
114- $episode = ' Untitled' unless ($episode =~ / \S / );
115- $description = ' No Description' unless ($description =~ / \S / );
118+ $info {' title' } = ' Untitled' unless ($info {' title' } =~ / \S / );
119+ $info {' subtitle' } = ' Untitled' unless ($info {' subtitle' } =~ / \S / );
120+ $info {' description' } = ' No Description' unless ($info {' description' } =~ / \S / );
116121 # $description =~ s/(?:''|``)/"/sg;
117- push @{$Shows {$show }}, {' filename' => " $video_dir /$file " ,
118- ' channel' => $channel ,
119- ' start_time' => " $syear$smonth$sday$shour$sminute$ssecond " ,
120- ' end_time' => " $eyear$emonth$eday$ehour$eminute$esecond " ,
121- ' start_time_sep' => " $syear - $smonth - $sday - $shour - $sminute - $ssecond " ,
122- ' show_name ' => ( $show or ' ' ) ,
123- ' title ' => ( $episode or ' ' ) ,
124- ' description' => ( $ description or ' ' ) ,
125- ' hostname' => ($show_hostname or ' ' ),
126- ' cutlist' => ($cutlist or ' ' ),
127- ' lastgop' => ($lastgop or 0),
128- ' goptype' => ($goptype or 0),
129- ' showtime' => generate_showtime($syear , $smonth , $sday , $shour , $sminute , $ssecond ),
130- # This field is too slow to populate here, so it will be populated in ui.pm on-demand
131- ' finfo' => undef
132- };
122+ push @{$Shows {$info { ' title ' } }}, {' filename' => " $video_dir /$file " ,
123+ ' channel' => $info { ' chanid ' } ,
124+ ' start_time' => $info { ' starttime ' } ,
125+ ' end_time' => $info { ' endtime ' } ,
126+ ' start_time_sep' => $info { ' starttime_sep ' } ,
127+ ' show_name ' => $info { ' title ' } ,
128+ ' title ' => $info { ' subtitle ' } ,
129+ ' description' => $info { ' description' } ,
130+ ' hostname' => ($info { ' hostname ' } or ' ' ),
131+ ' cutlist' => ($info { ' cutlist' } or ' ' ),
132+ ' lastgop' => ($info { ' lastgop' } or 0),
133+ ' goptype' => ($info { ' goptype' } or 0),
134+ ' showtime' => generate_showtime(split ( / - / , $info { ' starttime_sep ' }) ),
135+ # This field is too slow to populate here, so it will be populated in ui.pm on-demand
136+ ' finfo' => undef
137+ };
133138 }
134139 $sh -> finish();
140+ $sh2 -> finish();
141+ $sh3 -> finish();
135142 print " \n " ;
136143
137144 # We now have a hash of show names, containing an array of episodes
0 commit comments