View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 9 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Fri Jun 10, 2005 7:41 pm 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location: California
I made some minor modifications to the "mythlink.sh" script several months ago to add some capabilities that I wanted and it recently dawned on me that others might find these useful. I can confirm that this script will work on V4R9 and V5A16. The changes I made do the following:

1. filenames are now of the form <Series name>-<yymmdd>-<hhmm>-<Episode Title>. This means that a simple alphabetic sort ensures that eipsides within a series are sorted by recording date.

2. A subdirectory names "pretty/descriptions" will contain one ".txt" file for each recorded program. The ".txt" file contains the episode synopsis for that show. ie: For the program "Desperate_Housewives-050501-2100-Fear_No_More.mpg", there is a file in "pretty/descriptions" named "Desperate_Housewives-050508-2100-Sunday_in_the_Park_With_George.mpg.txt" with the following content:
Quote:
George William continues to find a way into Bree's life; Lynette tries to spice things up when she fears Tom is losing interest.

3. The script also creates links in a directory named "/myth/pretty2". "/myth/pretty2" contains one subdirectory for each series, which in turn contains all of the epsiode files for that series.

My changes are very minor in nature -- credit for this script belongs to the original author.

If you use the script, you need to create the directory "/myth/pretty2" before you run it for the first time.

I don't know if anyone will find this useful, but in case you do the modified script is as follows:

Code:
#!/bin/sh

# mythlink.sh - Symlinks mythtv files to more readable version in /tv/pretty
# by Dale Gass
# modified by Dave Misevich for slightly prettier names and doesn't destroy/recreate valid links.
# (I found a windows box watching a recording would terminate if the link was removed)
# Bug fixed caused by programs that don't have a subtitle. Use start time/date to create one.
# modified to add .mpg to end of symlink. Thanks mike at the mysettopbox.tv forum for the code.

mysql -uroot  mythconverg -B --exec "select chanid,DATE_FORMAT(starttime,'%Y%m%d%H%i%s'),DATE_FORMAT(endtime,'%Y%m%d%H%i%s'),title,subtitle,description from recorded;" >/tmp/mythlink.$$
perl -w -e '
        my $mythpath= "/myth/tv";
        my $altpath= "/myth/pretty";
   my $altpath2 = "/myth/pretty2";
   my $dfile= "";
   my $edate= "";
   my %month = ( "01","Jan", "02","Feb", "03","Mar", "04","Apr", "05","May", "06","Jun",
                 "07","Jul", "08","Aug", "09","Sep", "10","Oct", "11","Nov", "12","Dec");
        if (!-d $altpath) {
                mkdir $altpath or die "Failed to make directory: $altpath\n";
        }
   opendir(DIR, $altpath) or die "cannot opendir $altpath: $!";
   while (defined($file = readdir(DIR))) {
      next if $file =~ /^\.\.?$/;     # skip . and ..
      @dirlist = (@dirlist,$file);
       }
       closedir(DIR);
        <>;
        while (<>) {
                chomp;
                my ($chanid,$start,$end,$title,$subtitle,$description) = split /\t/;
                $subtitle = "" if(!defined $subtitle);
                my $ofn = "${chanid}_${start}_${end}.nuv";
      # skip if the nuv doesnt exist
                do { print "Skipping $mythpath/$ofn\n"; next } unless -e "$mythpath/$ofn";
                $start =~ /^....(........)/;
      if ($subtitle eq "") {
        # if no subtitle then build one from start time.
        $subtitle = $month{substr($start,4,2)} . substr($start,6,2);
        $subtitle = $subtitle . "_" . substr($start,0,4) . "_" . substr($start,8,4);
      }
                # my $nfn = "${title}-${subtitle}";
      my $fntitle = "${title}";
                $fntitle =~ s/&/+/g;
      $fntitle =~ s/\047//g;
      $fntitle =~ s/[^+0-9a-zA-Z_-]+/_/g;
      $fntitle =~ s/_$//g;
      
      my $fnsubtitle = substr($start,2,2).substr($start,4,2).substr($start,6,2)."-".substr($start,8,4). "-${subtitle}";
                $fnsubtitle =~ s/&/+/g;
      $fnsubtitle =~ s/\047//g;
      $fnsubtitle =~ s/[^+0-9a-zA-Z_-]+/_/g;
      $fnsubtitle =~ s/_$//g;
      
      my $nfn = "${fntitle}-${fnsubtitle}";
      my $nfn2 = "${fntitle}/${fnsubtitle}";
   
      #print "\$ofn = $ofn $title \$nfn = $nfn\n";
      # make a list of existing nuv filenames for use later.
      $goodfile{$nfn.".mpg"} = 1;
      #
      # Create symlink in $altpath (pretty) and create description file
      #
      if (!-s "$altpath/$nfn".".mpg"){
                  #  print "Creating $altpath/$nfn\n";
                  symlink "$mythpath/$ofn", "$altpath/$nfn".".mpg" or die "Failed to create symlink $altpath/$nfn".".mpg".": $!";
        open ($dfile,">$altpath/descriptions/$nfn.mpg.txt") || die("Could not open txt file. $!");
        print $dfile "$description \l";
        close ($dfile);
      }
      #
      # Create secondary altpath2 -- subdir by series
      #
      if (!-s "$altpath2/$nfn2".".mpg") {
        mkdir "$altpath2/$fntitle";
        symlink "$mythpath/$ofn", "$altpath2/$nfn2".".mpg" or die "Failed to create symlink in $altpath2/$nfn2".": $!";
      }
        }
   # remove symlinks that are not pointed at valid files in the database
   # Also removed corresponding file in "descriptions"
   foreach $fname (@dirlist) {
       unlink "$altpath/$fname" unless $goodfile{$fname};
       unlink "$altpath/descriptions/$fname.txt" unless $goodfile{$fname};
       #print "I want to unlink $altpath/$fname\n" unless $goodfile{$fname};
       }

' /tmp/mythlink.$$
#
# Remove sym links in "pretty2" that point at files that
# don't exist anymore
#
find /myth/pretty2 -type l \! -xtype f -name \*.mpg -exec rm  \{\} \;
find /myth/pretty  -type l \! -xtype f -name \*.mpg -exec ls \{\} \;
rm /tmp/mythlink.$$


Marc


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 2:00 pm 
Offline
Joined: Fri Apr 02, 2004 10:08 am
Posts: 1637
Location: Virginia, USA
Marc: this revision to the script rocks. Thanks very much.

Just one note that, not only do you have to create /myth/pretty2, but you also have to create /myth/pretty/descriptions before the script works.

One possible addition down the road: I like to record both an HD version of a show like Lost on my HD3000, as well as a "backup" via my PVR-250, in case there's reception problems. Is there any way the script could be modified to name the files differently? I am pretty sure the old version did not, therefore there was only one symlink to one of the recordings.

Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 9:15 pm 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location: California
ceenvee703, glad you like it and good point about needing to create the "pretty/descriptions" subdirectory. In terms of the change you requested -- it should be quite do'able, but let me ask a few questions:

1. Am I correct in assuming that you are recording both the analog and digital show simultaneously, and that they have the same title, subititle date & time stamp? Is there anything different about any of these fields between the analog & digital recording?

2. When you run the script, which one do you get a link to? Is it always the analogue version or always the digital one, or does it vary?

