Skip to content

Commit

Permalink
Merge pull request trakt#276 from Razzeee/master
Browse files Browse the repository at this point in the history
Merge dev
  • Loading branch information
razzeee committed Mar 4, 2016
2 parents 39e1662 + eca6ea7 commit e4c3062
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 65 deletions.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.trakt" name="Trakt" version="3.1.2" provider-name="Trakt.tv, Razzeee">
<addon id="script.trakt" name="Trakt" version="3.1.3" provider-name="Trakt.tv, Razzeee">
<requires>
<import addon="xbmc.python" version="2.24.0"/>
<import addon="script.module.simplejson" version="3.3.0"/>
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
version 3.1.3
- bugfix for movies being rated with 1 on sync
- added fallback for dates outside of the unix timespan - they will now fall back to the current date/time
- fixed rating popup not showing up for content from external addons

version 3.1.2
- bugfix for movie playback progress sync

Expand Down
7 changes: 4 additions & 3 deletions scrobbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,16 @@ def playbackStarted(self, data):
if utilities.getSettingAsBool('scrobble_movie') or utilities.getSettingAsBool('scrobble_episode'):
result = self.__scrobble('start')
elif utilities.getSettingAsBool('rate_movie') and utilities.isMovie(self.curVideo['type']) and 'ids' in self.curVideoInfo:
result = {'movie': self.traktapi.getMovieSummary(utilities.best_id(self.curVideoInfo['ids'])).to_dict()}
result['movie']['movieid'] = self.curVideo['id']
best_id = utilities.best_id(self.curVideoInfo['ids'])
result = {'movie': self.traktapi.getMovieSummary(best_id).to_dict()}
if 'id' in self.curVideo: result['movie']['movieid'] = self.curVideo['id']
elif utilities.getSettingAsBool('rate_episode') and utilities.isEpisode(self.curVideo['type']) and 'ids' in self.traktShowSummary:
best_id = utilities.best_id(self.traktShowSummary['ids'])
result = {'show': self.traktapi.getShowSummary(best_id).to_dict(),
'episode': self.traktapi.getEpisodeSummary(best_id, self.curVideoInfo['season'],
self.curVideoInfo['number']).to_dict()}
result['episode']['season'] = self.curVideoInfo['season']
result['episode']['episodeid']= self.curVideo['id']
if 'id' in self.curVideo: result['episode']['episodeid'] = self.curVideo['id']

self.__preFetchUserRatings(result)

Expand Down
7 changes: 3 additions & 4 deletions service.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,9 @@ def onPlayBackStarted(self):
elif showtitle:
title, season, episode = utilities.regex_tvshow(False, showtitle)
data['type'] = 'episode'
data['season'] = int(season)
data['episode'] = int(episode)
data['showtitle'] = title
data['title'] = title
data['season'] = season
data['episode'] = episode
data['title'] = data['showtitle'] = title
logger.debug("[traktPlayer] onPlayBackStarted() - Title: %s, showtitle: %s, season: %d, episode: %d" % (title, showtitle, season, episode))
else:
logger.debug("[traktPlayer] onPlayBackStarted() - Non-library file, not enough data for scrobbling, skipping.")
Expand Down
8 changes: 4 additions & 4 deletions syncMovies.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ def __compareMovies(self, movies_col1, movies_col2, watched=False, restrict=Fals
if 'collected' in movie_col1 and movie_col1['collected']:
if watched and (movie_col1['watched'] == 1):
movies.append(movie_col1)
elif not watched:
elif rating and movie_col1['rating'] <> 0:
movies.append(movie_col1)
elif not watched and not rating:

movies.append(movie_col1)
return movies


Expand Down Expand Up @@ -343,9 +345,7 @@ def __syncMovieRatings(self, traktMovies, kodiMovies, fromPercent, toPercent):

self.sync.UpdateProgress(fromPercent, line1='', line2=utilities.getString(32180) % len(traktMoviesToUpdate))

moviesRatings = {'movies': []}
for movie in traktMoviesToUpdate:
moviesRatings['movies'].append(movie)
moviesRatings = {'movies': traktMoviesToUpdate}

self.sync.traktapi.addRating(moviesRatings)

Expand Down
79 changes: 26 additions & 53 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@

logger = logging.getLogger(__name__)

REGEX_EXPRESSIONS = ['[Ss]([0-9]+)[][._-]*[Ee]([0-9]+)([^\\\\/]*)$',
'[\._ \-]([0-9]+)x([0-9]+)([^\\/]*)', # foo.1x09
'[\._ \-]([0-9]+)([0-9][0-9])([\._ \-][^\\/]*)', # foo.109
'([0-9]+)([0-9][0-9])([\._ \-][^\\/]*)',
'[\\\\/\\._ -]([0-9]+)([0-9][0-9])[^\\/]*',
'Season ([0-9]+) - Episode ([0-9]+)[^\\/]*', # Season 01 - Episode 02
'Season ([0-9]+) Episode ([0-9]+)[^\\/]*', # Season 01 Episode 02
'[\\\\/\\._ -][0]*([0-9]+)x[0]*([0-9]+)[^\\/]*',
'[[Ss]([0-9]+)\]_\[[Ee]([0-9]+)([^\\/]*)', # foo_[s01]_[e01]
'[\._ \-][Ss]([0-9]+)[\.\-]?[Ee]([0-9]+)([^\\/]*)', # foo, s01e01, foo.s01.e01, foo.s01-e01
's([0-9]+)ep([0-9]+)[^\\/]*', # foo - s01ep03, foo - s1ep03
'[Ss]([0-9]+)[][ ._-]*[Ee]([0-9]+)([^\\\\/]*)$',
'[\\\\/\\._ \\[\\(-]([0-9]+)x([0-9]+)([^\\\\/]*)$'
]

REGEX_YEAR = '^(.+) \((\d{4})\)$'

REGEX_URL = '(^https?:https://)(.+)'
Expand Down Expand Up @@ -311,38 +296,26 @@ def findMediaObject(mediaObjectToMatch, listToSearch):
result = __findInList(listToSearch, title=mediaObjectToMatch['title'], year=mediaObjectToMatch['year'])
return result

def regex_tvshow(compare, file, sub=""):
tvshow = 0

for regex in REGEX_EXPRESSIONS:
response_file = re.findall(regex, file)
if len(response_file) > 0:
logger.debug("regex_tvshow(): Regex File Se: %s, Ep: %s," % (str(response_file[0][0]), str(response_file[0][1]),))
tvshow = 1
if not compare:
title = re.split(regex, file)[0]
for char in ['[', ']', '_', '(', ')', '.', '-']:
title = title.replace(char, ' ')
if title.endswith(" "):
title = title[:-1]
return title, response_file[0][0], response_file[0][1]
else:
break

if tvshow == 1:
for regex in REGEX_EXPRESSIONS:
response_sub = re.findall(regex, sub)
if len(response_sub) > 0:
try:
if int(response_sub[0][1]) == int(response_file[0][1]):
return True
except:
pass
return False
if compare:
return True
else:
return "", "", ""
def regex_tvshow(label):
regexes = [
'(.*?)[._ -]s([0-9]+)[._ -]*e([0-9]+)', # ShowTitle.S01E09; s01e09, s01.e09, s01-e09
'(.*?)[._ -]([0-9]+)x([0-9]+)', # Showtitle.1x09
'(.*?)[._ -]([0-9]+)([0-9][0-9])', # ShowTitle.109
'(.*?)[._ -]?season[._ -]*([0-9]+)[._ -]*-?[._ -]*episode[._ -]*([0-9]+)', # ShowTitle.Season 01 - Episode 02, Season 01 Episode 02
'(.*?)[._ -]\[s([0-9]+)\][._ -]*\[[e]([0-9]+)', # ShowTitle_[s01]_[e01]
'(.*?)[._ -]s([0-9]+)[._ -]*ep([0-9]+)'] # ShowTitle - s01ep03, ShowTitle - s1ep03

for regex in regexes:
match = re.search(regex, label, re.I)
if match:
show_title, season, episode = match.groups()
if show_title:
show_title = re.sub('[\[\]_\(\).-]', ' ', show_title)
show_title = re.sub('\s\s+', ' ', show_title)
show_title = show_title.strip()
return show_title, int(season), int(episode)

return '', -1, -1

def regex_year(title):
prog = re.compile(REGEX_YEAR)
Expand Down Expand Up @@ -571,14 +544,14 @@ def getMediaType():

def best_id(ids):
if 'trakt' in ids:
return ids['trakt'], 'trakt'
return ids['trakt']
elif 'imdb' in ids:
return ids['imdb'], 'imdb'
return ids['imdb']
elif 'tmdb' in ids:
return ids['tmdb'], 'tmdb'
return ids['tmdb']
elif 'tvdb' in ids:
return ids['tvdb'], 'tvdb'
return ids['tvdb']
elif 'tvrage' in ids:
return ids['tvrage'], 'tvrage'
return ids['tvrage']
elif 'slug' in ids:
return ids['slug'], 'slug'
return ids['slug']

0 comments on commit e4c3062

Please sign in to comment.