The branch, frodo has been updated
via 36e3c4bd164c671ddbab091c598affa67a9894b6 (commit)
from 729c173b42534f395b9fb02127550bf0c42aedbe (commit)
- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/scripts;a=commit;h=36e3c4bd164c671ddbab091c598affa67a9894b6
commit 36e3c4bd164c671ddbab091c598affa67a9894b6
Author: Martijn Kaijser <[email protected]>
Date: Thu Nov 21 08:34:46 2013 +0100
[script.module.metahandler] 2.3.0
diff --git a/script.module.metahandler/addon.xml
b/script.module.metahandler/addon.xml
index c2d07ac..2d44f56 100644
--- a/script.module.metahandler/addon.xml
+++ b/script.module.metahandler/addon.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.metahandler"
name="metahandler"
- version="2.2.0"
+ version="2.3.0"
provider-name="Eldorado">
<requires>
<import addon="xbmc.python" version="2.1.0" />
diff --git a/script.module.metahandler/changelog.txt
b/script.module.metahandler/changelog.txt
index 4c7fb2a..28a7909 100644
--- a/script.module.metahandler/changelog.txt
+++ b/script.module.metahandler/changelog.txt
@@ -1,3 +1,9 @@
+[B]Version 2.3.0[/B]
+- Fixed changed watched on episodes (again)
+- Added fetch of trailers using v3 of tmdb api
+- Check if a match if found from tmdb before requesting rest of data
+- Added search on similar movies from tmdb
+
[B]Version 2.2.0[/B]
- Reverted back to simplejson import for TMDB scraper
- Updated metacontainers folder deleting functionality
@@ -31,4 +37,4 @@
- Corrected Ratings and Episode values on TV Shows not returning in proper
format in all scenarios
[B]Version 1.0.0[/B]
-- Initial Release.
+- Initial Release.
\ No newline at end of file
diff --git a/script.module.metahandler/lib/metahandler/TMDB.py
b/script.module.metahandler/lib/metahandler/TMDB.py
index c46d9de..7bd7683 100644
--- a/script.module.metahandler/lib/metahandler/TMDB.py
+++ b/script.module.metahandler/lib/metahandler/TMDB.py
@@ -275,24 +275,32 @@ class TMDB(object):
return meta
- # video_id is either tmdb or imdb id
- def _get_version(self, video_id):
- ''' Helper method to start a TMDB getVersion request '''
- return self._do_request('movie/'+str(video_id), '')
-
-
def _get_info(self, tmdb_id, q = False):
''' Helper method to start a TMDB getInfo request '''
r = self._do_request('movie/'+str(tmdb_id), '')
if q: q.put(r)
return r
-
+
+
def _get_cast(self, tmdb_id, q = False):
''' Helper method to start a TMDB getCast request '''
r = self._do_request('movie/'+str(tmdb_id)+'/casts', '')
if q: q.put(r)
return r
-
+
+
+ def _get_trailer(self, tmdb_id, q = False):
+ ''' Helper method to start a TMDB trailer request '''
+ r = self._do_request('movie/'+str(tmdb_id)+'/trailers', '')
+ if q: q.put(r)
+ return r
+
+
+ def _get_similar_movies(self, tmdb_id, page):
+ ''' Helper method to start a TMDB get similar movies request '''
+ r = self._do_request('movie/'+str(tmdb_id)+'/similar_movies',
'page=%s' % page)
+ return r
+
def _search_movie(self, name, year=''):
''' Helper method to start a TMDB Movie.search request - search by
Name/Year '''
@@ -300,7 +308,25 @@ class TMDB(object):
if year:
name = name + '&year=' + year
return self._do_request('search/movie','query='+name)
+
+
+ def tmdb_similar_movies(self, tmdb_id, page=1):
+ '''
+ Query for a list of movies that are similar to the given id
+
+ MUST use a TMDB ID - NOT a IMDB ID
+
+ Returns a tuple of matches containing movie name and imdb id
+ Args:
+ tmdb_id (str): MUST be a valid TMDB ID
+ page (int): Page # of results to return - check # of pages first
before calling subsequent pages
+
+ Returns:
+ DICT of matches
+ '''
+ return self._get_similar_movies(tmdb_id, page)
+
def tmdb_search(self, name):
'''
@@ -342,7 +368,7 @@ class TMDB(object):
##Retry without the year
if meta and meta['total_results'] == 0 and year:
meta = self._search_movie(name,'')
- if meta and meta['total_results'] != 0:
+ if meta and meta['total_results'] != 0 and meta['results']:
tmdb_id = meta['results'][0]['id']
if meta['results'][0].has_key('imdb_id'):
imdb_id = meta['results'][0]['imdb_id']
@@ -359,16 +385,22 @@ class TMDB(object):
tmdb_id = imdb_id
if tmdb_id:
- metaQueue = queue.Queue()
+ #metaQueue = queue.Queue()
castQueue = queue.Queue()
- Thread(target=self._get_info, args=(tmdb_id,metaQueue)).start()
- Thread(target=self._get_cast, args=(tmdb_id,castQueue)).start()
- meta = metaQueue.get()
- cast = castQueue.get()
+ trailerQueue = queue.Queue()
+ #Thread(target=self._get_info, args=(tmdb_id,metaQueue)).start()
+ #meta = metaQueue.get()
+ #Only grab extra info if initial search returns results
+ meta = self._get_info(tmdb_id)
if meta is None: # fall through to IMDB lookup
meta = {}
else:
+ #Grab extra info on threads
+ Thread(target=self._get_cast, args=(tmdb_id,castQueue)).start()
+ Thread(target=self._get_trailer,
args=(tmdb_id,trailerQueue)).start()
+ cast = castQueue.get()
+ trailers = trailerQueue.get()
if meta.has_key('poster_path') and meta['poster_path']:
meta['cover_url'] = self.poster_prefix +
meta['poster_path']
@@ -381,9 +413,21 @@ class TMDB(object):
if cast:
meta['cast'] = cast['cast']
meta['crew'] = cast['crew']
+
+ if trailers:
+ #We only want youtube trailers
+ trailers = trailers['youtube']
+
+ #Only want trailers - no Featurettes etc.
+ found_trailer = next((item for item in trailers if
'Trailer' in item["name"] and item['type'] == 'Trailer'), None)
+ if found_trailer:
+ meta['trailers'] = found_trailer['source']
+ else:
+ meta['trailers'] = ''
+ else:
+ meta['trailers'] = ''
+
#Update any missing information from IDMB
- #if meta['overview'] == 'None' or meta['overview'] == '' or
meta['overview'] == 'TBD' or meta['overview'] == 'No overview found.' or
meta['rating'] == 0 or meta['runtime'] == 0 or meta['runtime'] == None or
str(meta['genres']) == '[]' or str(meta['posters']) == '[]' or meta['released']
== None or meta['certification'] == None:
- #addon.log('Some info missing in TMDB for Movie *** %s ***.
Will search imdb for more' % imdb_id, 0)
if meta.has_key('imdb_id'):
imdb_id = meta['imdb_id']
addon.log('Requesting IMDB for extra information: %s' %
imdb_id, 0)
diff --git a/script.module.metahandler/lib/metahandler/metahandlers.py
b/script.module.metahandler/lib/metahandler/metahandlers.py
index f352fbe..ad5de60 100644
--- a/script.module.metahandler/lib/metahandler/metahandlers.py
+++ b/script.module.metahandler/lib/metahandler/metahandlers.py
@@ -40,6 +40,8 @@ net = Net()
sys.path.append((os.path.split(common.addon_path))[0])
+common.addon.log('Initializing MetaHandlers version: %s' %
common.addon.get_version())
+
'''
Use SQLIte3 wherever possible, needed for newer versions of XBMC
Keep pysqlite2 for legacy support
@@ -153,60 +155,6 @@ class MetaData:
self.dbcur = self.dbcon.cursor()
- # !!!!!!!! TEMPORARY CODE !!!!!!!!!!!!!!!
- if xbmcvfs.exists(self.videocache):
- table_exists = True
- try:
- sql_select = 'select * from tvshow_meta'
- self.dbcur.execute(sql_select)
- matchedrow = self.dbcur.fetchall()[0]
- except:
- table_exists = False
-
- if table_exists:
- sql_select = 'SELECT year FROM tvshow_meta'
- if DB == 'mysql':
- sql_alter = 'RENAME TABLE tvshow_meta TO tmp_tvshow_meta'
- else:
- sql_alter = 'ALTER TABLE tvshow_meta RENAME TO
tmp_tvshow_meta'
- try:
- self.dbcur.execute(sql_select)
- matchedrow = self.dbcur.fetchall()[0]
- except Exception, e:
- print '************* tvshow year column does not exist -
creating temp table'
- print e
- self.dbcur.execute(sql_alter)
- self.dbcon.commit()
-
- ## !!!!!!!!!!!!!!!!!!!!!!!
-
-
- # initialize cache db
- self._cache_create_movie_db()
-
-
- # !!!!!!!! TEMPORARY CODE !!!!!!!!!!!!!!!
-
- if DB == 'mysql':
- sql_insert = "INSERT INTO tvshow_meta (imdb_id, tvdb_id, title,
year, cast, rating, duration, plot, mpaa, premiered, genre, studio, status,
banner_url, cover_url, trailer_url, backdrop_url, imgs_prepacked, overlay)
SELECT imdb_id, tvdb_id, title, cast(substr(premiered, 1,4) as unsigned) as
year, cast, rating, duration, plot, mpaa, premiered, genre, studio, status,
banner_url, cover_url, trailer_url, backdrop_url, imgs_prepacked, overlay FROM
tmp_tvshow_meta"
- else:
- sql_insert = "INSERT INTO tvshow_meta (imdb_id, tvdb_id, title,
year, cast, rating, duration, plot, mpaa, premiered, genre, studio, status,
banner_url, cover_url, trailer_url, backdrop_url, imgs_prepacked, overlay)
SELECT imdb_id, tvdb_id, title, cast(substr(premiered, 1,4) as integer) as
year, [cast], rating, duration, plot, mpaa, premiered, genre, studio, status,
banner_url, cover_url, trailer_url, backdrop_url, imgs_prepacked, overlay FROM
tmp_tvshow_meta"
- sql_select = 'SELECT imdb_id from tmp_tvshow_meta'
- sql_drop = 'DROP TABLE tmp_tvshow_meta'
- try:
- self.dbcur.execute(sql_select)
- matchedrow = self.dbcur.fetchall()[0]
- self.dbcur.execute(sql_insert)
- self.dbcon.commit()
- self.dbcur.execute(sql_drop)
- self.dbcon.commit()
- except Exception, e:
- print '************* tmp_tvshow_meta does not exist: %s' % e
-
- ## !!!!!!!!!!!!!!!!!!!!!!!
-
-
-
def __del__(self):
''' Cleanup db when object destroyed '''
try:
@@ -819,11 +767,23 @@ class MetaData:
#Return a trailer link that will play via youtube addon
try:
- trailer_id = re.match('^[^v]+v=(.{3,11}).*',
meta['trailer_url']).group(1)
- meta['trailer'] =
'plugin://plugin.video.youtube/?action=play_video&videoid=%s' % trailer_id
- except:
meta['trailer'] = ''
-
+ trailer_id = ''
+ if meta['trailer_url']:
+ r = re.match('^[^v]+v=(.{3,11}).*', meta['trailer_url'])
+ if r:
+ trailer_id = r.group(1)
+ else:
+ trailer_id = meta['trailer_url']
+
+ if trailer_id:
+ meta['trailer'] =
'plugin://plugin.video.youtube/?action=play_video&videoid=%s' % trailer_id
+
+ except Exception, e:
+ meta['trailer'] = ''
+ common.addon.log('Failed to set trailer: %s' % e, 3)
+ pass
+
#Ensure we are not sending back any None values, XBMC doesn't like them
meta = self._remove_none_values(meta)
@@ -1167,7 +1127,7 @@ class MetaData:
'''
tmdb = TMDB()
- meta = tmdb.tmdb_lookup(name,imdb_id,tmdb_id, year)
+ meta = tmdb.tmdb_lookup(name,imdb_id,tmdb_id, year)
if meta is None:
# create an empty dict so below will at least populate empty data
for the db insert.
@@ -1213,7 +1173,7 @@ class MetaData:
#meta['year'] = int(self._convert_date(meta['premiered'],
'%Y-%m-%d', '%Y'))
meta['year'] = int(meta['premiered'][:4])
- meta['trailer_url'] = md.get('trailer', '')
+ meta['trailer_url'] = md.get('trailers', '')
meta['genre'] = md.get('genre', '')
#Get cast, director, writers
@@ -1456,7 +1416,37 @@ class MetaData:
common.addon.log('Returning results: %s' % movie_list, 0)
return movie_list
-
+
+ def similar_movies(self, tmdb_id, page=1):
+ '''
+ Requests list of similar movies matching given tmdb id
+
+ Args:
+ tmdb_id (str): MUST be a valid TMDB ID
+ Kwargs:
+ page (int): page number of result to fetch
+ Returns:
+ List of dicts - each movie in it's own dict with supporting info
+ '''
+
common.addon.log('---------------------------------------------------------------------------------------',
2)
+ common.addon.log('TMDB - requesting similar movies: %s' % tmdb_id, 2)
+ tmdb = TMDB()
+ movie_list = []
+ meta = tmdb.tmdb_similar_movies(tmdb_id, page)
+ if meta:
+ if meta['total_results'] == 0:
+ common.addon.log('No results found', 2)
+ return None
+ for movie in meta['results']:
+ movie_list.append(movie)
+ else:
+ common.addon.log('No results found', 2)
+ return None
+
+ common.addon.log('Returning results: %s' % movie_list, 0)
+ return movie_list
+
+
def get_episode_meta(self, tvshowtitle, imdb_id, season, episode,
air_date='', episode_title='', overlay=''):
'''
Requests meta data from TVDB for TV episodes, searches local cache db
first.
@@ -1894,7 +1884,7 @@ class MetaData:
def update_trailer(self, media_type, imdb_id, trailer, tmdb_id=''):
'''
- Change watched status on video
+ Change videos trailer
Args:
media_type (str): media_type of video to update, 'movie', 'tvshow'
or 'episode'
@@ -2020,7 +2010,7 @@ class MetaData:
#If we have an air date use that instead of season/episode #
if air_date:
- sql_update = sql_update + ' AND premiered = %s' % air_date
+ sql_update = sql_update + " AND premiered = '%s'" % air_date
else:
sql_update = sql_update + ' AND season = %s AND episode = %s'
% (season, episode)
@@ -2083,11 +2073,17 @@ class MetaData:
'''
if meta['imdb_id']:
- sql_select = 'SELECT * FROM episode_meta WHERE imdb_id = "%s" AND
season = %s AND episode = %s and premiered = "%s"' % (meta['imdb_id'],
meta['season'], meta['episode'], meta['premiered'])
+ sql_select = "SELECT * FROM episode_meta WHERE imdb_id = '%s'" %
meta['imdb_id']
elif meta['tvdb_id']:
- sql_select = 'SELECT * FROM episode_meta WHERE tvdb_id = "%s" AND
season = %s AND episode = %s and premiered = "%s"' % (meta['tvdb_id'],
meta['season'], meta['episode'], meta['premiered'])
+ sql_select = "SELECT * FROM episode_meta WHERE tvdb_id = '%s'" %
meta['tvdb_id']
else:
- sql_select = 'SELECT * FROM episode_meta WHERE title = "%s" AND
season = %s AND episode = %s and premiered = "%s"' %
(self._clean_string(meta['title'].lower()), meta['season'], meta['episode'],
meta['premiered'])
+ sql_select = "SELECT * FROM episode_meta WHERE title = '%s'" %
self._clean_string(meta['title'].lower())
+
+ if meta['premiered']:
+ sql_select += " AND premiered = '%s'" % meta['premiered']
+ else:
+ sql_select += ' AND season = %s AND episode = %s' %
(meta['season'], meta['episode'])
+
common.addon.log('Getting episode watched status', 0)
common.addon.log('SQL Select: %s' % sql_select, 0)
try:
-----------------------------------------------------------------------
Summary of changes:
script.module.metahandler/addon.xml | 2 +-
script.module.metahandler/changelog.txt | 8 +-
script.module.metahandler/lib/metahandler/TMDB.py | 76 +++++++++---
.../lib/metahandler/metahandlers.py | 128 ++++++++++----------
4 files changed, 130 insertions(+), 84 deletions(-)
hooks/post-receive
--
Scripts
------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing
conversations that shape the rapidly evolving mobile landscape. Sign up now.
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons