Kodi Community Forum

Full Version: mythicalLibrarian - a tool to build Movie and TV Show library from MythTV recordings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Just set XBMC to update library on startup. Or, you can make a button on your desktop to do

Code:
XBMCIP=192.168.1.110:8080 && curl -s -m1 "http://"$XBMCIP"/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(mythical%20Librarian%2Cadding%20shows%20to%20library))" && sleep 1  &&  curl -s -m1 "http://"$XBMCIP"/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video))" && sleep 30 && curl -s -m1 "http://"$XBMCIP"/xbmcCmds/xbmcHttp?command=ExecBuiltIn(CleanLibrary)"
change XBMCIP= to your ip
Then you can use this transparrent background icon I made for the shortcut
Image
barney_1 Wrote:I took this idea and modified it a bit to work for me. I wrote a comanion script for mythical librarian that will delete symlinks and the database entry that accompanies them:
Code:
#!/bin/sh

### myth-remove-from-library.sh - Use to remove a sym-linked mythtv recording and it's database entries

#Grab command line arguments
VIDEODIR=$1
FILENAME=$2

#Make sure we got command line arguments
if [ -z "${VIDEODIR}" -o -z "${FILENAME}" ]; then
        echo "Usage: $0 <VideoDirectory> <FileName> "
        exit 5
fi

#Test that input files exists and is a symbolic link (we don't want to delete actual recordings)
if [ ! -h "${VIDEODIR}/${FILENAME}" ]; then
        echo "File does not exist or is not a symbolic link: ${VIDEODIR}/${FILENAME}"
        exit 6
fi

#Remove recording entry from 'mythconverg' mysql database
    echo "Removing ${FILENAME} from recorded table"
        cat << EOF | mysql -u mythtv -pmythtv mythconverg
DELETE FROM
        recorded
WHERE
        basename = '${FILENAME}';
EOF

#Remove symblink file and thumbnails
    echo "Removing ${FILENAME} file and thumbnails"
    rm -f ${VIDEODIR}/${FILENAME}
    rm -f ${VIDEODIR}/${FILENAME}.*

exit 0
I then just added a command to execute this script. I added this to mythicalLibrarian.sh in the "MOVE" section, after the Success message is written:
Code:
...
#Send notification to daily report log
             dailyreport "$ShowFileName"
              echo "@@@@@@@@@@@@@OPERATION COMPLETE" `date` "@@@@@@@@@@@@@@@@">>"$mythicalLibrarian"/output.log
            #Use script to remove the sym-link and database entry from mythtv
            /home/mythtv/myth-remove-from-library.sh "`dirname "$3"`" "`basename "$3"`"
               exit 0
...
Works like a charm. Now I know that any videos still hanging out in the mythtv recordings are not being recognized by mythical librarian and need to be moved manually.

I could add this in as a function for "SYMLINK=Disabled", with your permsision of course.
outleradam Wrote:I could add this in as a function for "SYMLINK=Disabled", with your permsision of course.

That'd be great. I made it a separate script so that it would be easy for me to upgrade to new versions of your script. If you integrate it that means no work for me at all!
I made some changes, but it's mostly intact. You should grab the SVN and test it out to verify. The smart installer will be comming soon.

Code:
SYMLINKDisabled () {

#Grab command line arguments
    VIDEODIR=$1
    FILENAME=$2

#Make sure we got command line arguments
     if [ -z "${VIDEODIR}" -o -z "${FILENAME}" ] && [ ! -h "${VIDEODIR}/${FILENAME}" ]; then
         echo "ATTEMPTED DATABASE DELETE:FILE DOES NOT EXIST OR IS NOT A SYMBOLIC LINK.">>"$mythicalLibrarian"/output.log
     else
    
#Remove recording entry from 'mythconverg' mysql database
         echo "REMOVING - ${FILENAME} - THUMBNAILS - DATABASE ENTRIES">>"$mythicalLibrarian"/output.log
          echo "REMOVING - ${FILENAME} - THUMBNAILS - DATABASE ENTRIES"
        mysql -u$MySQLuser -p$MySQLpass -e "use '$MySQLMythDb' ; delete from recorded where basename like '${FILENAME}'; "

#Remove symbolink file and thumbnails
         rm -f ${VIDEODIR}/${FILENAME}
         rm -f ${VIDEODIR}/${FILENAME}.*    
     fi
}
Oh yeah, also added custom commands to be run upon your request. Last line of user settings

Code:
#Command to be run on Failed job
FailedJob="echo failed"
#Command to be run on sucessful job
SucessfulJob="echo Sucessful"
Oh yeah, Variables are possible
$ShowName = input show name
$NewShowName = sucessfully resolved show name
$exx = Episode Number or "Movie" in case of a movie
$sxx = Season number or blank in case of movie
$epn = Subtitle
$ChanID = ChannelID
$ProgramID= Zap2it listing
$plot = plot
$stars = stars
$ShowStartTime = begin recording time
$ShowCategory = category like children or sports
$OriginalAirDate = original air date
$XMLTVGrabber = your guide data type
$MovieAirDate = the original year the movie aired
$mythicalLibrarianProgramIDCheck = SH MV or EP
$ProgramIDType= Generic episode with no data, Movie, or Series With Episode Data
$Zap2itSeriesID= Zap2it ID with SH, MV or EP stripped
$seriesid = TheTVDB series ID
$TvDbTime = current tvdb time
$LastUpdated = last updated time (for Episodes only others wil be blank)
$absolouteEpisodeNumber = tvdb order (for Episodes only)
$ShowFileName = name of the file (if sucessful)
$originalext = file's "EXT"ension
$originaldirname = dirname of the file to be moved
$FileBaseName = name of the file to be moved without ext
$MyUserName = name of user running mythicalLibrarian

Whoo... there's more too.
Wow, awesome work! I'm off to the pub but will try this out tomorrow.
I chagned that function again to use internal variables instead of passing internal to external back to internal. Also, changed conditions. Since it is SYMLINK=Disabled, no link will be created.

Code:
#####REMOVE ENTRIES FROM LIBRARY#####
# myth-remove-from-library.sh - Use to remove a sym-linked mythtv recording and it's database entries.  Thanks to barney_1.
SYMLINKDisabled () {

#Make sure we got input arguments and file is valid
     if [ -f "$3" ]; then
         echo "DATABASE ENTRIES COULD NOT BE DELETED- FILE STILL EXISTS">>"$mythicalLibrarian"/output.log
     else "$originaldirname" "$FileBaseName"
    
#Remove recording entry from 'mythconverg' mysql database
         echo "REMOVING - $FileBaseName - THUMBNAILS - DATABASE ENTRIES">>"$mythicalLibrarian"/output.log
          echo "REMOVING - $FileBaseName - THUMBNAILS - DATABASE ENTRIES"
        mysql -u$MySQLuser -p$MySQLpass -e "use '$MySQLMythDb' ; delete from recorded where basename like '$FileBaseName'; "

#Remove symbolink file and thumbnails
         rm -f "$originaldirname/$FileBaseName"
         rm -f "$originaldirname/$FileBaseName".*    
     fi
}
Back from the pub but was visited by the muse while there. What do you think about an RSS feed reported from this script? That way you could see what new shows you have, and get reports on failed matches.

I may try an implementation of this myself if I get a bit of extra time.
I was thinking about that. I had messed around with the RSS feeds for a while, but I decided to call it quits after realizing the Really Simple Syndication was not that simple. It would require making a rotating file of some sort. Maybe a day or two of the daily report. Dunno. There should be more then enough variables to make an external script with an RSS.
Code:
#####REMOVE ENTRIES FROM LIBRARY#####
#remove mythtv recording's pictures and database entries.  Thanks to barney_1.
SYMLINKDisabled () {

#Make sure we got input arguments and file is valid
     if [ ! -f "$3" ]; then
    
#Remove recording entry from mysql database
         echo "REMOVING - $FileBaseName - THUMBNAILS - DATABASE ENTRIES">>"$mythicalLibrarian"/output.log
          echo "REMOVING - $FileBaseName - THUMBNAILS - DATABASE ENTRIES"
        mysql -u$MySQLuser -p$MySQLpass -e "use '$MySQLMythDb' ; delete from recorded where basename like '$FileBaseName'; "

#Remove thumbnails
         rm -f "$originaldirname/$FileBaseName".*    
     fi
}
since there was some testing before the file was moved, there is no reason to have a message that it was not moved. Just verify that it is moved before executing the function.

