| 1 | #!/bin/sh
|
|---|
| 2 | # mythlink.sh
|
|---|
| 3 | #
|
|---|
| 4 | # Creates readable symlinks referring to MythTV recordings
|
|---|
| 5 | #
|
|---|
| 6 | # Based on the script mythlink.sh by Dale Gass
|
|---|
| 7 | #
|
|---|
| 8 | # Modified by Mike Dean
|
|---|
| 9 | # - Provides multiple easily-configurable "views"
|
|---|
| 10 | # - System specific information is specified as environment variables
|
|---|
| 11 | # - Uses '-' to separate portions of the filename (instead of '_' since '_'
|
|---|
| 12 | # is used to replace special characters (such as the space character))
|
|---|
| 13 | # - Shows recording year
|
|---|
| 14 | # - Shows end time
|
|---|
| 15 | # - Separates date and time info
|
|---|
| 16 | # - Removes trailing separator (i.e. for movies, which have no subtitle)
|
|---|
| 17 | # - Adds an optional extension (for specifying filetype to Windows)
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | ### Modify these values for your installation ###
|
|---|
| 21 | # The location of the MythTV Recordings (with "ugly" filenames)
|
|---|
| 22 | MYTH_RECORDINGS_PATH=/var/storage/mythtv
|
|---|
| 23 | # The path in which the views ("pretty" links) will be created
|
|---|
| 24 | VIEWS_PATH=/var/storage/mythtv/views
|
|---|
| 25 | # The extension added to the end of the links, including the period.
|
|---|
| 26 | # For no extension, specify '' for the value.
|
|---|
| 27 | EXTENSION='.mpg'
|
|---|
| 28 | # Enables output for debugging (set to 0 for no output)
|
|---|
| 29 | DEBUG=0
|
|---|
| 30 |
|
|---|
| 31 | ### The following directory names and formats may be customized ###
|
|---|
| 32 |
|
|---|
| 33 | # Formats may consist of any combination of
|
|---|
| 34 | # ${title}, ${subtitle}
|
|---|
| 35 | # ${date}, ${starttime}, ${endtime}, ${originalairdate}
|
|---|
| 36 | # ${category}, ${recgroup}
|
|---|
| 37 |
|
|---|
| 38 | # Files will be sorted "alphabetically" so the appropriate fields on which you
|
|---|
| 39 | # would like to sort should be placed at the beginning of the format
|
|---|
| 40 |
|
|---|
| 41 | # Formats of the individual fields were chosen to minimize confusion caused by
|
|---|
| 42 | # use of different sorting algorithms by clients (i.e. alphabetically versus
|
|---|
| 43 | # alphanumerically).
|
|---|
| 44 |
|
|---|
| 45 | # To add a custom format, simply include a directory name and format in the
|
|---|
| 46 | # environment variables below. (Whitespace separates the values.)
|
|---|
| 47 |
|
|---|
| 48 | # The names of the directories containing the views
|
|---|
| 49 | DIRECTORIES='time
|
|---|
| 50 | title
|
|---|
| 51 | group
|
|---|
| 52 | category
|
|---|
| 53 | original_airdate'
|
|---|
| 54 | # The formats used for the respective directories specified above
|
|---|
| 55 | FORMATS='${date}-${starttime}-${endtime}-${title}-${subtitle}
|
|---|
| 56 | ${title}-${date}-${starttime}-${endtime}-${subtitle}
|
|---|
| 57 | ${recgroup}-${title}-${date}-${starttime}-${endtime}-${subtitle}
|
|---|
| 58 | ${category}-${title}-${date}-${starttime}-${endtime}-${subtitle}
|
|---|
| 59 | ${title}-${originalairdate}-${subtitle}'
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | ### These values most likely do not need modification ###
|
|---|
| 63 | # The name of the MythTV database
|
|---|
| 64 | MYTH_DB=mythconverg
|
|---|
| 65 | # The database username and password
|
|---|
| 66 | MYTH_DB_USER=mythtv
|
|---|
| 67 | MYTH_DB_PASSWD=mythtv
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | export MYTH_RECORDINGS_PATH VIEWS_PATH EXTENSION DEBUG DIRECTORIES FORMATS
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | for dir in ${DIRECTORIES}
|
|---|
| 74 | do
|
|---|
| 75 | rm -rf ${VIEWS_PATH}/${dir}/*
|
|---|
| 76 | done
|
|---|
| 77 | mysql -u${MYTH_DB_USER} -p${MYTH_DB_PASSWD} ${MYTH_DB} -B --exec "select chanid,starttime,endtime,title,subtitle,recgroup,category,originalairdate from recorded;" >/tmp/mythlink.$$
|
|---|
| 78 | perl -w -e '
|
|---|
| 79 | my $mythpath=$ENV{"MYTH_RECORDINGS_PATH"};
|
|---|
| 80 | my $viewspath=$ENV{"VIEWS_PATH"};
|
|---|
| 81 | my $extension=$ENV{"EXTENSION"};
|
|---|
| 82 | my $debug=$ENV{"DEBUG"};
|
|---|
| 83 | my $dirs=$ENV{"DIRECTORIES"};
|
|---|
| 84 | my $fmts=$ENV{"FORMATS"};
|
|---|
| 85 | my @directories=split(/\s+/,$dirs);
|
|---|
| 86 | my @formats=split(/\s+/,$fmts);
|
|---|
| 87 | if (!-d ${viewspath}) {
|
|---|
| 88 | mkdir ${viewspath} or die "Failed to make directory: ${viewspath}\n";
|
|---|
| 89 | }
|
|---|
| 90 | foreach (@directories) {
|
|---|
| 91 | if (!-d "${viewspath}/$_") {
|
|---|
| 92 | mkdir "${viewspath}/$_" or die "Failed to make directory: ${viewspath}/$_\n";
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|
| 95 | <>;
|
|---|
| 96 | while (<>) {
|
|---|
| 97 | chomp;
|
|---|
| 98 | my ($chanid,$start,$end,$title,$subtitle,$recgroup,$category,$originalairdate) = split /\t/;
|
|---|
| 99 | $start =~ s/[^0-9]//g;
|
|---|
| 100 | $end =~ s/[^0-9]//g;
|
|---|
| 101 | $subtitle = "" if(!defined $subtitle);
|
|---|
| 102 | my $filename = "${chanid}_${start}_${end}.nuv";
|
|---|
| 103 | do { print "Skipping ${mythpath}/${filename}\n"; next } unless -e "${mythpath}/${filename}";
|
|---|
| 104 | $end =~ /^........(....)/;
|
|---|
| 105 | my $endtime = $1;
|
|---|
| 106 | $start =~ /^(........)(....)/;
|
|---|
| 107 | my $date = $1;
|
|---|
| 108 | my $starttime = $2;
|
|---|
| 109 | $originalairdate =~ s/[^0-9]//g;
|
|---|
| 110 | $originalairdate = "00000000" if(($originalairdate eq ""));
|
|---|
| 111 | for ($i = 0; $i < @directories; $i++) {
|
|---|
| 112 | my $directory = $directories[$i];
|
|---|
| 113 | my $link=$formats[$i];
|
|---|
| 114 | $link =~ s/(\${\w+})/$1/gee;
|
|---|
| 115 | $link =~ s/-$//;
|
|---|
| 116 | $link =~ s/ /_/g;
|
|---|
| 117 | $link =~ s/&/+/g;
|
|---|
| 118 | $link =~ s/[^+0-9a-zA-Z_-]+/_/g;
|
|---|
| 119 | $link = $link . $extension;
|
|---|
| 120 | print "Creating $link\n" if ($debug);
|
|---|
| 121 | unlink "${viewspath}/${directory}/${link}" if(-e "${viewspath}/${directory}/${link}");
|
|---|
| 122 | symlink "${mythpath}/${filename}", "${viewspath}/${directory}/${link}" or die "Failed to create symlink ${viewspath}/${directory}/${link}: $!";
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 | ' /tmp/mythlink.$$
|
|---|
| 126 | rm /tmp/mythlink.$$
|
|---|
| 127 |
|
|---|