Myth.rebuilddatabase.pl

From MythTV Official Wiki
Revision as of 20:31, 7 July 2010 by Newbury (talk | contribs)

Jump to: navigation, search

Important.png Note: The correct title of this article is myth.rebuilddatabase.pl. It appears incorrectly here due to technical restrictions.

Warning.png Warning: This script is deprecated. It has not been updated in line with changes to the main mythtv programs. The developers are looking to put this functionality into the main backend and frontend programs, but as at 28 Feb 2010 this has not been acheived. See http://www.gossamer-threads.com/lists/mythtv/users/425156#425156

myth.rebuilddatabase.pl is a script in the contrib directory that traverses the specified MythTV recordings directory and finds all files with video extensions and checks if they appear in the database. If no entry exists it prompts for identifying information and a recording entry is created.

Let's say you have a recorded program, a *.nuv file for example. And MythTV doesn't know about it (e.g., you copied it from your video directory to a backup location and then deleted it from the MythTV list of recordings). And then you want to re-introduce the recording to MythTV (so the recording shows up again in the list of recordings). How do you do that re-introduction? The myth.rebuilddatabase.pl script can do that for you.

    usage: myth.rebuilddatabase.pl [options]

    Where [options] is:
      --host          - hostname of this backend (default: "ubuntu")
      --dbhost        - hostname or IP address of the mysql server
                        (default: "ubuntu")
      --user          - DBUSERNAME (default: "mythtv")
      --pass          - DBPASSWORD (default: "mythtv")
      --database      - DATABASENAME (default: "mythconverg")
      --show_existing - Dumps current recorded table.
      --dir           - path to recordings
      --group         - Storage Group to import as (default: "Default")
      --try_default   - Try to just run with the defaults.
      --quick_run     - don't prompt for title/subtitle/description just
                        use the default
      --test_mode     - do everything except update the database
      --ext           - file extensions to scan. csh/File::Glob syntax
                        is used (ie, --ext {mpg,avi,divx})
      --file          - specific file to import
      --answer        - command-line response to prompts (give as many
                        answers as you like)
      --norename      - don't rename file to myth convention

    Example 1:
      Assumption: The script is run on DB/backend machine.

        myth.rebuilddatabase.pl --try_default

    Example 2:
      Assumption: The script is run on a backend other than the DB host.

        myth.rebuilddatabase.pl --dbhost=mydbserver

    Example 3:
      Import one specific file and supply first few answers.

        myth.rebuilddatabase.pl --file MyVideo.avi --answer y \
                     --answer 1041 --answer "My Video"

    The script chooses reasonable defaults for all values so it's possible
    to do a quick import of a single video by taking input from null:

        myth.rebuilddatabase.pl --file MyVideo.avi < /dev/null

    this also works with multiple videos but because record start time is
    synthesized from file modification time you have to be careful of
    possible collisions.

Here's an example session to re-introduce a recording.

$ cd /video
$ ls *Peach*
JamesAndTheGiantPeach.nuv
$ alias myrbdb=/local/mythtv-src/mythtv-0.20/contrib/myth.rebuilddatabase.pl
$ mysql -u mythtv -pmythtv mythconverg -e 'SELECT chanid,starttime,endtime,title,subtitle,description FROM recordedprogram WHERE title LIKE "%Peach%"'
chanid	starttime	endtime	title	subtitle	description
1059	2007-08-08 11:00:00	2007-08-08 12:30:00	James and the Giant Peach		A kindly British orphan (Paul Terry) escapes his cruel aunts (Joanna Lumley, Miriam Margolyes) to sail the sea on a giant peach with six friendly bugs. Animated.
$
$ myrbdb --dbhost localhost --file JamesAndTheGiantPeach.nuv

These are the files stored in (/video) and will be checked against
your database to see if the exist.  If they do not, you will be prompted
for a title and subtitle of the entry, and a record will be created.

