2013-06-03, 07:38
I would like to produce a simple printout of every video file in my database and the title, preferably to a pdf. Must run on linux.
./texturecache.py j movies | grep '"title":' | cut -d: -f2- | awk '{print substr($0,3,length($0)-5)}'
./texturecache.py j tvshows | grep '"title":' | cut -d: -f2- | awk '{print substr($0,3,length($0)-5)}'
./texturecache.py j songs | grep '"title":' | cut -d: -f2- | awk '{print substr($0,3,length($0)-5)}'
./texturecache.py query movies 'title != ""' | sed 's/^.* \[\(.*\)] .*$/\1/'
# --------------------
# tvshows.py
# toodlydo
# printout all tv show folder and files up to 3 directories down
# --------------------
import json
import urllib2, base64
import os
from pprint import pprint
f = open('tvshows.txt','w')
rooturl = "http://192.168.0.101:81/jsonrpc"
username = "xbmc"
password = "xbmc"
url1= rooturl + "?request="
url=url1+'{"jsonrpc":"2.0","method":"VideoLibrary.GetTVShows","id":1,"params":{"properties":["title","file","episode"]}}'
#print url;
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, rooturl, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
data = json.load(opener.open(url))
tvshows = data["result"]["tvshows"]
for tvshow in tvshows:
#print tvshow['label'] + " (" + str(tvshow['episode']) + ")" + " - " + tvshow['file']
f.write((tvshow['label'] + " (" + str(tvshow['episode']) + ")" + " - " + tvshow['file']+ os.linesep).encode("utf-8"))
jdata = json.dumps({"jsonrpc":"2.0","method":"Files.GetDirectory","id":2,"params":{"directory":tvshow['file'],"properties":["file"]}})
req = urllib2.Request(rooturl, jdata, {'Content-Type': 'application/json'})
data = json.load(opener.open(req))
folders = data["result"]["files"]
for folder in folders:
#print "\t" + folder["file"].replace(tvshow['file'], "")
f.write(("\t" + folder["file"].replace(tvshow['file'], "") + os.linesep).encode("utf-8"))
jdata = json.dumps({"jsonrpc":"2.0","method":"Files.GetDirectory","id":2,"params":{"directory":folder['file'],"properties":["file"]}})
req = urllib2.Request(rooturl, jdata, {'Content-Type': 'application/json'})
data = json.load(opener.open(req))
if folder["filetype"] == "directory":
files = data["result"]["files"]
for efile in files:
#print "\t\t" + efile["file"].replace(folder['file'], "")
f.write(("\t\t" + efile["file"].replace(folder['file'], "") + os.linesep).encode("utf-8"))
jdata = json.dumps({"jsonrpc":"2.0","method":"Files.GetDirectory","id":2,"params":{"directory":efile['file'],"properties":["file"]}})
req = urllib2.Request(rooturl, jdata, {'Content-Type': 'application/json'})
data = json.load(opener.open(req))
if efile["filetype"] == "directory":
eefiles = data["result"]["files"]
for eefile in eefiles:
#print "\t\t\t" + eefile["file"].replace(efile['file'], "")
f.write(("\t\t\t" + eefile["file"].replace(efile['file'], "") + os.linesep).encode("utf-8"))
f.close()