Linux-Script List Of All Effective Scrapers

This script queries XBMC's (movie-)database and generates a simple list showing the effectively used scraper for every path entry, even if this entry has no scraper definition by its own.

Warning
This script should be harmless but as it writes out two files, there are chances you might overwrite something when running this script. So be careful and adjust the settings first!

Description
This script does a read-only query to the database which contains the library information for the video items and extracts all defined paths with their associated scrapers. As some paths don't have a scraper definition by their own, they inherit this definition from their parent directory. Within the database structure this isn't obvious at all and even sorting the list of paths by their name doesn't make it much better. This script helps in that it writes out a line for every path and the scraper that is used for it. Not existing scraper definitions get inheritet from their parent entries. In the end, every line states clear and obvious which scraper gets used and which content type is set.

Results
As result there are two files generated:

The filenames are effectively preceeded with the content of the variable PREFIX.

Attention: the entry for the root directory "/" gets deleted as this entry doesn't really belong to the path structure and therefore contains no scraper definition. As it has no parent entry either, there can't be a scraper definition inherited and this used to break my script. So the script deletes it while processing the output.


 * db_scraper_path: this is the original list from the database. Every line contains three elements, separated by a tab-stop: the path, the content and the scraper. If something goes wrong or if you miss an entry in the other file, have a look into this file. If a path isn't listed here, it isn't stored in the database at all.
 * db_scraper: this file contains the improved list. Every line contains three elements, separated by blanks: the path, the scraper and surrounded by parenthesis the content type.

Settings
The following settings are available in this script and you are urged to check them and adjust them if needed to fit your environment:


 * DBPATH points to the video-database (the file itself, not just the directory)
 * PREFIX will set a prefix that is used for the files that are created during the runtime of the script. It may include an absolute or relative path and a prefix of the filename. A good idea for this setting is something like the homefolder and a file-prefix or a temporary folder. Any given folder must already exist.

Execution
All you need to do is copy the code to an empty textfile, adjust the settings to your needs, save this file and run it with the following command

sh

You might also set the executable-bit to the file and run it directly, just as you like. chmod +x

Sourcecode

 * 1) !/bin/bash
 * 2)  Scraper
 * v1
 * 1) created by BaerMan for XBMC-community
 * 2) This script may be used for any purposes.
 * 3) You may change, sell, print or even sing it
 * 4) but you have to use it at your own risk!
 * 5) This script is ugly and may under certain circumstances crash your
 * 6) computer, kill your cat and/or drink your beer.
 * 7) Use it at your own risk!
 * 8) This script just lists the scrapers that are actuallay used for a given
 * 9) path entry
 * 1) Use it at your own risk!
 * 2) This script just lists the scrapers that are actuallay used for a given
 * 3) path entry
 * 1) path entry


 * 1) Settings ###
 * 1) Settings ###

DBPATH="/home/xbmc/.xbmc/userdata/Database/MyVideos34.db"
 * 1) Full path to the video-database ; may be absolute (preceeded by a
 * 2) slash "/") or relative form the current directory

PREFIX=/home/xbmc/xbmc_ DBPATHLIST=${PREFIX}db_scraper_path.lst SCRAPERLIST=${PREFIX}db_scraper.lst
 * 1) Filenames for results
 * 2) You may change these to any name and place you like but beware not to
 * 3) overwrite or delete files you may still need

SQLITECMD="sqlite3" ; GREPCMD="grep" ; RMCMD="rm"
 * 1) Programs used ; either absolute path or command only if path to the
 * 2) binary is in variable $PATH ; each command may be extended by optional
 * 3) arguments - refer to the specific manpage for details

${RMCMD} ${DBPATHLIST} $SCRAPERLIST 2>/dev/null
 * 1) working code ###
 * 1) working code ###

${SQLITECMD} -list -separator ' ' ${DBPATH} \ "select strPath, strContent, strScraper from path order by strPath;" \ | ${GREPCMD} -v ^"/  " > ${DBPATHLIST}

aPATH="" ; fPATH="" Scraper="" ; aScraper="" Content="" ; aContent="" IFS=' ' for fPATH in $(<${DBPATHLIST}) ; do   aPATH=`echo $fPATH|cut -f 1` Content=`echo $fPATH|cut -f 2` Scraper=`echo $fPATH|cut -f 3` if [ z$Content == 'zNone' ] ; then # this path element is not to be scanned aScraper="SKIPPED" aContent=$Content elif [ z$Scraper == 'z' ] ; then # this path has no own scraper definition if [ z$aScraper == 'z' ] ; then # even no previous definition exists ... not good echo "Error, something bad happened!" echo -e "$fPATH \n\t$Content \n\t$aScraper" exit fi   fi    echo "$aPATH: $aScraper ($aContent)" >> $SCRAPERLIST done unset IFS
 * 1) initializing some variables

Discussion
Discussion about this script is in the Forum: http://forum.kodi.tv/showthread.php?t=62219