/video/JamesAndTheGiantPeach.nuv
Unknown file /video/JamesAndTheGiantPeach.nuv found.
Do you want to import? [y]:
Enter channel [1002]: 1059
... title [JamesAndTheGiantPeach]: James and the Giant Peach
... subtitle:
Description [Recovered file JamesAndTheGiantPeach.nuv]: A kindly British orphan (Paul Terry) escapes his cruel aunts (Joanna Lumley, Miriam Margolyes) to sail the sea on a giant peach with six friendly bugs. Animated.
... start time (YYYY-MM-DD HH:MM:SS) [2007-08-18 20:33:23]: 2007-08-08 11:00:00
... duration (in minutes) [60]: 90
Building a seek table should improve FF/RW and JUMP functions when watching this video
Do you want to build a seek table for this file? [y]:
2007-08-20 13:12:19.260 Using runtime prefix = /usr/local
2007-08-20 13:12:19.348 New DB connection, total: 1
2007-08-20 13:12:19.366 mythcommflag version: 0.20.20060828-3 www.mythtv.org
2007-08-20 13:12:19.374 Enabled verbose msgs: important

MythTV Commercial Flagger, started at Mon Aug 20 13:12:19 2007
Rebuilding SeekTable(s) for:
ChanID  Start Time      Title                                      Status
------  --------------  -----------------------------------------  ------
2007-08-20 13:12:21.400 New DB connection, total: 2
1059    20070808110000  James and the Giant Peach                  2007-08-20 13:12:21.554 Using protocol version 30
 99%/ 1935fpsRebuilt

Finished commercial break flagging at Mon Aug 20 13
$

Version Notes

Version 0.0.3 (installed with Ubuntu's Gutsy Gibbon) does not seem to work with the --file command. As a workaround use the --ext command.

Prerequisites

On Ubuntu 6.06, 7.04, and 9.04 at least, you must install the libtime-format-perl package.

On Fedora 8,9,10,11 and 12 you need the following packages (can be grabbed with wget as noted).

Files needed by myth.rebuilddatabase.pl
wget http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.013.tar.gz
wget http://search.cpan.org/CPAN/authors/id/M/MA/MAKOTO/File-Stat-0.01.tar.gz
wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/TimeDate-1.16.tar.gz 
wget http://search.cpan.org/CPAN/authors/id/R/RO/ROODE/Time-Format-1.09.tar.g

Further Warning

The foregoing script is also deprecated in that it does not create an entry for the filesize of 'found' files, in the database. As a consequence, mythtv will report that it is unable to find the file. The following script is a long-way-round kludge to find and poke the filesize into the proper place. It can be run at any time to find and fix zero length files. It checks the database against the output of 'ls'. (And yes, this capability should be included in the script above!)

# This script checks your mythconverg database for files with a zero filesize,
# determines the file size(s) and pokes that value into the database.
# Finally, it prints a list of all files in the 'recorded' table.
# R. G. Newbury  newbury@mandamus.org 2010-07-07
#
# If this fails with a 'cannot access error' then run this as root mysql user:
# mysql -u root -p << EOF
# use mysql;
# update user set File_priv = "Y" where user = "mythtv";
# EOF

# Revise as necessary: hard-coded variables are:
# /video                           your default storage group folder
# /var/lib/mysql/junk              /var/lib/mysql is the fedora standard   
# mysql -u mythtv -pmythtv mythconverg   per your setup

rm -f /var/lib/mysql/junk
cd /video
mysql -u mythtv -pmythtv mythconverg << EOF
select basename into outfile "/var/lib/mysql/junk" from recorded where filesize = '0';
EOF
echo ""
echo ""
echo "The following files were found and the filesizes fixed:"
echo ""

for file in `cat /var/lib/mysql/junk`; do
SIZE=`ls -l $file | awk '{print $5}'`
echo "   File  $file  is  $SIZE bytes"

echo ""
echo""
mysql -u mythtv -pmythtv mythconverg << EOF
update recorded set filesize = '$SIZE' where basename = '$file';
EOF
done
echo ""
echo "This is a list of all recorded files:"
echo ""
mysql -u mythtv -pmythtv mythconverg --column-names --table << EOF
select chanid,title,subtitle,basename,filesize from recorded order by title,subtitle;
EOF

echo ""
echo ""