View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 7 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Tue Mar 21, 2006 8:00 am 
Offline
Joined: Tue Mar 29, 2005 6:15 pm
Posts: 79
Location: Plymouth, MI
As part of my upgrade to R5B7, I copied my old version of mythlink.sh to /usr/local/bin so I could keep using the wonderful script that I got from marc.aronson (http://mysettopbox.tv/phpBB2/viewtopic.php?t=4865). Unfortunately, the script doesn't create new links for .mpg files. While I'm certainly not a linux shell scripting OR a database expert, I did a little digging and discovered the 'basename' field in the 'recorded' table that the script uses. With just a couple quick changes to mythlink.sh, it now seems to work fine for both the old .nuv's and the new .mpg's in /myth/tv.

Essentially, the changes I made were to 2 lines in the code from the post mentioned above.

Change one: add basename to the mysql query
Original code:
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.$$

New code:
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,basename from recorded;" >/tmp/mythlink.$$


Change two: change $ofn to use the 'basename' data from the query
Original code:
Code:
my $ofn = "${chanid}_${start}_${end}.nuv";

New code:
Code:
my $ofn = "${basename}";


Again, I am certainly not a scripting expert - and this may not be the best way to handle the mix of old .nuv's and new .mpg's, but it works for me - and it keeps my wife happy (she still likes using a Windows box to watch shows through the pretty share).

The complete script is available at http://www.doute.net/mythlink.sh.txt, and is listed below (be careful about line wrapping). Again, many thanks to all that contributed to the original script that I modified slightly.

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.
# modified to use 'basename' from mythconverg to handle a mix of .nuv & .mpg's in /myth/tv
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,basename 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,$basename) = split /\t/;
                $subtitle = "" if(!defined $subtitle);
                my $ofn = "${basename}";
      # 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.$$


Allan


Last edited by adoute on Tue Mar 21, 2006 9:32 am, edited 1 time in total.


Top
 Profile  
 
PostPosted: Tue Mar 21, 2006 8:17 am 
Offline
Joined: Fri Sep 19, 2003 7:05 pm
Posts: 5088
Location: Fontana, Ca
adoute wrote:
As part of my upgrade to R5B7, I copied my old version of mythlink.sh to /usr/local/bin so I could keep using the wonderful script
R5B7 already included an updated "pretty"...

_________________
cesman

When the source is open, the possibilities are endless!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 9:30 am 
Offline
Joined: Tue Mar 29, 2005 6:15 pm
Posts: 79
Location: Plymouth, MI
I can't believe I missed that - normally I'm very careful about making a backup copy of any file that I'm replacing - I must have somehow missed that one. I have an un-edited copy of the script that comes with R5B7 on my FE only machine.

I thought that I may have finally found a way to contribute something to the community - apparently not this time. If you think this topic will cause confusion, please remove it.

Thanks again for all the time and effort that must have gone in to a great release - and apologies from someone who has once again missed the obvious...

Allan


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 16, 2006 11:49 am 
Offline
Joined: Fri Apr 02, 2004 10:08 am
Posts: 1637
Location: Virginia, USA
adoute: just a note that I'm using your version of mythlink.sh now instead of the version that came with R5B7.

Don't know why but the version that came with R5B7 was not working consistently... I had about a week of programs that did not have any corresponding episodes in /myth/pretty and I don't know why. If I removed all the symlinks in /myth/pretty and re-ran mythlink.sh manually, it worked.

Moreover, the version that came with R5B7 would only make a single symlink for a show where the program title and program subtitle were the same... for instance, there was an episode of a show broken into three parts, but the program subtitle didn't include "part 1" "part 2" etc. The R5B7 mythlink.sh only made a single symlink. Since your revision includes recording date and time, I get multiple files as I should.

I also like the /myth/pretty2 folder.

Anyhow, just thought I'd report my problems with the shipping version of mythlink.sh and that this edited version seems to work better, at least for me.


Last edited by ceenvee703 on Sun Apr 16, 2006 3:00 pm, edited 1 time in total.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 16, 2006 12:45 pm 
Offline
Joined: Tue Mar 29, 2005 6:15 pm
Posts: 79
Location: Plymouth, MI
I'm glad someone else found it useful. I'm still using it myself.

Allan

_________________
Running Knoppmyth R5F27 since 09/12/07

Hardware Specs


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 16, 2006 7:38 pm 
Offline
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location: California
Glad to hear that you both find this variant of the original script useful. I've made various changes to it since originally posting it, but the one that you may find the most useful is the improvements I've made in "cleaning up" the "pretty2" directory. With the original script the subdirectory for a series would be left in "pretty2" even if all episodes of that series had been deleted. With the change I've made the subdirectory for a series will be deleted if all of the episodes have been deleted. Of course, if you record a new episde for that series, the subdirectory for that series will then be re-created. If you like this, the change is trivial. The last 3 lines of the script that adoute posted cotains two "find" commands. Simply replace those two find commands with the following:
Code:
find /myth/pretty2 -type l \! -xtype f -name \*.mpg -exec rm  -f \{\} \;
find /myth/pretty2 -type d -empty -exec rmdir -v \{\} \;
find /myth/pretty  -type l \! -xtype f -name \*.mpg -exec rm -f \{\} \;


Enjoy!

Marc


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 17, 2006 9:35 am 
Offline
Joined: Fri Apr 02, 2004 10:08 am
Posts: 1637
Location: Virginia, USA
Thanks, Marc, that fix works as advertised and removes the only problem I ever had with your version of the script. I appreciate it.


Top
 Profile  
 

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


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 23 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