self.item

This commit is contained in:
SpootDev 2016-03-30 22:01:37 -05:00
parent 16fb22792f
commit 065b8d84f0

View file

@ -37,7 +37,7 @@ class API():
try: try:
userdata = self.item['UserData'] userdata = self.item['UserData']
except KeyError: # No userdata found. except KeyError: # No userdata found.
pass pass
@ -57,7 +57,7 @@ class API():
lastPlayedDate = userdata.get('LastPlayedDate') lastPlayedDate = userdata.get('LastPlayedDate')
if lastPlayedDate: if lastPlayedDate:
lastPlayedDate = lastPlayedDate.split('.')[0].replace('T', " ") lastPlayedDate = lastPlayedDate.split('.')[0].replace('T', " ")
if userdata['Played']: if userdata['Played']:
# Playcount is tied to the watch status # Playcount is tied to the watch status
played = True played = True
@ -91,10 +91,10 @@ class API():
try: try:
people = self.item['People'] people = self.item['People']
except KeyError: except KeyError:
pass pass
else: else:
for person in people: for person in people:
@ -116,17 +116,16 @@ class API():
} }
def getMediaStreams(self): def getMediaStreams(self):
item = self.item
videotracks = [] videotracks = []
audiotracks = [] audiotracks = []
subtitlelanguages = [] subtitlelanguages = []
try: try:
media_streams = item['MediaSources'][0]['MediaStreams'] media_streams = self.item['MediaSources'][0]['MediaStreams']
except KeyError: except KeyError:
if not item.get("MediaStreams"): return None if not self.item.get("MediaStreams"): return None
media_streams = item['MediaStreams'] media_streams = self.item['MediaStreams']
for media_stream in media_streams: for media_stream in media_streams:
# Sort through Video, Audio, Subtitle # Sort through Video, Audio, Subtitle
@ -141,12 +140,12 @@ class API():
'codec': codec, 'codec': codec,
'height': media_stream.get('Height'), 'height': media_stream.get('Height'),
'width': media_stream.get('Width'), 'width': media_stream.get('Width'),
'video3DFormat': item.get('Video3DFormat'), 'video3DFormat': self.item.get('Video3DFormat'),
'aspect': 1.85 'aspect': 1.85
} }
try: try:
container = item['MediaSources'][0]['Container'].lower() container = self.item['MediaSources'][0]['Container'].lower()
except: except:
container = "" container = ""
@ -161,16 +160,16 @@ class API():
track['codec'] = "avc1" track['codec'] = "avc1"
# Aspect ratio # Aspect ratio
if item.get('AspectRatio'): if self.item.get('AspectRatio'):
# Metadata AR # Metadata AR
aspect = item['AspectRatio'] aspect = self.item['AspectRatio']
else: # File AR else: # File AR
aspect = media_stream.get('AspectRatio', "0") aspect = media_stream.get('AspectRatio', "0")
try: try:
aspectwidth, aspectheight = aspect.split(':') aspectwidth, aspectheight = aspect.split(':')
track['aspect'] = round(float(aspectwidth) / float(aspectheight), 6) track['aspect'] = round(float(aspectwidth) / float(aspectheight), 6)
except (ValueError, ZeroDivisionError): except (ValueError, ZeroDivisionError):
width = track.get('width') width = track.get('width')
height = track.get('height') height = track.get('height')
@ -179,16 +178,16 @@ class API():
track['aspect'] = round(float(width / height), 6) track['aspect'] = round(float(width / height), 6)
else: else:
track['aspect'] = 1.85 track['aspect'] = 1.85
if item.get("RunTimeTicks"): if self.item.get("RunTimeTicks"):
track['duration'] = item.get("RunTimeTicks") / 10000000.0 track['duration'] = self.item.get("RunTimeTicks") / 10000000.0
videotracks.append(track) videotracks.append(track)
elif stream_type == "Audio": elif stream_type == "Audio":
# Codec, Channels, language # Codec, Channels, language
track = { track = {
'codec': codec, 'codec': codec,
'channels': media_stream.get('Channels'), 'channels': media_stream.get('Channels'),
'language': media_stream.get('Language') 'language': media_stream.get('Language')
@ -205,18 +204,17 @@ class API():
return { return {
'video': videotracks, 'video': videotracks,
'audio': audiotracks, 'audio': audiotracks,
'subtitle': subtitlelanguages 'subtitle': subtitlelanguages
} }
def getRuntime(self): def getRuntime(self):
item = self.item
try: try:
runtime = item['RunTimeTicks'] / 10000000.0 runtime = self.item['RunTimeTicks'] / 10000000.0
except KeyError: except KeyError:
runtime = item.get('CumulativeRunTimeTicks', 0) / 10000000.0 runtime = self.item.get('CumulativeRunTimeTicks', 0) / 10000000.0
return runtime return runtime
@ -234,20 +232,19 @@ class API():
def getStudios(self): def getStudios(self):
# Process Studios # Process Studios
item = self.item
studios = [] studios = []
try: try:
studio = item['SeriesStudio'] studio = self.item['SeriesStudio']
studios.append(self.verifyStudio(studio)) studios.append(self.verifyStudio(studio))
except KeyError: except KeyError:
studioList = item['Studios'] studioList = self.item['Studios']
for studio in studioList: for studio in studioList:
name = studio['Name'] name = studio['Name']
studios.append(self.verifyStudio(name)) studios.append(self.verifyStudio(name))
return studios return studios
def verifyStudio(self, studioName): def verifyStudio(self, studioName):
@ -265,12 +262,11 @@ class API():
def getChecksum(self): def getChecksum(self):
# Use the etags checksum and userdata # Use the etags checksum and userdata
item = self.item userdata = self.item['UserData']
userdata = item['UserData']
checksum = "%s%s%s%s%s%s%s" % ( checksum = "%s%s%s%s%s%s%s" % (
item['Etag'], self.item['Etag'],
userdata['Played'], userdata['Played'],
userdata['IsFavorite'], userdata['IsFavorite'],
userdata.get('Likes',''), userdata.get('Likes',''),
@ -282,9 +278,8 @@ class API():
return checksum return checksum
def getGenres(self): def getGenres(self):
item = self.item
all_genres = "" all_genres = ""
genres = item.get('Genres', item.get('SeriesGenres')) genres = self.item.get('Genres', self.item.get('SeriesGenres'))
if genres: if genres:
all_genres = " / ".join(genres) all_genres = " / ".join(genres)
@ -344,7 +339,7 @@ class API():
def getMpaa(self): def getMpaa(self):
# Convert more complex cases # Convert more complex cases
mpaa = self.item.get('OfficialRating', "") mpaa = self.item.get('OfficialRating', "")
if mpaa in ("NR", "UR"): if mpaa in ("NR", "UR"):
# Kodi seems to not like NR, but will accept Not Rated # Kodi seems to not like NR, but will accept Not Rated
mpaa = "Not Rated" mpaa = "Not Rated"
@ -362,9 +357,8 @@ class API():
def getFilePath(self): def getFilePath(self):
item = self.item
try: try:
filepath = item['Path'] filepath = self.item['Path']
except KeyError: except KeyError:
filepath = "" filepath = ""
@ -375,17 +369,16 @@ class API():
filepath = filepath.replace("\\\\", "smb://") filepath = filepath.replace("\\\\", "smb://")
filepath = filepath.replace("\\", "/") filepath = filepath.replace("\\", "/")
if item.get('VideoType'): if self.item.get('VideoType'):
videotype = item['VideoType'] videotype = self.item['VideoType']
# Specific format modification # Specific format modification
if 'Dvd'in videotype: if 'Dvd'in videotype:
filepath = "%s/VIDEO_TS/VIDEO_TS.IFO" % filepath filepath = "%s/VIDEO_TS/VIDEO_TS.IFO" % filepath
elif 'BluRay' in videotype: elif 'BluRay' in videotype:
filepath = "%s/BDMV/index.bdmv" % filepath filepath = "%s/BDMV/index.bdmv" % filepath
if "\\" in filepath: if "\\" in filepath:
# Local path scenario, with special videotype # Local path scenario, with special videotype
filepath = filepath.replace("/", "\\") filepath = filepath.replace("/", "\\")
return filepath return filepath