def movietitle_to_id(self, title):
query = {
"jsonrpc": "2.0",
"method": "VideoLibrary.GetMovies",
"params": {
"properties": ["title"]
},
"id": "libMovies"
}
try:
rpc_result = xbmc.executeJSONRPC(
jsonrpccommand=json.dumps(query, encoding='utf-8'))
json_result = json.loads(rpc_result)
if 'result' in json_result and 'movies' in json_result['result']:
json_result = json_result['result']['movies']
for movie in json_result:
# Switch to ascii/lowercase and remove special chars and spaces
# to make sure best possible compare is possible
titledb = movie['title'].encode('ascii', 'ignore')
titledb = re.sub(r'[?|$|!|:|#|\.|\,|\'| ]', r'', titledb).lower().replace('-', '')
if '(' in titledb:
titledb = titledb.split('(')[0]
titlegiven = title.encode('ascii','ignore')
titlegiven = re.sub(r'[?|$|!|:|#|\.|\,|\'| ]', r'', titlegiven).lower().replace('-', '')
if '(' in titlegiven:
titlegiven = titlegiven.split('(')[0]
if titledb == titlegiven:
return movie['movieid']
return '-1'
except Exception:
return '-1'
评论列表
文章目录