From b8bd8cbd61951d3604ac3578b4a249bd9e30ae13 Mon Sep 17 00:00:00 2001 From: Andrea Panizza Date: Mon, 22 Mar 2021 16:01:46 +0100 Subject: [PATCH 1/5] Refactoring --- default.py | 409 +++++++++++++++++++++++++++++------------------------ 1 file changed, 226 insertions(+), 183 deletions(-) diff --git a/default.py b/default.py index 7e9d1ee..76b325a 100644 --- a/default.py +++ b/default.py @@ -73,193 +73,236 @@ def onNotification(self, sender, method, data): log('onNotification') log('method=%s' % method) if (method == 'Player.OnPlay'): - self._setUp() - self._total_time = player.getTotalTime() - self._tracker.start() - log('Player.OnPlay') - if player.http == 'true' and player.getPlayingFile()[:4] == 'http' and re.search(r'[sS][0-9]*[eE][0-9]*', os.path.basename(player.getPlayingFile()), flags=0) : - player.http_playing = True - player.filename = os.path.basename(player.getPlayingFile()) - self.startcut = player.filename.find("%5B") - self.endcut = player.filename.find("%5D") - self.tocut = player.filename[self.startcut:self.endcut] - player.filename = player.filename.replace(self.tocut, "") - player.filename = player.filename.replace("%5B", "") - player.filename = player.filename.replace("%5D", "") - player.filename = player.filename.replace("%20", ".") + self._player_onplay(data) + if (method == 'Player.OnStop'): + self._player_onstop(data) + if (method == 'VideoLibrary.OnUpdate'): + self._video_onupdate(data) + + def _player_onplay(self, data): + self._setUp() + self._total_time = player.getTotalTime() + self._tracker.start() + log('Player.OnPlay') + if player.http == 'true' and player.getPlayingFile()[:4] == 'http' and re.search(r'[sS][0-9]*[eE][0-9]*', os.path.basename(player.getPlayingFile()), flags=0) : + player.http_playing = True + player.filename = os.path.basename(player.getPlayingFile()) + startcut = player.filename.find("%5B") + endcut = player.filename.find("%5D") + tocut = player.filename[startcut:endcut] + player.filename = player.filename.replace(tocut, "") + player.filename = player.filename.replace("%5B", "") + player.filename = player.filename.replace("%5D", "") + player.filename = player.filename.replace("%20", ".") + log('tvshowtitle=%s' % player.filename) + + player.episode = FindEpisode(player.token, 0, player.filename) + log('episode.is_found=%s' % player.episode.is_found) + + if player.notifications != 'true': + return + if player.notif_during_playback == 'false' and player.isPlaying() == 1: + return + + if player.episode.is_found: + if player.notif_scrobbling == 'false': + return + notif('%s %s %sx%s' % (__language__(32904), player.episode.showname, player.episode.season_number, player.episode.number), time=2500) + else: + notif(__language__(32905), time=2500) + else: + player.http_playing = False + response = json.loads(data) + log('%s' % response) + if response.get('item').get('type') != 'episode': + return + + xbmc_id = response.get('item').get('id') + item = self.getEpisodeTVDB(xbmc_id) + log('showtitle=%s' % item['showtitle']) + log('season=%s' % item['season']) + log('episode=%s' % item['episode']) + log('episode_id=%s' % item['episode_id']) + if len(item['showtitle']) > 0 and item['season'] > 0 and item['episode'] > 0 and len(str(item['episode_id'])) > 0: + player.filename = '%s.S%.2dE%.2d' % (formatName(item['showtitle']), float(item['season']), float(item['episode'])) log('tvshowtitle=%s' % player.filename) - player.episode = FindEpisode(player.token, 0, player.filename) + + player.episode = FindEpisode(player.token, item['episode_id'], player.filename) log('episode.is_found=%s' % player.episode.is_found) + + if player.notifications != 'true': + return + if player.notif_during_playback == 'false' and player.isPlaying() == 1: + return + if player.episode.is_found: - if player.notifications == 'true': - if player.notif_during_playback == 'false' and player.isPlaying() == 1: - return - if player.notif_scrobbling == 'false': - return - notif('%s %s %sx%s' % (__language__(32904), player.episode.showname, player.episode.season_number, player.episode.number), time=2500) + notif('%s %s %sx%s' % (__language__(32904), player.episode.showname, player.episode.season_number, player.episode.number), time=2500) else: - if player.notifications == 'true': - if player.notif_during_playback == 'false' and player.isPlaying() == 1: - return - notif(__language__(32905), time=2500) - else: - player.http_playing = False - response = json.loads(data) - log('%s' % response) - if response.get('item').get('type') == 'episode': - xbmc_id = response.get('item').get('id') - item = self.getEpisodeTVDB(xbmc_id) - log('showtitle=%s' % item['showtitle']) - log('season=%s' % item['season']) - log('episode=%s' % item['episode']) - log('episode_id=%s' % item['episode_id']) - if len(item['showtitle']) > 0 and item['season'] > 0 and item['episode'] > 0 and len(str(item['episode_id'])) > 0: - player.filename = '%s.S%.2dE%.2d' % (formatName(item['showtitle']), float(item['season']), float(item['episode'])) - log('tvshowtitle=%s' % player.filename) - player.episode = FindEpisode(player.token, item['episode_id'], player.filename) - log('episode.is_found=%s' % player.episode.is_found) - if player.episode.is_found: - if player.notifications == 'true': - if player.notif_during_playback == 'false' and player.isPlaying() == 1: - return - if player.notif_scrobbling == 'false': - return - notif('%s %s %sx%s' % (__language__(32904), player.episode.showname, player.episode.season_number, player.episode.number), time=2500) - else: - if player.notifications == 'true': - if player.notif_during_playback == 'false' and player.isPlaying() == 1: - return - notif(__language__(32905), time=2500) - else: - if player.notifications == 'true': - if player.notif_during_playback == 'false' and player.isPlaying() == 1: - return - notif(__language__(32905), time=2500) - if (method == 'Player.OnStop'): - self._tearDown() - actual_percent = (self._last_pos/self._total_time)*100 - log('last_pos / total_time : %s / %s = %s %%' % (self._last_pos, self._total_time, actual_percent)) - log('Player.OnStop') - if player.http == 'true' and player.http_playing == True : - if player.progress == 'true': - player.episode = FindEpisode(player.token, 0, player.filename) - log('episode.is_found=%s' % player.episode.is_found) - if player.episode.is_found: - log('progress=%s' % self._last_pos) - self.progress = SaveProgress(player.token, player.episode.id, self._last_pos) - log('progress.is_set:=%s' % self.progress.is_set) - if actual_percent > 90: - log('MarkAsWatched(*, %s, %s, %s)' % (player.filename, player.facebook, player.twitter)) - checkin = MarkAsWatched(player.token, player.episode.id, player.facebook, player.twitter) - log('checkin.is_marked:=%s' % checkin.is_marked) - if checkin.is_marked: - if player.emotion == 'true': - self.emotion = xbmcgui.Dialog().select('%s: %s %sx%s' % (__language__(33909), player.episode.showname, player.episode.season_number, player.episode.number), [__language__(35311), __language__(35312), __language__(35313), __language__(35314), __language__(35316), __language__(35317)]) - if self.emotion < 0: return - if self.emotion == 0: - self.emotion = 1 - elif self.emotion == 1: - self.emotion = 2 - elif self.emotion == 2: - self.emotion = 3 - elif self.emotion == 3: - self.emotion = 4 - elif self.emotion == 4: - self.emotion = 6 - elif self.emotion == 5: - self.emotion = 7 - SetEmotion(player.token, player.episode.id, self.emotion) - if player.notifications == 'true': - if player.notif_during_playback == 'false' and player.isPlaying() == 1: - return - if player.notif_scrobbling == 'false': - return - notif('%s %s %sx%s' % (__language__(32906), player.episode.showname, player.episode.season_number, player.episode.number), time=2500) + notif(__language__(32905), time=2500) else: - response = json.loads(data) - log('%s' % response) - if player.progress == 'true': - if response.get('item').get('type') == 'episode': - xbmc_id = response.get('item').get('id') - item = self.getEpisodeTVDB(xbmc_id) - log('showtitle=%s' % item['showtitle']) - log('season=%s' % item['season']) - log('episode=%s' % item['episode']) - log('episode_id=%s' % item['episode_id']) - if len(item['showtitle']) > 0 and item['season'] > 0 and item['episode'] > 0 and len(str(item['episode_id'])) > 0: - player.filename = '%s.S%.2dE%.2d' % (formatName(item['showtitle']), float(item['season']), float(item['episode'])) - log('tvshowtitle=%s' % player.filename) - log('progress=%s' % self._last_pos) - self.progress = SaveProgress(player.token, item['episode_id'], self._last_pos) - log('progress.is_set:=%s' % self.progress.is_set) - if (method == 'VideoLibrary.OnUpdate'): - log('VideoLibrary.OnUpdate') + if player.notifications != 'true': + return + if player.notif_during_playback == 'false' and player.isPlaying() == 1: + return + + notif(__language__(32905), time=2500) + + + def _player_onstop(self, data): + self._tearDown() + actual_percent = (self._last_pos/self._total_time)*100 + log('last_pos / total_time : %s / %s = %s %%' % (self._last_pos, self._total_time, actual_percent)) + log('Player.OnStop') + if player.http == 'true' and player.http_playing == True: + if player.progress != 'true': + return + + player.episode = FindEpisode(player.token, 0, player.filename) + log('episode.is_found=%s' % player.episode.is_found) + + if not player.episode.is_found: + return + + log('progress=%s' % self._last_pos) + progress = SaveProgress(player.token, player.episode.id, self._last_pos) + log('progress.is_set:=%s' % progress.is_set) + + if actual_percent <= 90: + return + + log('MarkAsWatched(*, %s, %s, %s)' % (player.filename, player.facebook, player.twitter)) + checkin = MarkAsWatched(player.token, player.episode.id, player.facebook, player.twitter) + log('checkin.is_marked:=%s' % checkin.is_marked) + if not checkin.is_marked: + return + + if player.emotion == 'true': + msg = '%s: %s %sx%s' % (__language__(33909), player.episode.showname, player.episode.season_number, player.episode.number) + emotion = xbmcgui.Dialog().select(msg, [__language__(35311), __language__(35312), __language__(35313), __language__(35314), __language__(35316), __language__(35317)]) + if emotion < 0: return + if emotion == 0: + emotion = 1 + elif emotion == 1: + emotion = 2 + elif emotion == 2: + emotion = 3 + elif emotion == 3: + emotion = 4 + elif emotion == 4: + emotion = 6 + elif emotion == 5: + emotion = 7 + SetEmotion(player.token, player.episode.id, emotion) + + if player.notifications != 'true': + return + if player.notif_during_playback == 'false' and player.isPlaying() == 1: + return + notif('%s %s %sx%s' % (__language__(32906), player.episode.showname, player.episode.season_number, player.episode.number), time=2500) + else: response = json.loads(data) log('%s' % response) - if response.get('item').get('type') == 'episode': - xbmc_id = response.get('item').get('id') - playcount = response.get('playcount') - log('playcount=%s' % playcount) - item = self.getEpisodeTVDB(xbmc_id) - log('showtitle=%s' % item['showtitle']) - log('season=%s' % item['season']) - log('episode=%s' % item['episode']) - log('episode_id=%s' % item['episode_id']) - log('playcount=%s' % playcount) - if len(item['showtitle']) > 0 and item['season'] > 0 and item['episode'] > 0 and len(str(item['episode_id'])) > 0: - self.filename = '%s.S%.2dE%.2d' % (formatName(item['showtitle']), float(item['season']), float(item['episode'])) - log('tvshowtitle=%s' % self.filename) - self.episode = FindEpisode(player.token, item['episode_id'], self.filename) - log('episode.is_found=%s' % self.episode.is_found) - if self.episode.is_found: - if playcount == 1: - log('MarkAsWatched(*, %s, %s, %s)' % (self.filename, player.facebook, player.twitter)) - checkin = MarkAsWatched(player.token, self.episode.id, player.facebook, player.twitter) - log('checkin.is_marked:=%s' % checkin.is_marked) - if checkin.is_marked: - if player.emotion == 'true': - self.emotion = xbmcgui.Dialog().select('%s: %s' % (__language__(33909), self.filename), [__language__(35311), __language__(35312), __language__(35313), __language__(35314), __language__(35316), __language__(35317)]) - if self.emotion < 0: return - if self.emotion == 0: - self.emotion = 1 - elif self.emotion == 1: - self.emotion = 2 - elif self.emotion == 2: - self.emotion = 3 - elif self.emotion == 3: - self.emotion = 4 - elif self.emotion == 4: - self.emotion = 6 - elif self.emotion == 5: - self.emotion = 7 - SetEmotion(player.token, self.episode.id, self.emotion) - if player.notifications == 'true': - if player.notif_during_playback == 'false' and player.isPlaying() == 1: - return - if player.notif_scrobbling == 'false': - return - notif('%s %s %sx%s' % (__language__(32906), self.episode.showname, self.episode.season_number, self.episode.number), time=2500) - else: - if player.notifications == 'true': - if player.notif_during_playback == 'false' and player.isPlaying() == 1: - return - notif(__language__(32907), time=2500) - if playcount == 0: - log('MarkAsUnWatched(*, %s)' % (self.filename)) - checkin = MarkAsUnWatched(player.token, self.episode.id) - log('checkin.is_unmarked:=%s' % checkin.is_unmarked) - if checkin.is_unmarked: - if player.notifications == 'true': - if player.notif_during_playback == 'false' and player.isPlaying() == 1: - return - if player.notif_scrobbling == 'false': - return - notif('%s %s %sx%s' % (__language__(32908), self.episode.showname, self.episode.season_number, self.episode.number), time=2500) - else: - if player.notifications == 'true': - if player.notif_during_playback == 'false' and player.isPlaying() == 1: - return - notif(__language__(32907), time=2500) + + if player.progress != 'true': + return + + if response.get('item').get('type') != 'episode': + return + + xbmc_id = response.get('item').get('id') + item = self.getEpisodeTVDB(xbmc_id) + log('showtitle=%s' % item['showtitle']) + log('season=%s' % item['season']) + log('episode=%s' % item['episode']) + log('episode_id=%s' % item['episode_id']) + + if len(item['showtitle']) > 0 and item['season'] > 0 and item['episode'] > 0 and len(str(item['episode_id'])) > 0: + player.filename = '%s.S%.2dE%.2d' % (formatName(item['showtitle']), float(item['season']), float(item['episode'])) + log('tvshowtitle=%s' % player.filename) + + log('progress=%s' % self._last_pos) + progress = SaveProgress(player.token, item['episode_id'], self._last_pos) + log('progress.is_set:=%s' % progress.is_set) + + def _video_onupdate(self, data): + log('VideoLibrary.OnUpdate') + response = json.loads(data) + log('%s' % response) + if response.get('item').get('type') != 'episode': + return + xbmc_id = response.get('item').get('id') + playcount = response.get('playcount') + log('playcount=%s' % playcount) + + item = self.getEpisodeTVDB(xbmc_id) + log('showtitle=%s' % item['showtitle']) + log('season=%s' % item['season']) + log('episode=%s' % item['episode']) + log('episode_id=%s' % item['episode_id']) + log('playcount=%s' % playcount) + + if len(item['showtitle']) > 0 and item['season'] > 0 and item['episode'] > 0 and len(str(item['episode_id'])) > 0: + return + + self.filename = '%s.S%.2dE%.2d' % (formatName(item['showtitle']), float(item['season']), float(item['episode'])) + log('tvshowtitle=%s' % self.filename) + self.episode = FindEpisode(player.token, item['episode_id'], self.filename) + log('episode.is_found=%s' % self.episode.is_found) + + if not self.episode.is_found: + return + + if playcount == 1: + log('MarkAsWatched(*, %s, %s, %s)' % (self.filename, player.facebook, player.twitter)) + checkin = MarkAsWatched(player.token, self.episode.id, player.facebook, player.twitter) + log('checkin.is_marked:=%s' % checkin.is_marked) + if checkin.is_marked: + if player.emotion == 'true': + emotion = xbmcgui.Dialog().select('%s: %s' % (__language__(33909), self.filename), [__language__(35311), __language__(35312), __language__(35313), __language__(35314), __language__(35316), __language__(35317)]) + if emotion < 0: return + if emotion == 0: + emotion = 1 + elif emotion == 1: + emotion = 2 + elif emotion == 2: + emotion = 3 + elif emotion == 3: + emotion = 4 + elif emotion == 4: + emotion = 6 + elif emotion == 5: + emotion = 7 + SetEmotion(player.token, self.episode.id, emotion) + + if player.notifications != 'true': + return + if player.notif_during_playback == 'false' and player.isPlaying() == 1: + return + if player.notif_scrobbling == 'false': + return + notif('%s %s %sx%s' % (__language__(32906), self.episode.showname, self.episode.season_number, self.episode.number), time=2500) + else: + if player.notifications != 'true': + return + if player.notif_during_playback == 'false' and player.isPlaying() == 1: + return + notif(__language__(32907), time=2500) + elif playcount == 0: + log('MarkAsUnWatched(*, %s)' % (self.filename)) + checkin = MarkAsUnWatched(player.token, self.episode.id) + log('checkin.is_unmarked:=%s' % checkin.is_unmarked) + + if player.notifications != 'true': + return + if player.notif_during_playback == 'false' and player.isPlaying() == 1: + return + + if checkin.is_unmarked: + if player.notif_scrobbling == 'false': + return + notif('%s %s %sx%s' % (__language__(32908), self.episode.showname, self.episode.season_number, self.episode.number), time=2500) + else: + notif(__language__(32907), time=2500) def getEpisodeTVDB(self, xbmc_id): rpccmd = {'jsonrpc': '2.0', 'method': 'VideoLibrary.GetEpisodeDetails', 'params': {"episodeid": int(xbmc_id), 'properties': ['season', 'episode', 'tvshowid', 'showtitle', 'uniqueid']}, 'id': 1} @@ -267,6 +310,7 @@ def getEpisodeTVDB(self, xbmc_id): result = xbmc.executeJSONRPC(rpccmd) result = json.loads(result) log('result=%s' % result) + if 'unknown' in result['result']['episodedetails']['uniqueid']: episode_id = result['result']['episodedetails']['uniqueid']['unknown'] elif 'tvdb' in result['result']['episodedetails']['uniqueid']: @@ -274,7 +318,7 @@ def getEpisodeTVDB(self, xbmc_id): elif 'tmdb' in result['result']['episodedetails']['uniqueid']: episode_id = result['result']['episodedetails']['uniqueid']['tmdb'] else: - return False + return {} log('episode_id=%s' % episode_id) try: @@ -286,7 +330,7 @@ def getEpisodeTVDB(self, xbmc_id): item['episode_id'] = episode_id return item except: - return False + return {} def getAllEpisodes(self, xbmc_id): rpccmd = {'jsonrpc': '2.0', 'method': 'VideoLibrary.GetEpisodes', 'params': {"tvshowid": int(xbmc_id), 'properties': ['season', 'episode', 'showtitle', 'playcount']}, 'id': 1} @@ -296,7 +340,6 @@ def getAllEpisodes(self, xbmc_id): return result class Player(xbmc.Player): - def __init__ (self): xbmc.Player.__init__(self) log('Player - init') From dbd7ceeb04c164ef091fdd54ec47b3c11d1f6d4d Mon Sep 17 00:00:00 2001 From: Andrea Panizza Date: Mon, 22 Mar 2021 16:25:55 +0100 Subject: [PATCH 2/5] refactoring fixes --- default.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/default.py b/default.py index 76b325a..f6f4029 100644 --- a/default.py +++ b/default.py @@ -72,6 +72,8 @@ def onSettingsChanged( self ): def onNotification(self, sender, method, data): log('onNotification') log('method=%s' % method) + log('sender=%s' % sender) + log('data=%s' % data) if (method == 'Player.OnPlay'): self._player_onplay(data) if (method == 'Player.OnStop'): @@ -87,6 +89,7 @@ def _player_onplay(self, data): if player.http == 'true' and player.getPlayingFile()[:4] == 'http' and re.search(r'[sS][0-9]*[eE][0-9]*', os.path.basename(player.getPlayingFile()), flags=0) : player.http_playing = True player.filename = os.path.basename(player.getPlayingFile()) + log('rawname=%s' % player.filename) startcut = player.filename.find("%5B") endcut = player.filename.find("%5D") tocut = player.filename[startcut:endcut] @@ -114,7 +117,7 @@ def _player_onplay(self, data): player.http_playing = False response = json.loads(data) log('%s' % response) - if response.get('item').get('type') != 'episode': + if response.get('item') is not None and reponse.get.get('type') != 'episode': return xbmc_id = response.get('item').get('id') @@ -241,7 +244,7 @@ def _video_onupdate(self, data): log('episode_id=%s' % item['episode_id']) log('playcount=%s' % playcount) - if len(item['showtitle']) > 0 and item['season'] > 0 and item['episode'] > 0 and len(str(item['episode_id'])) > 0: + if item.get('showtitle') is None or item.get('season') is None or item.get('episode') is None or item.get('episode_id') is None: return self.filename = '%s.S%.2dE%.2d' % (formatName(item['showtitle']), float(item['season']), float(item['episode'])) @@ -398,7 +401,7 @@ def notif(msg, time=5000): def log(msg): xbmc.log("### [%s] - %s" % (__scriptname__, encode(msg), ), - level=xbmc.LOGDEBUG) #100 #xbmc.LOGDEBUG + level=xbmc.LOGINFO) #100 #xbmc.LOGDEBUG def encode(string): result = '' From 64d66b03af59bba8a604e60c3c095129aca39027 Mon Sep 17 00:00:00 2001 From: Andrea Panizza Date: Mon, 22 Mar 2021 16:31:17 +0100 Subject: [PATCH 3/5] refactoring fixes --- default.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/default.py b/default.py index f6f4029..3d8f246 100644 --- a/default.py +++ b/default.py @@ -117,7 +117,7 @@ def _player_onplay(self, data): player.http_playing = False response = json.loads(data) log('%s' % response) - if response.get('item') is not None and reponse.get.get('type') != 'episode': + if response.get('item') is None or response.get('item').get('type') != 'episode': return xbmc_id = response.get('item').get('id') @@ -231,8 +231,9 @@ def _video_onupdate(self, data): log('VideoLibrary.OnUpdate') response = json.loads(data) log('%s' % response) - if response.get('item').get('type') != 'episode': + if response.get('item') is None or response.get('item').get('type') != 'episode': return + xbmc_id = response.get('item').get('id') playcount = response.get('playcount') log('playcount=%s' % playcount) From 9eb1bf23ee926fb1e36d0da5d81dc8b162051de9 Mon Sep 17 00:00:00 2001 From: Andrea Panizza Date: Mon, 22 Mar 2021 17:48:25 +0100 Subject: [PATCH 4/5] Added autofollow --- resources/lib/tvtime.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/resources/lib/tvtime.py b/resources/lib/tvtime.py index d560c8e..c799715 100644 --- a/resources/lib/tvtime.py +++ b/resources/lib/tvtime.py @@ -157,21 +157,29 @@ def __init__(self, token, episode_id): self.is_watched = data['code'] class MarkAsWatched(object): - def __init__(self, token, episode_id, facebook=0, twitter=0): + def __init__(self, token, episode_id, facebook=0, twitter=0, autofollow=1): self.token = token self.episode_id = episode_id + self.facebook = facebook if self.facebook == True: self.facebook = 1 else: self.facebook = 0 + self.twitter = twitter if self.twitter == True: self.twitter = 1 else: self.twitter = 0 + + self.autofollow = autofollow + if self.autofollow == True: self.autofollow = 1 + else: self.autofollow = 0 + self.action = 'checkin' request_data = urllib.parse.urlencode({ 'access_token' : self.token, 'episode_id' : self.episode_id, 'publish_on_ticker' : self.facebook, - 'publish_on_twitter' : self.twitter + 'publish_on_twitter' : self.twitter, + 'auto_follow': self.autofollow }).encode("utf-8") self.cj = http.cookiejar.CookieJar() From 49eaaea43b4babeea4dc7e3a2081fde11facd93f Mon Sep 17 00:00:00 2001 From: Andrea Panizza Date: Mon, 22 Mar 2021 17:48:28 +0100 Subject: [PATCH 5/5] Added autofollow --- default.py | 29 +++++++++++++++++++++++---- resources/language/English/strings.po | 4 ++++ resources/language/French/strings.po | 4 ++++ resources/language/Italian/strings.po | 4 ++++ resources/lib/tvtime.py | 7 +++---- resources/settings.xml | 1 + 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/default.py b/default.py index 3d8f246..c02cbfd 100644 --- a/default.py +++ b/default.py @@ -24,6 +24,7 @@ from resources.lib.tvtime import FindEpisode from resources.lib.tvtime import MarkAsWatched +from resources.lib.tvtime import Follow from resources.lib.tvtime import MarkAsUnWatched from resources.lib.tvtime import GetUserInformations from resources.lib.tvtime import SaveProgress @@ -173,12 +174,21 @@ def _player_onstop(self, data): if actual_percent <= 90: return - log('MarkAsWatched(*, %s, %s, %s)' % (player.filename, player.facebook, player.twitter)) - checkin = MarkAsWatched(player.token, player.episode.id, player.facebook, player.twitter) + log('MarkAsWatched(*, %s, %s, %s, %s)' % (player.filename, player.facebook, player.twitter, player.autofollow)) + checkin = MarkAsWatched(player.token, player.episode.id, player.facebook, player.twitter, player.autofollow) log('checkin.is_marked:=%s' % checkin.is_marked) if not checkin.is_marked: return + # this is just temporary fix because TVTime's Checkin API is not working correctly + # auto_follow parameter is not working, if tvtime fixes this issue we can remove this piece of code + try: + if player.autofollow: + log("following tvshow manually=%s" % player.episode.showid) + Follow(player.token, player.episode.showid) + except: + pass + if player.emotion == 'true': msg = '%s: %s %sx%s' % (__language__(33909), player.episode.showname, player.episode.season_number, player.episode.number) emotion = xbmcgui.Dialog().select(msg, [__language__(35311), __language__(35312), __language__(35313), __language__(35314), __language__(35316), __language__(35317)]) @@ -257,9 +267,19 @@ def _video_onupdate(self, data): return if playcount == 1: - log('MarkAsWatched(*, %s, %s, %s)' % (self.filename, player.facebook, player.twitter)) - checkin = MarkAsWatched(player.token, self.episode.id, player.facebook, player.twitter) + log('MarkAsWatched(*, %s, %s, %s, %s)' % (self.filename, player.facebook, player.twitter, player.autofollow)) + checkin = MarkAsWatched(player.token, self.episode.id, player.facebook, player.twitter, player.autofollow) log('checkin.is_marked:=%s' % checkin.is_marked) + + # this is just temporary fix because TVTime's Checkin API is not working correctly + # auto_follow parameter is not working, if tvtime fixes this issue we can remove this piece of code + try: + if player.autofollow: + log("following tvshow manually=%s" % self.episode.showid) + Follow(player.token, self.episode.showid) + except: + pass + if checkin.is_marked: if player.emotion == 'true': emotion = xbmcgui.Dialog().select('%s: %s' % (__language__(33909), self.filename), [__language__(35311), __language__(35312), __language__(35313), __language__(35314), __language__(35316), __language__(35317)]) @@ -353,6 +373,7 @@ def __init__ (self): self.welcome = __addon__.getSetting('welcome') self.notifications = __addon__.getSetting('notifications') self.notif_during_playback = __addon__.getSetting('notif_during_playback') + self.autofollow = __addon__.getSetting('autofollow') self.notif_scrobbling = __addon__.getSetting('notif_scrobbling') self.progress = __addon__.getSetting('progress') self.http = __addon__.getSetting('http') diff --git a/resources/language/English/strings.po b/resources/language/English/strings.po index d612b77..77fcba9 100644 --- a/resources/language/English/strings.po +++ b/resources/language/English/strings.po @@ -41,6 +41,10 @@ msgctxt "#32303" msgid "Mark the http streams" msgstr "" +msgctxt "#32304" +msgid "Auto-follow the show if not already followed" +msgstr "" + msgctxt "#33001" msgid "Notifications" msgstr "" diff --git a/resources/language/French/strings.po b/resources/language/French/strings.po index 6b9aa0b..c9ecc71 100644 --- a/resources/language/French/strings.po +++ b/resources/language/French/strings.po @@ -41,6 +41,10 @@ msgctxt "#32303" msgid "Mark the http streams" msgstr "Marquer les flux http" +msgctxt "#32304" +msgid "Auto-follow the show if not already followed" +msgstr "Suivre automatiquement le spectacle s'il n'est pas déjà suivi" + msgctxt "#33001" msgid "Notifications" msgstr "Notifications" diff --git a/resources/language/Italian/strings.po b/resources/language/Italian/strings.po index e464264..99d5dc4 100644 --- a/resources/language/Italian/strings.po +++ b/resources/language/Italian/strings.po @@ -41,6 +41,10 @@ msgctxt "#32303" msgid "Mark the http streams" msgstr "Segna i flussi http" +msgctxt "#32304" +msgid "Auto-follow the show if not already followed" +msgstr "Segui automaticamente lo show se non è già seguito" + msgctxt "#33001" msgid "Notifications" msgstr "Notifiche" diff --git a/resources/lib/tvtime.py b/resources/lib/tvtime.py index c799715..5d2f74f 100644 --- a/resources/lib/tvtime.py +++ b/resources/lib/tvtime.py @@ -45,6 +45,7 @@ def __init__(self, token, episode_id, filename=''): else: self.is_found = True self.resultdata = data['result'] + self.showid = data['episode']['show']['id'] self.showname = data['episode']['show']['name'] self.episodename = data['episode']['name'] self.season_number = data['episode']['season_number'] @@ -170,10 +171,8 @@ def __init__(self, token, episode_id, facebook=0, twitter=0, autofollow=1): else: self.twitter = 0 self.autofollow = autofollow - if self.autofollow == True: self.autofollow = 1 - else: self.autofollow = 0 - self.action = 'checkin' + request_data = urllib.parse.urlencode({ 'access_token' : self.token, 'episode_id' : self.episode_id, @@ -206,7 +205,7 @@ def __init__(self, token, episode_id, facebook=0, twitter=0, autofollow=1): self.is_marked = False else: self.is_marked = True - + class MarkAsUnWatched(object): def __init__(self, token, episode_id): self.token = token diff --git a/resources/settings.xml b/resources/settings.xml index 9452c15..1c65674 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -5,6 +5,7 @@ +