3. If you look in "recorded programs" is the channel number the same or different for the analogue vs. digital recording? If they are different, post back the two different channels displayed. (I'm lookng at channel ID in mythweb / recorded shows).

More generally I'm looking for a column/field in the"recorded" table that is different for the analogue vs. digital recording that I can key off of.

BTW, thanks for your help on getting mediaMVP running on my other post -- glad that I could repay the favor!


Marc


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 7:47 am 
Offline
Joined: Tue Dec 07, 2004 12:04 pm
Posts: 369
I think the quickest hack would be noting which tuner was used to record it, if that's stored in the db, and append that (the name and/or number) to the filename before the filetype. Or perhaps the resolution, which is less likely to be unique, but gives more usefule information for day-to-day use and solves the parallel recordings issue for HD vs. SD.

-brendan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 9:03 am 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location: California
That's a good idea but the tuner # isn't in the table "recorded", which is the one used by this script. If someone knows the table & column with the turner number and can provide me with the appropriate sql to join the recorded table w/ that table, I should be able to use this approach.

In the meantime, I've looked at the list of available fields in the "recorded" table and here are the options I see:

1. Channel ID ("recorded.chanid"), if they are different for analog vs. digital (I'm guessing they aren't.)

2. recording group ("recorded.recgroup"). This would require that all digitial recordings be placed in a different recording group than the analogue recordings. I would simply add an option that either creates a sub-directory per recording group or append the recording group to the end of file name. (Could also choose to pre-pend recording group to the beginning of the file name instead, depending on which seems more intuitive.) Probably makes the most sense to use the subdirectory approach in "pretty2" and the filename prefix/suffix approach in "pretty".

3. filesize ("recorded.filesize"). The filesizes are different, so I could append the filesize to the end of the filename. Not very intuitive, but it would ensure unique filenames.

Thoughts?

Marc


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 10:17 am 
Offline
Joined: Fri Apr 02, 2004 10:08 am
Posts: 1637
Location: Virginia, USA
Marc: I tried doing this last night and the digital recording was the one that had the symlink in /myth/pretty. Not sure if it's always that way though; I'll try again and see.

I took a quick look at mythconverg with webmin and I saw a "recordedprogram" table, but not simply a "recorded" table. With "recordedprogram" the "chanid" looks to be different (it seems to be a combination of the source ID + channel number, and source ID is different for my HD card). There was also a "hdtv" field in "recordedprogram" as well but I wasn't able to check a HD recording to see what was different about it.

Anyhow, I'll look again for "recorded" and see what other fields could work. Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 18, 2005 8:22 am 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location: California
ceenvee703:

Good info on chanid. On my system chanid appears to always be a 4-digits long. It is essentially "1000 + channel #". ie: Channel 23 is "1023". Sounds like that first digit is a tuner #.

The script below will now append "chanid" to the end of the filename. Let me know if this works and if using the first digit from chanid along is sufficient to keep things unique. If it is, I'll tweak the script so that only that single character is optionally appended to the file name.

Marc

Note: Post edited by Marc at 8:12am PST 6/18/05 to remove blank link above "#!/bin/sh".

Code:
#!/bin/sh

# mythlink.sh - Symlinks mythtv files to more readable version in /tv/pretty
# by Dale Gass
# modified by Dave Misevich for slightly prettier names and doesn't destroy/recreate valid links.
# (I found a windows box watching a recording would terminate if the link was removed)
# Bug fixed caused by programs that don't have a subtitle. Use start time/date to create one.
# modified to add .mpg to end of symlink. Thanks mike at the mysettopbox.tv forum for the code.

mysql -uroot  mythconverg -B --exec "select chanid,DATE_FORMAT(starttime,'%Y%m%d%H%i%s'),DATE_FORMAT(endtime,'%Y%m%d%H%i%s'),title,subtitle,description from recorded;" >/tmp/mythlink.$$
perl -w -e '
        my $mythpath= "/myth/tv";
        my $altpath= "/myth/pretty";
   my $altpath2 = "/myth/pretty2";
   my $dfile= "";
   my $edate= "";
   my %month = ( "01","Jan", "02","Feb", "03","Mar", "04","Apr", "05","May", "06","Jun",
                 "07","Jul", "08","Aug", "09","Sep", "10","Oct", "11","Nov", "12","Dec");
        if (!-d $altpath) {
                mkdir $altpath or die "Failed to make directory: $altpath\n";
        }
   opendir(DIR, $altpath) or die "cannot opendir $altpath: $!";
   while (defined($file = readdir(DIR))) {
      next if $file =~ /^\.\.?$/;     # skip . and ..
      @dirlist = (@dirlist,$file);
       }
       closedir(DIR);
        <>;
        while (<>) {
                chomp;
                my ($chanid,$start,$end,$title,$subtitle,$description) = split /\t/;
                $subtitle = "" if(!defined $subtitle);
                my $ofn = "${chanid}_${start}_${end}.nuv";
      # skip if the nuv doesnt exist
                do { print "Skipping $mythpath/$ofn\n"; next } unless -e "$mythpath/$ofn";
                $start =~ /^....(........)/;
      if ($subtitle eq "") {
        # if no subtitle then build one from start time.
        $subtitle = $month{substr($start,4,2)} . substr($start,6,2);
        $subtitle = $subtitle . "_" . substr($start,0,4) . "_" . substr($start,8,4);
      }
                # my $nfn = "${title}-${subtitle}";
      my $fntitle = "${title}";
                $fntitle =~ s/&/+/g;
      $fntitle =~ s/\047//g;
      $fntitle =~ s/[^+0-9a-zA-Z_-]+/_/g;
      $fntitle =~ s/_$//g;
      
      my $fnsubtitle = substr($start,2,2).substr($start,4,2).substr($start,6,2)."-".substr($start,8,4). "-${subtitle}";
                $fnsubtitle =~ s/&/+/g;
      $fnsubtitle =~ s/\047//g;
      $fnsubtitle =~ s/[^+0-9a-zA-Z_-]+/_/g;
      $fnsubtitle =~ s/_$//g;
      
      my $nfn = "${fntitle}-${fnsubtitle}-${chanid}";
      my $nfn2 = "${fntitle}/${fnsubtitle}-${chanid}";
   
      #print "\$ofn = $ofn $title \$nfn = $nfn\n";
      # make a list of existing nuv filenames for use later.
      $goodfile{$nfn.".mpg"} = 1;
      #
      # Create symlink in $altpath (pretty) and create description file
      #
      if (!-s "$altpath/$nfn".".mpg"){
                  #  print "Creating $altpath/$nfn\n";
                  symlink "$mythpath/$ofn", "$altpath/$nfn".".mpg" or die "Failed to create symlink $altpath/$nfn".".mpg".": $!";
        open ($dfile,">$altpath/descriptions/$nfn.mpg.txt") || die("Could not open txt file. $!");
        print $dfile "$description \l";
        close ($dfile);
      }
      #
      # Create secondary altpath2 -- subdir by series
      #
      if (!-s "$altpath2/$nfn2".".mpg") {
        mkdir "$altpath2/$fntitle";
        symlink "$mythpath/$ofn", "$altpath2/$nfn2".".mpg" or die "Failed to create symlink in $altpath2/$nfn2".": $!";
      }
        }
   # remove symlinks that are not pointed at valid files in the database
   # Also removed corresponding file in "descriptions"
   foreach $fname (@dirlist) {
       unlink "$altpath/$fname" unless $goodfile{$fname};
       unlink "$altpath/descriptions/$fname.txt" unless $goodfile{$fname};
       #print "I want to unlink $altpath/$fname\n" unless $goodfile{$fname};
       }

' /tmp/mythlink.$$
#
# Remove sym links in "pretty2" that point at files that
# don't exist anymore
#
find /myth/pretty2 -type l \! -xtype f -name \*.mpg -exec rm  \{\} \;
find /myth/pretty  -type l \! -xtype f -name \*.mpg -exec ls \{\} \;
rm /tmp/mythlink.$$


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 18, 2005 2:48 pm 
Offline
Joined: Fri Apr 02, 2004 10:08 am
Posts: 1637
Location: Virginia, USA
Marc: if you saw my previous post, never mind... it's working fine...

Code:
David_Sheehans_Summer_Movie_Magic_2005-050618-1532-Jun18_2005_1532-2073.mpg
David_Sheehans_Summer_Movie_Magic_2005-050618-1532-Jun18_2005_1532-1007.mpg


Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 19, 2005 9:45 am 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location: California
Glad to hear it's working. Let me know if you want it tweaked to a different file naming convention.

If you want to re-arrange the way the strings are put together to create the file names, you only need to tweak the following two lines:

Code:
      my $nfn = "${fntitle}-${fnsubtitle}-${chanid}";
      my $nfn2 = "${fntitle}/${fnsubtitle}-${chanid}";


"nfn" is the New File Name for /myth/pretty and "nfn2" is the New File Name for /myth/pretty2.

Marc


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 17 guests


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 post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu