Пример #1
0
    def _update_show(self, trakt_id, show_item, get_meta=True):
        tools.traktSyncDB_lock.acquire()
        cursor = self._get_cursor()
        cursor.execute('SELECT * FROM shows WHERE trakt_id=?', (trakt_id, ))
        old_entry = cursor.fetchone()
        cursor.close()
        tools.try_release_lock(tools.traktSyncDB_lock)

        if get_meta:
            try:
                kodi_meta = tvdb.TVDBAPI().seriesIDToListItem(show_item)
                if kodi_meta is None or kodi_meta == '{}':
                    kodi_meta = tmdb.TMDBAPI().showToListItem(show_item)
                if kodi_meta is None or kodi_meta == '{}':
                    kodi_meta = imdb.IMDBScraper().showToListItem(show_item)
                if kodi_meta is None or kodi_meta == '{}':
                    return
                update_time = str(
                    datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S'))
            except:
                return None
        else:
            if old_entry is None:
                kodi_meta = {}
                update_time = self.base_date
            else:
                update_time = old_entry['last_updated']
                kodi_meta = old_entry['kodi_meta']
        tools.traktSyncDB_lock.acquire()
        cursor = self._get_cursor()
        try:
            cursor.execute('PRAGMA foreign_keys=OFF')
            cursor.execute(
                "REPLACE INTO shows ("
                "trakt_id, kodi_meta, last_updated, air_date)"
                "VALUES "
                "(?, ?, ?, ?)", (int(trakt_id), str(kodi_meta), update_time,
                                 kodi_meta['info']['premiered']))
            cursor.execute('PRAGMA foreign_keys=ON')
            cursor.connection.commit()
            cursor.close()

            return {
                'trakt_id': trakt_id,
                'kodi_meta': kodi_meta,
                'last_updated': update_time
            }
        except:
            cursor.close()

            import traceback
            traceback.print_exc()
            pass
        finally:
            tools.try_release_lock(tools.traktSyncDB_lock)
Пример #2
0
    def _update_movie(self, trakt_object, get_meta=True):

        movie_id = trakt_object['ids']['trakt']
        update_time = str(datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S'))
        cursor = self._get_cursor()
        cursor.execute('SELECT * FROM movies WHERE trakt_id=?',
                       (int(movie_id), ))
        old_entry = cursor.fetchone()
        cursor.close()

        if get_meta and (old_entry is None or old_entry['kodi_meta'] == '{}'):
            kodi_meta = tmdb.TMDBAPI().movieToListItem(trakt_object)
        else:
            if old_entry is None:
                kodi_meta = {}
            else:
                kodi_meta = old_entry['kodi_meta']

        if kodi_meta is None:
            return

        if old_entry is None:
            old_entry = {'collected': 0, 'watched': 0}

        collected = old_entry['collected']
        watched = old_entry['watched']

        cursor = self._get_cursor()

        try:
            cursor.execute(
                "INSERT OR REPLACE INTO movies ("
                "trakt_id, kodi_meta, collected, watched, last_updated)"
                "VALUES "
                "(?, ?, ?, ?, ?)",
                (movie_id, str(kodi_meta), collected, watched, update_time))
            cursor.connection.commit()
            cursor.close()

            return {
                'trakt_id': movie_id,
                'kodi_meta': kodi_meta,
                'update_time': update_time,
                'watched': watched,
                'collected': collected
            }
        except:
            cursor.close()
            import traceback
            traceback.print_exc()
            pass
Пример #3
0
    def _update_season(self, show_meta, season_meta, get_meta=True):

        if get_meta:
            try:
                kodi_meta = tvdb.TVDBAPI().seasonIDToListItem(
                    season_meta, show_meta)
                if kodi_meta is None or kodi_meta == '{}':
                    kodi_meta = tmdb.TMDBAPI().showSeasonToListItem(
                        season_meta, show_meta)
                if kodi_meta is None or kodi_meta == '{}':
                    kodi_meta = imdb.IMDBScraper().showSeasonToListItem(
                        season_meta, show_meta)
            except:
                return None
        else:
            kodi_meta = {}

        season = season_meta['number']
        show_id = show_meta['ids']['trakt']
        tools.traktSyncDB_lock.acquire()
        cursor = self._get_cursor()

        try:
            cursor.execute(
                "REPLACE INTO seasons ("
                "show_id, season, kodi_meta, air_date)"
                "VALUES "
                "(?, ?, ?, ?)", (int(show_id), str(season), str(kodi_meta),
                                 kodi_meta['info']['aired']))
            cursor.connection.commit()
            cursor.close()
            return {
                'show_id': show_meta['ids']['trakt'],
                'season': season,
                'kodi_meta': kodi_meta
            }

        except:
            cursor.close()
            import traceback
            traceback.print_exc()
            pass
        finally:
            tools.try_release_lock(tools.traktSyncDB_lock)
Пример #4
0
    def _update_episode(self, show_id, episode_object, get_meta=True, watched=None, collected=None):
        episode_id = episode_object['ids']['trakt']
        season = episode_object['season']
        old_entry = None
        number = episode_object['number']

        show_meta = self.get_single_show(show_id, get_meta=get_meta)
        if show_meta is None:
            return

        season_meta = self.get_single_season(show_id, season, get_meta=get_meta)
        if season_meta is None:
            return

        try:
            tools.traktSyncDB_lock.acquire()
            cursor = self._get_cursor()
            cursor.execute("SELECT * FROM episodes WHERE trakt_id=?", (episode_id,))
            old_entry = cursor.fetchone()
            cursor.close()
            tools.try_release_lock(tools.traktSyncDB_lock)
        except:
            pass

        if show_meta == '{}' and get_meta:
            return

        show_meta = {'showInfo': show_meta, 'seasonInfo': season_meta}

        if (get_meta and old_entry is None) or (get_meta and old_entry['kodi_meta'] == '{}'):
            try:
                kodi_meta = tmdb.TMDBAPI().episodeIDToListItem(episode_object, copy.deepcopy(show_meta))
                if kodi_meta is None or kodi_meta == '{}':
                    kodi_meta = tvdb.TVDBAPI().episodeIDToListItem(episode_object, copy.deepcopy(show_meta))
                if kodi_meta is None or kodi_meta == '{}':
                    kodi_meta = imdb.IMDBScraper().episodeIDToListItem(episode_object, copy.deepcopy(show_meta))
                if kodi_meta is None or kodi_meta == '{}':
                    return
            except:
                return None
            kodi_meta.pop('showInfo')
            update_time = str(datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S'))
        else:
            if old_entry is None:
                update_time = self.base_date
                kodi_meta = {}
            else:
                update_time = old_entry['last_updated']
                kodi_meta = old_entry['kodi_meta']

        if old_entry is None:
            old_entry = {'collected': 0, 'watched': 0, 'air_date': ''}

        if collected is None:
            collected = old_entry['collected']

        if watched is None:
            watched = old_entry['watched']
        tools.traktSyncDB_lock.acquire()
        cursor = self._get_cursor()

        try:
            cursor.execute(
                "REPLACE INTO episodes ("
                "show_id, season, trakt_id, kodi_meta, last_updated, watched, collected, number, air_date)"
                "VALUES "
                "(?, ?, ?, ?, ?, ?, ?, ?, ?)",
                (show_id, season, episode_id, str(kodi_meta), update_time, watched, collected, number,
                 kodi_meta['info']['premiered']))

            cursor.connection.commit()
            cursor.close()

            return {'show_id': show_id, 'season': season, 'episode_id': episode_id, 'kodi_meta': kodi_meta,
                    'update_time': update_time, 'watched': watched, 'collected': collected, 'number': number}
        except:
            cursor.close()

            import traceback
            traceback.print_exc()
            pass
        finally:
            tools.try_release_lock(tools.traktSyncDB_lock)
Пример #5
0
    def _update_movie(self, trakt_object, get_meta=True):
        movie_id = trakt_object['ids']['trakt']
        update_time = str(datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S'))
        tools.traktSyncDB_lock.acquire()
        cursor = self._get_cursor()
        cursor.execute('SELECT * FROM movies WHERE trakt_id=?',
                       (int(movie_id), ))
        old_entry = cursor.fetchone()
        cursor.close()
        tools.try_release_lock(tools.traktSyncDB_lock)

        if get_meta and (old_entry is None or old_entry['kodi_meta'] == '{}'):
            try:
                kodi_meta = tmdb.TMDBAPI().movieToListItem(trakt_object)
                if kodi_meta is None or kodi_meta == '{}':
                    kodi_meta = imdb.IMDBScraper().movieToListItem(
                        trakt_object)
            except:
                return None
        else:
            if old_entry is None:
                kodi_meta = {}
            else:
                kodi_meta = old_entry['kodi_meta']

        if kodi_meta is None:
            return

        if old_entry is None:
            air_date = kodi_meta['info'].get('aired',
                                             kodi_meta['info']['premiered'])
            old_entry = {'collected': 0, 'watched': 0, 'air_date': air_date}

        collected = old_entry['collected']
        watched = old_entry['watched']
        air_date = old_entry['air_date']

        tools.traktSyncDB_lock.acquire()
        cursor = self._get_cursor()

        try:
            cursor.execute(
                "REPLACE INTO movies ("
                "trakt_id, kodi_meta, collected, watched, last_updated, air_date)"
                "VALUES "
                "(?, ?, ?, ?, ?, ?)", (movie_id, str(kodi_meta), collected,
                                       watched, update_time, air_date))
            cursor.connection.commit()
            cursor.close()

            return {
                'trakt_id': movie_id,
                'kodi_meta': kodi_meta,
                'update_time': update_time,
                'watched': watched,
                'collected': collected
            }
        except:
            cursor.close()
            import traceback
            traceback.print_exc()
            pass
        finally:
            tools.try_release_lock(tools.traktSyncDB_lock)
Пример #6
0
    def episodeIDToListItem(self, trakt_object, showArgs):
        url = "episodes/%s" % trakt_object['ids']['tvdb']
        response = self.get_request(url)['data']

        item = {'info': None, 'art': None}

        art = copy.deepcopy(showArgs['seasonInfo']['art'])

        info = {}
        try:
            info['episode'] = info['sortepisode'] = int(
                response['airedEpisodeNumber'])
        except:
            pass
        try:
            info['absoluteNumber'] = int(response['absoluteNumber'])
        except:
            pass
        try:
            info['season'] = info['sortseason'] = int(response['airedSeason'])
        except:
            pass
        try:
            info['title'] = info['originaltitle'] = response.get('episodeName')
            if info['title'] is None:
                return None
        except:
            pass
        try:
            info['rating'] = float(response['siteRating'])
        except:
            pass

        try:
            info['premiered'] = trakt_object['first_aired']
            info['aired'] = trakt_object['first_aired']
        except:
            info['premiered'] = ''
            info['aired'] = ''

        try:
            info['year'] = trakt_object['first_aired'][:4]
        except:
            pass
        try:
            info['plot'] = response['overview']
        except:
            pass
        try:
            info['imdbnumber'] = response['imdbId']
        except:
            pass
        try:
            info['studio'] = showArgs['showInfo']['info'].get('studio')
        except:
            pass
        try:
            info['mpaa'] = showArgs['showInfo']['info']['mpaa']
        except:
            pass

        try:
            if self.episode_fanart == 'true':
                art.update(tmdb.TMDBAPI().getEpisodeFanartArt(
                    trakt_object, showArgs))
        except:
            pass
        try:
            art['thumb'] = self.baseImageUrl + response['filename']
            if art['thumb'] == self.baseImageUrl:
                art['thumb'] = art['fanart']
        except:
            pass
        try:
            info['tvshowtitle'] = showArgs['showInfo']['info']['tvshowtitle']
        except:
            pass
        try:
            info['genre'] = showArgs['showInfo']['info']['genre']
        except:
            pass
        try:
            info['duration'] = showArgs['showInfo']['info']['duration']
        except:
            pass

        info['trailer'] = ''
        info['mediatype'] = 'episode'
        item['ids'] = trakt_object['ids']
        for id, value in showArgs['showInfo']['ids'].items():
            item['ids']['tvshow.{}'.format(id)] = value
        item['info'] = info
        item['art'] = art
        item['cast'] = showArgs['showInfo']['cast']
        item['trakt_object'] = {}
        item['trakt_object']['episodes'] = [trakt_object]
        item['showInfo'] = showArgs['showInfo']

        requirements = ['title', 'season', 'episode']
        for i in requirements:
            if info.get(i, None) == None:
                return None
            if i not in info:
                return None
        return item