Archive:MythicalLibrarian UserJobs

From Official Kodi Wiki
Jump to navigation Jump to search

mythicalLibrarian UserJobs

Archive:MythicalLibrarian has incorporated user jobs to allow users to expand mythcialLibrarian to suit their needs without having to worry about loosing their changes when upgrading. User jobs are bash code which run at the end of mythicalLibrarian. Everything which mythicalLibrarian does can be undone or redone using user jobs and a bit of wit.

user jobs are a part of mythicalLibrarian

during mythicalSetup (aka mythicalLibrarian --update), the latest version of mythicalLibrarian is downloaded. mythicalSetup separates the code portion of the script from the user portion of the script. Think of the code portion as unmaintainable and dynamic from a user perspective, that is, it will change frequently. mythicalSetup then asks a series of questions and makes decisions based on your computer's setup. The final step before actually inserting the code into your user portion is to insert the user jobs.

Job Files

Normally, you will only want to script the JobSucessful job. However, the available user jobs are as follows:

  • /etc/mythicalLibrarian/JobSucessful -Is run when mythicalLibrarian completes in the most appropriate manner
  • /etc/mythicalLibrarian/JobInformationNotComplete -Is run when mythcalLibrarian determines there was not sufficient information to name the file according to standards. This type of job occurs when mythicalLibrarian attempts to rename by season and episode, but cannot obtain the information from TheTvDb. This is also accompanied by a spot in the --doover job file.
  • /etc/mythicalLibrarian/JobFilesystemError - Is run when mythcialLibrarian detects that it does not have proper permissions on one or more of the required folders.
  • /etc/mythicalLibrarian/JobInsufficientData - Is run in place of JobInformationNotComplete when the user elects not to process shows without required information. AKA. Showstopper.
  • /etc/mythicalLibrarian/JobIgnoreList - Is run when the user elects to ignore a show based on category or Title.
  • /etc/mythicalLibrarian/JobGenericError - Is run when mythicalLibrarian is not given enough information and has no TV Recording database to work with
  • /etc/mythicalLibrarian/JobUnspecified - This job should never be run unless you are debugging. It is called when RunJob is called in mythicalLibrarian and there is no JobType variable set.

Only one of these jobs will be run by mythicalLibrarian before it exits.

Variables for use in user jobs

The following variables can be used in any user job.

  • ALL RECORDINGS - these variables will be set on all recordings
$MoveDir/$ShowFileName.$originalext = location of moved file.
$ShowName = Processed Title
$InputTitle = actual database title
$MoveDir = the folder to which the file was moved ie. "/home/mythtv/videos/Episode"
$ShowFileName = the name of the show moved, not including extension eg. "simpsons S01E02 (foo)" or "MovieTitle(year)"
$originalext = original file extension  eg "mpg"
$NewShowName = Successfully resolved show name
$ChanID = ChannelID
$ProgramID= Zap2it listing
$ShowStartTime = begin recording time
$ShowCategory = category like children or sports
$mythicalLibrarianProgramIDCheck = "SH" for SHow or sports - "MV" for MoVie - "EP" for EPisode
$plot = plot
$stars = stars
$FileBaseName = name of the file to be moved without ext 
$XMLTVGrabber = your guide data type
$ProgramIDType= Generic episode with no data, Movie, or Series With Episode Data
$Zap2itSeriesID= Zap2it ID with SH, MV or EP stripped
$MyUserName = name of user running mythicalLibrarian
$SafeShowName = title of show after showtranslations formatted for filesystem use
  • EPISODES AND GENERIC SHOWS -These variables will be set only on series type shows
$OriginalAirDate = original air date  Generic programming will be the first episode ever, for episodes it will be the first aired date
$epn = Subtitle or EPisode Name
  • EPISODES AND MOVIES - This variable will be set only for shows with season/episode information or movies
$exx = Episode Number or "Movie" in case of a movie
  • EPISODES -These variables will be set
$sxx = Season number or blank in case of movie
$seriesid = TheTVDB series ID
$TvDbTime = current tvdb time
$LastUpdated = last updated time (for Episodes only others wil be blank) 
$absolouteEpisodeNumber = tvdb order numbering
  • MOVIES - This variable will only be set for a movie
$MovieAirDate = the original year the movie aired

Depending on the recording, different variables will be available. Unused variables will be blank.

Examples

Transcoding and Tracking

The following is an example which transcodes a file

/etc/mythicalLibrarian/JobSucessful:

#Run a transcoding program on the file
ffmpeg -i S:"$MoveDir/$ShowFileName.$originalext" -target ntsc-svcds:"$MoveDir/$ShowFileName.mp4"

#Write the new file extension over the old extension for logging
originalext=mp4 

#Run logging for the new file extension so mythicalLibrarian can keep track of files it created.
performLoggingForMoveMode #or performLoggingForLinkMode
 
#remove the mythicalLibrarian symlink
rm "$InputPath"

#make a new symlink
ln -s  "$MoveDir/$ShowFileName.originalext" "$InputPath"

#Enable Kodi Communications which were disabled so mythicalLibrarian did not communicate when the command was called before
XBMCUpdate=Enabled
XBMCClean=Enabled
XBMCNotify=Enabled

#Tell mythicalLibrarian to send a message to Kodi and update the library
XBMCAutomate

#Don't exit, just let mythicalLibrarian take back over.


Multilingual Recognition

The following is a multilingual example which first searches TheTvDb in English, then tries Spanish. You need two mythicalLibrarian executables, one which has the Language setting to English

/usr/local/bin/mythicalLibrarian:

...
#Language setting
Language=en
...

and a copy of mythicalLibrarian, called "mythicalLibrarianSP" with the Language setting set to Spanish /usr/local/bin/mythicalLibrarianSP:

...
#Language setting
Language=sp
...

This allows for two instances of mythicalLibrarian to run in sequence for those who are multi-lingual. So the rest of the setup is cake. Just create a file like this one and mythicalLibrarian will run through TheTvDb in English, then when it is unable to process a match, it runs through TheTvDb in Spanish.

/etc/mythicalLibrarian/JobInformationNotComplete:

test "$Language" = "sp" && Exit 0
test "$Language" != "sp" && mythicalLibrarianSP

Notes

Don't try to override a setting with a user job. If you wish to set a variable as a "global setting" Place that variable in the global settings file

/etc/mythicalLibrarian/globalSettings"

SYMLINK=Disabled                                 
AlternateMoveDir=/media/usbDrive 
NotifyUserName=adam                              
XBMCIPs=( "user:[email protected]:8080" )                
MySQLpass="Gq3117m8"