Archive:Linux-Script List Of All Effective Scrapers

From Official Kodi Wiki
Jump to navigation Jump to search

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 <filename>

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

chmod +x <filename>


Sourcecode

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

################
### Settings ###
################

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

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

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

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

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

# initializing some variables
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


Discussion

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