XBMC Metadata fixes
This commit is contained in:
1 parent
780fb35b45
commit
154a5dc099
10 files changed
+91
-73
No files matched your search
@@ -1,6 +1,8 @@
|
||||
from couchpotato.core.event import addEvent, fireEvent
|
||||
from couchpotato.core.helpers.variable import mergeDicts
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
import json
|
||||
import os.path
|
||||
import shutil
|
||||
import traceback
|
||||
@@ -20,8 +22,21 @@ class MetaDataBase(Plugin):
|
||||
|
||||
log.info('Creating %s metadata.' % self.getName())
|
||||
|
||||
# Update library to get latest info
|
||||
try:
|
||||
updated_library = fireEvent('library.update', release['library']['identifier'], force = True, single = True)
|
||||
release['library'] = mergeDicts(release['library'], updated_library)
|
||||
except:
|
||||
log.error('Failed to update movie, before creating metadata: %s' % traceback.format_exc())
|
||||
|
||||
root = self.getRootName(release)
|
||||
|
||||
try:
|
||||
movie_info = json.loads(release['library'].get('info'))
|
||||
except:
|
||||
log.error('Failed to parse movie info: %s' % traceback.format_exc())
|
||||
movie_info = {}
|
||||
|
||||
for file_type in ['nfo', 'thumbnail', 'fanart']:
|
||||
try:
|
||||
# Get file path
|
||||
@@ -30,7 +45,7 @@ class MetaDataBase(Plugin):
|
||||
if name and self.conf('meta_' + file_type):
|
||||
|
||||
# Get file content
|
||||
content = getattr(self, 'get' + file_type.capitalize())(release)
|
||||
content = getattr(self, 'get' + file_type.capitalize())(movie_info = movie_info, data = release)
|
||||
if content:
|
||||
log.debug('Creating %s file: %s' % (file_type, name))
|
||||
if os.path.isfile(content):
|
||||
@@ -38,7 +53,7 @@ class MetaDataBase(Plugin):
|
||||
else:
|
||||
self.createFile(name, content)
|
||||
|
||||
except Exception, e:
|
||||
except:
|
||||
log.error('Unable to create %s file: %s' % (file_type, traceback.format_exc()))
|
||||
|
||||
def getRootName(self, data):
|
||||
@@ -53,18 +68,18 @@ class MetaDataBase(Plugin):
|
||||
def getNfoName(self, root):
|
||||
return
|
||||
|
||||
def getNfo(self, data):
|
||||
def getNfo(self, movie_info = {}, data = {}):
|
||||
return
|
||||
|
||||
def getThumbnail(self, data, file_type = 'poster_original'):
|
||||
def getThumbnail(self, movie_info = {}, data = {}, wanted_file_type = 'poster_original'):
|
||||
file_types = fireEvent('file.types', single = True)
|
||||
for type in file_types:
|
||||
if type.get('identifier') == file_type:
|
||||
for file_type in file_types:
|
||||
if file_type.get('identifier') == wanted_file_type:
|
||||
break
|
||||
|
||||
for cur_file in data['library'].get('files'):
|
||||
if cur_file.get('type_id') is type.get('id'):
|
||||
for cur_file in data['library'].get('files', []):
|
||||
if cur_file.get('type_id') is file_type.get('id'):
|
||||
return cur_file.get('path')
|
||||
|
||||
def getFanart(self, data):
|
||||
return self.getThumbnail(data, file_type = 'backdrop_original')
|
||||
def getFanart(self, movie_info = {}, data = {}):
|
||||
return self.getThumbnail(movie_info = movie_info, data = data, wanted_file_type = 'backdrop_original')
|
||||
@@ -1,10 +1,14 @@
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.providers.metadata.base import MetaDataBase
|
||||
from xml.etree.ElementTree import Element, SubElement, tostring
|
||||
import os
|
||||
import re
|
||||
import traceback
|
||||
import xml.dom.minidom
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
class XBMC(MetaDataBase):
|
||||
|
||||
def getRootName(self, data = {}):
|
||||
@@ -19,11 +23,9 @@ class XBMC(MetaDataBase):
|
||||
def getNfoName(self, root):
|
||||
return '%s.nfo' % root
|
||||
|
||||
def getNfo(self, data):
|
||||
def getNfo(self, movie_info = {}, data = {}):
|
||||
nfoxml = Element('movie')
|
||||
|
||||
types = ['rating', 'year', 'votes', 'rating', 'mpaa', 'originaltitle:original_title', 'outline:plot', 'premiered:released']
|
||||
|
||||
# Title
|
||||
try:
|
||||
el = SubElement(nfoxml, 'title')
|
||||
@@ -41,11 +43,12 @@ class XBMC(MetaDataBase):
|
||||
# Runtime
|
||||
try:
|
||||
runtime = SubElement(nfoxml, 'runtime')
|
||||
runtime.text = '%s min' % data['library']['runtime']
|
||||
runtime.text = '%s min' % movie_info.get('runtime')
|
||||
except:
|
||||
pass
|
||||
|
||||
# Other values
|
||||
types = ['rating', 'year', 'mpaa', 'originaltitle:original_title', 'outline', 'plot', 'tagline', 'premiered:released']
|
||||
for type in types:
|
||||
|
||||
if ':' in type:
|
||||
@@ -56,14 +59,32 @@ class XBMC(MetaDataBase):
|
||||
try:
|
||||
if data['library'].get(type):
|
||||
el = SubElement(nfoxml, name)
|
||||
el.text = toUnicode(data['library'].get(type, ''))
|
||||
el.text = toUnicode(movie_info.get(type, ''))
|
||||
except:
|
||||
pass
|
||||
|
||||
# Rating
|
||||
for rating_type in ['imdb', 'rotten', 'tmdb']:
|
||||
try:
|
||||
r, v = movie_info['rating'][rating_type]
|
||||
rating = SubElement(nfoxml, 'rating')
|
||||
rating.text = str(r)
|
||||
votes = SubElement(nfoxml, 'votes')
|
||||
votes.text = str(v)
|
||||
break
|
||||
except:
|
||||
log.error('Failed adding rating info from %s: %s' % (rating_type, traceback.format_exc()))
|
||||
|
||||
# Genre
|
||||
for genre in data['library'].get('genres', []):
|
||||
for genre in movie_info.get('genres', []):
|
||||
genres = SubElement(nfoxml, 'genre')
|
||||
genres.text = genre.get('name')
|
||||
genres.text = toUnicode(genre)
|
||||
|
||||
# Actors
|
||||
for actor in movie_info.get('actors', []):
|
||||
actors = SubElement(nfoxml, 'actor')
|
||||
name = SubElement(actors, 'name')
|
||||
name.text = toUnicode(actor)
|
||||
|
||||
|
||||
# Clean up the xml and return it
|
||||
|
||||
Reference in new issue
Block a user