2011-04-14, 04:06
[WINDOWS]
I been googling and searching this forum for days to no avail. One of the "shortcomings" of XBMC is it doesn't know which DVD or Blu-Ray is in the drive. So, I'm writing a python script to query imdbapi and parse the json response.
It took me just an hour or so to get all this working in Python on Windows using the IDLE editor. Unfortunately, when I go to run it in XBMC, I get " ImportError: No module named json". I tried simplejson but ... import error.
I just want to take the json response from imdb and parse it "pythonically" without looking for squiggly-brackets, colons, quotes, commas ... yuch!
Here's a simple version of my code which works like a dream in IDLE but can't see json from XBMC. NOTE: for now, I hard-coded my "X:" drive.
I been googling and searching this forum for days to no avail. One of the "shortcomings" of XBMC is it doesn't know which DVD or Blu-Ray is in the drive. So, I'm writing a python script to query imdbapi and parse the json response.
It took me just an hour or so to get all this working in Python on Windows using the IDLE editor. Unfortunately, when I go to run it in XBMC, I get " ImportError: No module named json". I tried simplejson but ... import error.
I just want to take the json response from imdb and parse it "pythonically" without looking for squiggly-brackets, colons, quotes, commas ... yuch!
Here's a simple version of my code which works like a dream in IDLE but can't see json from XBMC. NOTE: for now, I hard-coded my "X:" drive.
Code:
import os
import subprocess
import json
try:
import urllib.request as urllib
except:
import urllib2 as urllib
for vol in os.popen('wmic logicaldisk where drivetype=5 get name,volumename').readlines():
if vol[0:2] == 'X:':
title = vol[6:].replace('_',' ')
if len(title.strip()) == 0:
title = 'no disc'
else:
imdbURL = urllib.quote('http://www.imdbapi.com/?t=%s' % title, safe="%/:=&?~#+!$,;'@()*[]")
results = urllib.urlopen(imdbURL)
imdbJson = json.loads(results.read().decode('utf-8'))
if imdbJson['Response'] == 'True':
title = imdbJson['Year'] + ' - ' + imdbJson['Title']
else:
title = imdbJson['Response']
print(title)