add resolution limit (#90)

This commit is contained in:
andreas-woelfl 2017-07-29 03:43:48 +02:00 committed by angelblue05
commit 82c02594cb
4 changed files with 40 additions and 4 deletions

View file

@ -168,6 +168,11 @@ class PlayUtils():
log.info("Can't direct play, server doesn't allow/support it.")
return False
# Verify screen resolution
if self.resolutionConflict():
log.info("Can't direct play, resolution limit is enabled")
return False
location = self.item['LocationType']
if location == "FileSystem":
# Verify the path
@ -271,6 +276,11 @@ class PlayUtils():
log.info("The network speed is insufficient to direct stream file.")
return False
# Verify screen resolution
if self.resolutionConflict():
log.info("Can't direct stream, resolution limit is enabled")
return False
return True
def directStream(self):
@ -331,6 +341,11 @@ class PlayUtils():
if transcodeHi10P == "true":
playurl = "%s&MaxVideoBitDepth=8" % playurl
# Adjust video resolution
if self.resolutionConflict():
screenRes = self.getScreenResolution()
playurl = "%s&maxWidth=%s&maxHeight=%s" % (playurl, screenRes['width'], screenRes['height'])
user_token = downloadutils.DownloadUtils().get_token()
playurl += "&api_key=" + str(user_token)
@ -659,4 +674,22 @@ class PlayUtils():
"DidlMode": ""
}
]
}
}
def resolutionConflict(self):
if settings('limitResolution') == "true":
screenRes = self.getScreenResolution()
videoRes = self.getVideoResolution()
return videoRes['width'] > screenRes['width'] or videoRes['height'] > screenRes['height']
else:
return False
def getScreenResolution(self):
wind = xbmcgui.Window()
return {'width' : wind.getWidth(),
'height' : wind.getHeight()}
def getVideoResolution(self):
return {'width' : self.item['MediaStreams'][0]['Width'],
'height' : self.item['MediaStreams'][0]['Height']}