Just did another revision update removed some randomness from that last one. Gee, I wish I could test this before uploading, but if I did, then I'd loose data.
Sorry, haven't tested the new version yet. I've hammer-out a proof of concept RSS builder. It uses the DailyLogs and for now, just makes an entry for each line and makes that line a title.

Questions:
-Is this something that will be useful?
-If we want to implement this can failure info be added as part of these reports?
-Links are required in RSS feeds... what would these items link to?

Anyway, let me know and I can do some work on limiting the number of days that are included in the RSS and using the data at hand in a better way.
Code:
#!/bin/sh

reportDIR="/home/mythtv/mythicalLibrarian/DailyReport/"
rssFile="/var/www/mythical-rss/rss.xml"

#Setup the rss file
echo '<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">

<channel>
  <title>Myhtical Librarian</title>
  <link>http://xbmc.org</link>
  <description>Mythical Library Daily Report Information</description>' > $rssFile

for thisReport in $(ls -l $reportDIR | awk '{print $8}')
do
    echo "$(awk '{ print "  <item>\n    <title>" $0 "</title>\n    <link>http://xbmc.org</link>\n    <description>Put description here</description>\n  </item>"}' $reportDIR/$thisReport)" >> $rssFile
done
echo '</channel>

</rss>' >> $rssFile

Here's part of a sample output. Please note that I didn't to anything to include or control chronology but that's pretty easy to add later.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">

<channel>
  <title>Myhtical Librarian</title>
  <link>http://xbmc.org</link>
  <description>Mythical Library Daily Report Information</description>
  <item>
    <title>16:00:09 How I Met Your Mother.S05E14 (The Perfect Week)</title>
    <link>http://xbmc.org</link>
    <description>Put description here</description>
  </item>
  <item>
    <title>22:20:58 NOVA.S37E12 (Ghosts of Machu Picchu)</title>
    <link>http://xbmc.org</link>
    <description>Put description here</description>
  </item>
  <item>
    <title>23:49:04 Frontline PBS.S2010E01 (Digital Nation)</title>
    <link>http://xbmc.org</link>
    <description>Put description here</description>
  </item>
barney_1 Wrote:Sorry, haven't tested the new version yet. I've hammer-out a proof of concept RSS builder. It uses the DailyLogs and for now, just makes an entry for each line and makes that line a title.

Questions:
-Is this something that will be useful?
-If we want to implement this can failure info be added as part of these reports?
-Links are required in RSS feeds... what would these items link to?

Anyway, let me know and I can do some work on limiting the number of days that are included in the RSS and using the data at hand in a better way.

First off, I'm feeling a bit off right now, so if this does not make sense, then please let me know.

1. Yes this would be very useful. It should be possible to use the new RSS tool with XBMC to change the RSS feed to the one generated by mythicalLibrarian.

2. Yes This would be great to add, assuming the list can be made to rotate efficiently.

hrm...
numberofentries=grep -c "</item>" /thelist
cat /thelist itemdelete=grep -m1 <item>
...
...
...
and then cat /thelist with a tr -d itemdelete ... ... ... grep match.

3. I was looking at that.. Recognized episodes could go to
I have no idea about shows, but Episodes:
Code:
http://thetvdb.com/?tab=series&id=$seriesid
where $seriesid is defined in mythicalLibrarian
Movies:
Code:
moviename=`echo $NewShowName |tr -d :punct:|tr -d " "
http://www.imdb.com/find?s=all&q=$moviename

I'll try to think of something for shows. They will be comming after I finish the easy installer.
ok, due to the XBMC crash, we have lost alot of data in this thread. If anyone recalls anything important, please post it up.

Easy installation instructions:
Code:
sudo apt-get install curl && mkdir ~/.mythicalLibrarian && mkdir ~/.mythicalLibrarian/mythicalSetup && cd ~/.mythicalLibrarian/mythicalSetup
curl http://mythicallibrarian.googlecode.com/svn/trunk/mythicalSetup.sh>./mythicalSetup.sh
sudo chmod +x ./mythicalSetup.sh && sudo ./mythicalSetup.sh
I am not working on anything having to do with mythicalLibrarian right now, so please submit bug reports.
yikes... I got pretty much erased...

SVN 256 is stable; There was a guy who was asking if he should update his MythTV to the latest 0.22+fixes I believe...