View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 4 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Tue Jan 13, 2004 9:41 am 
Offline
Joined: Mon Nov 17, 2003 8:59 am
Posts: 206
Location: Michigan
There's a neat program in the contribs dir that creates symlinks with human readable names for all the nuvs in the tv directory. If you create a cron job to run this thing periodically, the links will always be up to date, and makes playing files outside of myth pretty easy. If you export the dir with nfs or samba, other computers (even M$ computers) can play the videos.

I modified the file slightly and have attached my version below. The original occasionally made not so pretty names when the show name had special characters, so I tweaked that. Also, it destroyed all the links at the start, then recreated them all. If I was watching a show on my desktop, mplayer would terminate because the link went away. So I modifed the script to only create new links, and to only destroy invalid links.

Here is what I did. If you want different paths, you must edit the file accordingly. Please be cautious, because this script deletes files. If something is set up wrong, it could delete something you really want!!

To be extra cautious, I've commented out the "unlink" line at the bottom of the file and added a print line that will print what files would be removed. When you are satisfied that the script is working properly, move the comment from the real unlink line to the print line.
Also, if you've changed the root password to mysql this will need to be tweaked.

su
#mkdir /tv
#mkdir /tv/pretty
#chown mythtv:mythv /tv
#chown mythtv:mythtv /tv/pretty
#exit

touch /tv/mythlink.sh
chmod a+x /tv/mythlink.sh
vi (or what ever editor you like) /tv/mythlink.sh and add the code below:
Code:
#!/bin/sh
# mythlink.sh - Symlinks mythtv files to more readable version in /tv/pretty
# by Dale Gass
# modified by Dave M. for slightly prettier names and doesn't destroy/recreate valid links.
# (I found a windows box watching a recording would terminate playback if the link was removed)
 
mysql -uroot  mythconverg -B --exec "select chanid,starttime,endtime,title,subtitle from recorded;" >/tmp/mythlink.$$
perl -w -e '
        my $mythpath= "/myth/tv";
        my $altpath= "/tv/pretty";
        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) = split /\t/;
                $subtitle = "" if(!defined $subtitle);
                my $ofn = "${chanid}_${start}_${end}.nuv";
                do { print "Skipping $mythpath/$ofn\n"; next } unless -e "$mythpath/$ofn";
                $start =~ /^....(........)/;
                my $nfn = "$1_${title}_${subtitle}";
                $nfn =~ s/&/+/g;
                $nfn =~ s/\047//g;
                $nfn =~ s/[^+0-9a-zA-Z_-]+/_/g;
                $nfn =~ s/_$//g;
                $goodfile{$nfn} = 1;
                if (!-e "$altpath/$nfn"){
                print "Creating $nfn\n";
                symlink "$mythpath/$ofn", "$altpath/$nfn" or die "Failed to create symlink $altpath/$nfn: $!";
                }
        }
        # remove symlinks that are not pointed at valid files in the database
        foreach $fname (@dirlist) {
            # switch the comment to the second line after you
            # are satisfied that it would not delete a good file.
            #unlink "$altpath/$fname" unless $goodfile{$fname};
              print "I want to unlink $altpath/$fname\n" unless $goodfile{$fname};
            }
 
' /tmp/mythlink.$$
rm /tmp/mythlink.$$


Now run it:
/tv/mythlink.sh

It should create a bunch of symbolic links under /tv/pretty. If you delete a recording in mythtv and run it again, it should want to delete the link.

Now to run it in a cron job so that the links will always be up to date. I run it at 5 and 35 minutes after every hour, you can set up the cron job differently.

As user mythtv,
crontab -e
(now add the following lines with vi commands and then type :wq! in the editor)
Code:
# run tvpretty script at 5 and 35 after every hour
5,35 * * * * nice -n 19 /tv/mythlink.sh


If you run crontab -l, you should see the lines. That's it!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 2:14 pm 
Offline
Joined: Fri Dec 26, 2003 2:25 pm
Posts: 244
Thanks for the post. I tried it out and it worked great!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:56 pm 
Offline
Joined: Mon Nov 17, 2003 8:59 am
Posts: 206
Location: Michigan
You're welcome. I was happy when I stumbled upon that script. Glad it worked for you. :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2004 1:57 am 
Offline
Joined: Tue Jan 06, 2004 1:21 am
Posts: 21
This is a great script for those people with a pvr-?50 card (which output in mpeg format) who want to access their recordings from a windows box.

If a ".mpg" extension is added to the created links then windows programs will see the recordings as mpeg files and will load them with out complaints.

The following lines need to be edited to allow this behavior:
Line 33:$goodfile{$nfn .".mpg"} = 1;
Line 34:if (!-e "$altpath/$nfn" .".mpg"){
Line 36:symlink "$mythpath/$ofn", "$altpath/$nfn" .".mpg" or die "Failed to create symlink $altpath/$nfn" .".mpg" .": $!";

Thanks davem


Top
 Profile  
 

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


All times are UTC - 6 hours




Who is online

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