2009-05-28, 02:55
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.
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"