NFO Generator from sqlite db
#1
I haven't bothered making nfos for my films as I add them however I do use the scrapers to add to the sqlite database. So rather than add NFOs by hand I wrote this script.

It will only work for movies & music videos (tvshows will be added later & music may be added if I get round to it (None of my music is in the DB yet))

****************************************************
WARNING
If you value your files DO NOT USE!! I am not responsible if your house blows up after using this script. Use it at your own risk.
****************************************************

In saying that there is some error checking (if a nfo exists it *should* ignore it (if the names match), I'll maybe implement updating nfos later).
Some fields are left blank simply because they are blank in my db please submit unified (3line) diffs so I can apply them directly if you wish to help get this working.

This has only been roughly tested under linux though it should work under windows.

All comments are welcome.

Code:
#!/usr/bin/python
#
# Generates NFOs from XBMCs SQLite Database
# Copyright Ryan McLean,
#
# License: GPL v2 or later
#
# Requires python-sqlite
#
import sys, os
from stat import *
from pysqlite2 import dbapi2 as sqlite

version = "0.0.1"

def help():
        print sys.argv[0]+" version "+version
        print "Copyright Ryan McLean,
        print "License: GPL v2 or later\n"
        print sys.argv[0]+" [movie|music|musicvid|tv] <pathTO.xbmc>"
        print "E.g."
        print sys.argv[0]+" movie /home/xbmc"
        sys.exit(1)

argc = len(sys.argv)
if argc < 3:
        help()

def writefile(nfoPath, nfoName, nfoData):
        fname = nfoPath + nfoName + ".nfo"
        if not os.path.isfile(fname):
                try:
                        outfile = open(fname, 'w')
                        outfile.write(nfoData)
                        outfile.close()
                except IOError, e:
                        if e.errno==13:
                                print "Failed to create \"" + nfoName + ".nfo\", You do not have permission to write to " + nfoPath
        else:
                print nfoName + ".nfo already exists, skipping"

def MovieOut(data):
        mo = "<movie>\n"
        mo += " <title>"+data[0]+"</title>\n"
        mo += " <originaltitle>"+data[0]+"</originaltitle>\n"
        mo += " <rating>"+data[4]+"</rating>\n"
        mo += " <year>"+data[6]+"</year>\n"
        mo += " <top250></top250>\n"
        mo += " <votes></votes>\n"
        mo += " <outline>"+data[2]+"</outline>\n"
        mo += " <plot>"+data[1]+"</plot>\n"
        mo += " <tagline>"+data[3]+"</tagline>\n"
        mo += " <runtime>"+data[8]+"</runtime>\n"
        mo += " <thumb></thumb>\n"
        mo += " <mpaa>Not available</mpaa>\n"
        mo += " <playcount>0</playcount>\n"
        mo += " <watched>false</watched>\n"
        mo += " <id>"+data[7]+"</id>\n"
        mo += " <filenameandpath>"+data[11]+data[12]+"</filenameandpath>\n"
        mo += " <trailer></trailer>\n"
        mo += " <genre>"+data[9]+"</genre>\n"
        mo += " <credits></credits>\n"
        mo += " <director>"+data[10]+"</director>\n"
        actors = data[5].split('/')
        for actor in actors:
                mo += " <actor>\n"
                mo += "  <name>"+actor.strip()+"</name>\n"
                mo += "  <role></role>\n"
                mo += " </actor>\n"
        mo += "</movie>"

        nfoName = data[12].rsplit('.',1)
        writefile(data[11], nfoName[0], mo)

#def MusicOut(data):
#       print "TBC"

def MusicVidOut(data):
        mo = "<musicvideo>\n"
        mo += " <title>"+data[0]+"</title>\n"
        mo += " <artist>"+data[5]+"</artist>\n"
        mo += " <album>"+data[4]+"</album>\n"
        mo += " <genre></genre>\n"
        mo += " <runtime></runtime>\n"
        mo += " <plot></plot>\n"
        mo += " <year>"+data[3]+"</year>\n"
        mo += " <director>"+data[1]+"</director>\n"
        mo += " <studio>"+data[2]+"</studio>\n"
        mo += "</musicvideo>"

        nfoName = data[7].rsplit('.',1)
        writefile(data[6], nfoName[0], mo)

#def TVOut(data):
#       print "TBC"

def movie():
        # Query the DB
        cursor.execute('SELECT movie.c00 as Name, movie.c01 as Plot, movie.c02 as Outline, movie.c03 as Tagline, movie.c05 as Rating, movie.c06 as Actors, movie.c07 as Year, movie.c09 as ID, movie.c11 as Runtime, movie.c14 as Genre, movie.c15 as Director, path.strPath, files.strFilename FROM movie, files, path WHERE files.idFile = movie.idFile AND path.idPath = files.idPath ORDER BY movie.c00')

        for row in cursor:
                MovieOut(row)

def musicVid():
        print "TBC"
        cursor.execute('SELECT musicvideo.c00 as Title, musicvideo.c05 as Director, musicvideo.c06 as Studio, musicvideo.c07 as Year, musicvideo.c09 as Album, musicvideo.c10 as Artist, path.strPath, files.strFilename FROM musicvideo, files, path WHERE files.idFile = musicvideo.idFile and path.idPath = files.idPath ORDER BY musicvideo.c00')
        for row in cursor:
                MusicVidOut(row)

def tvshow():
        print "TBC"
#       cursor.execute('')
#       for row in cursor:
#               TVOut(row)

def music():
        print "TBC"
#       cursor.execute('')
#       for row in cursor:
#               MusicOut(row)

############# MAIN ####################
if os.path.exists(sys.argv[2]):
        if sys.argv[1] == "movie":
                # Create connection
                connection = sqlite.connect(sys.argv[2]+'/.xbmc/userdata/Database/MyVideos34.db')
                # Create cursor Obj to do interaction
                cursor = connection.cursor()
                movie()

        elif sys.argv[1] == "musicvid":
                # Create connection
                connection = sqlite.connect(sys.argv[2]+'/.xbmc/userdata/Database/MyVideos34.db')
                # Create cursor Obj to do interaction
                cursor = connection.cursor()
                musicvid()

        elif sys.argv[1] == "tv":
                # Create connection
                connection = sqlite.connect(sys.argv[2]+'/.xbmc/userdata/Database/MyVideos34.db')
                # Create cursor Obj to do interaction
                cursor = connection.cursor()
                tvshow()

        elif sys.argv[0] == "music":
                # Create connection
                connection = sqlite.connect(sys.argv[2]+'/.xbmc/userdata/Database/MyMusic7.db')
                # Create cursor Obj to do interaction
                cursor = connection.cursor()
                music()
        else:
                help();
else:
        print sys.argv[2] + " does not exist"
MC1 (SD & HD): Asus A8N SLI, AMD x2 4600+, 2GB DDR 400 Cosair, Palit Nvidia 9400GT 1GB (Passive), ARTIC 500W PSU, Lian Li PC-C32B, Samsung 250GB SATA
MC2 (SD&HD): RaspberryPi
MC3 (SD&HD): RaspberryPi
NAS1: HP Prolient Microserver N40L 2Gb Ram, 250Gb OS Disk, 1x2TB HDD ext4, 5.25" to 3.5" disk drive added to ODD Slot for OS disk

Blog: http://ninet.org
Reply
#2
Neat. Doesn't XBMC do this for you though on export?

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#3
Yeah, export to separate files will do it.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not PM or e-mail Team-Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#4
lol.. balls. Was gonna add that as a feature request.. Aw well, it kept me amused for an hour.
MC1 (SD & HD): Asus A8N SLI, AMD x2 4600+, 2GB DDR 400 Cosair, Palit Nvidia 9400GT 1GB (Passive), ARTIC 500W PSU, Lian Li PC-C32B, Samsung 250GB SATA
MC2 (SD&HD): RaspberryPi
MC3 (SD&HD): RaspberryPi
NAS1: HP Prolient Microserver N40L 2Gb Ram, 250Gb OS Disk, 1x2TB HDD ext4, 5.25" to 3.5" disk drive added to ODD Slot for OS disk

Blog: http://ninet.org
Reply
#5
Perhaps you could tweak it a bit so it could take in a movie or show name for those that want to do selective exports?

I'm sure someone will find a use for it Smile

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#6
just noticed xbmc Export outputs to .xbmc/temp and doesnt care if it exports music videos or movies. Mine exports to the dir the file is in.
MC1 (SD & HD): Asus A8N SLI, AMD x2 4600+, 2GB DDR 400 Cosair, Palit Nvidia 9400GT 1GB (Passive), ARTIC 500W PSU, Lian Li PC-C32B, Samsung 250GB SATA
MC2 (SD&HD): RaspberryPi
MC3 (SD&HD): RaspberryPi
NAS1: HP Prolient Microserver N40L 2Gb Ram, 250Gb OS Disk, 1x2TB HDD ext4, 5.25" to 3.5" disk drive added to ODD Slot for OS disk

Blog: http://ninet.org
Reply
#7
Nah, it does. You'll have to use export in separate files in order to get the .nfo along your video files.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not PM or e-mail Team-Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#8
problem is he does not have writable sources as i already put in the jump-the-gun feature request he posted.
Reply
#9
DOH, missed that one.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not PM or e-mail Team-Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#10
I forgot to add the relevant permissions for my share user. My bad..

I had been testing from a different account..
MC1 (SD & HD): Asus A8N SLI, AMD x2 4600+, 2GB DDR 400 Cosair, Palit Nvidia 9400GT 1GB (Passive), ARTIC 500W PSU, Lian Li PC-C32B, Samsung 250GB SATA
MC2 (SD&HD): RaspberryPi
MC3 (SD&HD): RaspberryPi
NAS1: HP Prolient Microserver N40L 2Gb Ram, 250Gb OS Disk, 1x2TB HDD ext4, 5.25" to 3.5" disk drive added to ODD Slot for OS disk

Blog: http://ninet.org
Reply

Logout Mark Read Team Forum Stats Members Help
NFO Generator from sqlite db0