Skip to content

Commit

Permalink
[script.plexmod] 0.7.3-rev2
Browse files Browse the repository at this point in the history
  • Loading branch information
pannal committed Dec 31, 2023
1 parent a131c9a commit 1a21617
Show file tree
Hide file tree
Showing 16 changed files with 204 additions and 103 deletions.
38 changes: 17 additions & 21 deletions script.plexmod/addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.plexmod"
name="PM4K for Plex"
version="0.7.2"
name="Plex"
version="0.7.3-rev2"
provider-name="pannal">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
Expand All @@ -25,25 +25,21 @@
<source>https://github.com/pannal/plex-for-kodi</source>
<platform>all</platform>
<news>
- Fix: playing next episode when episode played threshold was met when hitting STOP button
- Fix: Dropdown would roundrobin falsely onup item when initial item wasn't item 0
- Fix: Movies: pressing back in a scrolled movie view with the header options open wouldn't back out properly
- Fix: Reset library filters when Role/Cast view opened
- Fix: Cast display in movies/preplay
- Fix: Apply dialog flicker fix in Role/Cast
- Fix: Dropdowns were broken sometimes (especially library view)
- Fix: Addon crash on non-default Kodi (e.g. OSMC) due to System.BuildVersion not matching Kodi's default
- Fix: Error on no data returned on PlexObject.reload (disconnect); Handle connection errors more gracefully
- Fix: Background of info page (thanks @bowlingbeeg)
- Fix: Rare SeekDialog crashes between episodes
- Fix: OpenSubtitles not finding subtitles for certain Movies

- Core: Harden against network disconnects in multiple views, home and videoplayer/seekdialog
- Core: Re-enable backing out of videoplayer (inbetween screen)
- Core: Player: Alternative implementation of bingeMode auto-next; ignore stop events when triggering non-user-stop
- Core: Add setting for poster/thumbnail resolution scaling, implement everywhere sensible
- Core: Thumbnails/Art: use the same parameters as PlexWeb for images
- SeekDialog: Possible fix for OSD not coming up again in some scenarios
- Fix: certain home hubs were limited to 10 items without pagination
- Fix: very rare infinite playback loop with enabled embedded subtitles (thanks @florinvlaicu for reporting)
- Fix: Partially fix issues when switching audio streams during Transcoded/DirectStream playback
- Fix: Fix error in ExtendHubTask
- Fix: Partially revert "Home: Increase section change timeout from 0.3s to 0.5s; re-jig section change handling to allow using ENTER/SELECT to immediately select a section below 0.5s wait time" due to instability
- Fix: Fix a couple of SyntaxWarnings for invalid escape sequences
- Fix: Unfocusable buttons throw focus errors occasionally on shutdown
- Fix: Laggy UI after playback/5 minutes due to requesting certain hubs without limits applied. Drastically improving UI smoothness even for smaller hubs (below 1000 items)
This also fixes crash and shutdown issues and by proxy should enable everyone to use a poster resolution scale of at least 200%.
- Fix: Depending on the situation, the home hubs update request could be sent multiple times while waiting for the first one to finish. (thanks @bowlingbeeg)
- Subtitles: Supply OpenSubtitles.com hash if possible and enabled
- Subtitles: Add setting to Audio/Subtitles to calculate the OpenSubtitles.com hash (default: off)
- Core: Advanced Settings: make default resolution scale a percentage; limit to 750% max (based on Plex max poster size)
- Core: Add more debug logging for player events
- Core: Add more debug logging details for hub refresh events
</news>
<assets>
<icon>icon.png</icon>
Expand Down
18 changes: 18 additions & 0 deletions script.plexmod/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
[- 0.7.3-rev2 -]
- Fix: certain home hubs were limited to 10 items without pagination
- Fix: very rare infinite playback loop with enabled embedded subtitles (thanks @florinvlaicu for reporting)
- Fix: Partially fix issues when switching audio streams during Transcoded/DirectStream playback
- Fix: Fix error in ExtendHubTask
- Fix: Partially revert "Home: Increase section change timeout from 0.3s to 0.5s; re-jig section change handling to allow using ENTER/SELECT to immediately select a section below 0.5s wait time" due to instability
- Fix: Fix a couple of SyntaxWarnings for invalid escape sequences
- Fix: Unfocusable buttons throw focus errors occasionally on shutdown
- Fix: Laggy UI after playback/5 minutes due to requesting certain hubs without limits applied. Drastically improving UI smoothness even for smaller hubs (<1000 items)
This also fixes crash and shutdown issues and by proxy should enable everyone to use a poster resolution scale of at least 200%.
- Fix: Depending on the situation, the home hubs update request could be sent multiple times while waiting for the first one to finish. (thanks @bowlingbeeg)
- Subtitles: Supply OpenSubtitles.com hash if possible and enabled
- Subtitles: Add setting to Audio/Subtitles to calculate the OpenSubtitles.com hash (default: off)
- Core: Advanced Settings: make default resolution scale a percentage; limit to 750% max (based on Plex max poster size)
- Core: Add more debug logging for player events
- Core: Add more debug logging details for hub refresh events


[- 0.7.2 -]
- Fix: playing next episode when episode played threshold was met when hitting STOP button
- Fix: Dropdown would roundrobin falsely onup item when initial item wasn't item 0
Expand Down
2 changes: 1 addition & 1 deletion script.plexmod/lib/_included_packages/plexnet/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def getUrl(self):

def getRelativeUrl(self):
url = self.getUrl()
m = re.match('^\w+:\/\/.+?(\/.+)', url)
m = re.match(r'^\w+://.+?(/.+)', url)
if m:
return m.group(1)
return url
Expand Down
8 changes: 5 additions & 3 deletions script.plexmod/lib/_included_packages/plexnet/plexlibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,11 @@ def extend(self, start=None, size=None):
items = plexobjects.listItems(self.server, path)
self.offset = plexobjects.PlexValue(start)
self.size = plexobjects.PlexValue(len(items))
self.more = plexobjects.PlexValue(
(items[0].container.offset.asInt() + items[0].container.size.asInt() < items[0].container.totalSize.asInt()) and '1' or ''
)
self.more = plexobjects.PlexValue('')
if items:
self.more = plexobjects.PlexValue(
(items[0].container.offset.asInt() + items[0].container.size.asInt() < items[0].container.totalSize.asInt()) and '1' or ''
)
return items


Expand Down
11 changes: 7 additions & 4 deletions script.plexmod/lib/_included_packages/plexnet/plexserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ def buildUrl(self, path, includeToken=False):
def query(self, path, method=None, **kwargs):
method = method or self.session.get

limit = kwargs.pop("limit", None)
params = kwargs.pop("params", None)
if params:
if limit is None:
limit = params.get("limit", None)
path += util.joinArgs(params, '?' not in path)

offset = kwargs.pop("offset", None)
limit = kwargs.pop("limit", None)
if kwargs:
path += util.joinArgs(kwargs, '?' not in path)
kwargs.clear()
Expand All @@ -208,9 +210,10 @@ def query(self, path, method=None, **kwargs):
return None

# add offset/limit
if offset is not None:
url = http.addUrlParam(url, "X-Plex-Container-Start=%s" % offset)
offset = offset or 0

if limit is not None:
url = http.addUrlParam(url, "X-Plex-Container-Start=%s" % offset)
url = http.addUrlParam(url, "X-Plex-Container-Size=%s" % limit)

util.LOG('{0} {1}'.format(method.__name__.upper(), re.sub('X-Plex-Token=[^&]+', 'X-Plex-Token=****', url)))
Expand Down Expand Up @@ -584,7 +587,7 @@ def getLibrarySectionPrefs(self, uuid):
return None

def swizzleUrl(self, url, includeToken=False):
m = re.Search("^\w+:\/\/.+?(\/.+)", url)
m = re.search(r"^\w+://.+?(/.+)", url)
newUrl = m and m.group(1) or None
return self.buildUrl(newUrl or url, includeToken)

Expand Down
8 changes: 4 additions & 4 deletions script.plexmod/lib/kodijsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def __init__(self):

def __getattr__(self, method):
def handler(*args, **kwargs):
args = [str(a).replace(',', '\,') for a in args]
args = [str(a).replace(',', r'\,') for a in args]
for k, v in kwargs.items():
args.append('{0}={v}'.format(k, str(v).replace(',', '\,')))
args.append('{0}={v}'.format(k, str(v).replace(',', r'\,')))

if args:
command = '{0}.{1}({2})'.format(self.module, method, ','.join(args))
Expand All @@ -77,9 +77,9 @@ def handler(*args, **kwargs):
return handler

def __call__(self, *args, **kwargs):
args = [str(a).replace(',', '\,') for a in args]
args = [str(a).replace(',', r'\,') for a in args]
for k, v in kwargs.items():
args.append('{0}={v}'.format(k, str(v).replace(',', '\,')))
args.append('{0}={v}'.format(k, str(v).replace(',', r'\,')))

if args:
command = '{0}({1})'.format(self.module, ','.join(args))
Expand Down
18 changes: 15 additions & 3 deletions script.plexmod/lib/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def __init__(self, player, session_id=None):
self.bifURL = ''
self.title = ''
self.title2 = ''
self.seekOnStart = 0
self.chapters = None
self.stoppedInBingeMode = False
self.inBingeMode = False
Expand Down Expand Up @@ -247,7 +248,9 @@ def shouldShowPostPlay(self):

def showPostPlay(self):
if not self.shouldShowPostPlay():
util.DEBUG_LOG("SeekHandler: Not showing post-play")
return
util.DEBUG_LOG("SeekHandler: Showing post-play")

self.seeking = self.SEEK_POST_PLAY
self.hideOSD(delete=True)
Expand Down Expand Up @@ -321,6 +324,11 @@ def hideOSD(self, delete=False):
util.garbageCollect()

def seek(self, offset, settings_changed=False, seeking=SEEK_IN_PROGRESS):
util.DEBUG_LOG(
"SeekHandler: offset={0}, settings_changed={1}, seeking={2}, state={3}".format(offset,
settings_changed,
seeking,
self.player.playState))
if offset is None:
return

Expand All @@ -340,7 +348,7 @@ def seek(self, offset, settings_changed=False, seeking=SEEK_IN_PROGRESS):
if self.player.playState == self.player.STATE_PAUSED:
self.player.pauseAfterPlaybackStarted = True

util.DEBUG_LOG('New player offset: {0}'.format(self.offset))
util.DEBUG_LOG('New player offset: {0}, state: {1}'.format(self.offset, self.player.playState))
self.player._playVideo(offset, seeking=self.seeking, force_update=settings_changed)

def fastforward(self):
Expand Down Expand Up @@ -421,7 +429,9 @@ def onPlayBackResumed(self):
# self.hideOSD()

def onPlayBackStopped(self):
util.DEBUG_LOG('SeekHandler: onPlayBackStopped - Seeking={0}'.format(self.seeking))
util.DEBUG_LOG('SeekHandler: onPlayBackStopped - '
'Seeking={0}, QueueingNext={1}, BingeMode={2}'.format(self.seeking, self.queuingNext,
self.inBingeMode))

if self.dialog:
self.dialog.onPlayBackStopped()
Expand Down Expand Up @@ -485,6 +495,7 @@ def onPlayBackPaused(self):
self.dialog.onPlayBackPaused()

def onPlayBackSeek(self, stime, offset):
util.DEBUG_LOG('SeekHandler: onPlayBackSeek - {0}, {1}, {2}'.format(stime, offset, self.seekOnStart))
if self.dialog:
self.dialog.onPlayBackSeek(stime, offset)

Expand All @@ -494,7 +505,7 @@ def onPlayBackSeek(self, stime, offset):
seeked = self.dialog.tick(stime)

if seeked:
util.DEBUG_LOG("OnPlayBackSeek: Seeked on start")
util.DEBUG_LOG("OnPlayBackSeek: Seeked on start to: {0}".format(stime))
self.seekOnStart = 0
return

Expand Down Expand Up @@ -1087,6 +1098,7 @@ def _playVideo(self, offset=0, seeking=0, force_update=False, playerObject=None)
meta.playStart = introOffset // 1000
else:
if offset:
util.DEBUG_LOG("Using as SeekOnStart: {0}; offset: {1}".format(meta.playStart, offset))
self.handler.seekOnStart = meta.playStart * 1000
elif introOffset:
util.DEBUG_LOG("Seeking behind intro after playstart: {}".format(introOffset))
Expand Down
43 changes: 37 additions & 6 deletions script.plexmod/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error
import six
import os
import struct
import requests

from .kodijsonrpc import rpc
from kodi_six import xbmc
Expand All @@ -21,7 +23,6 @@
from kodi_six import xbmcvfs

from . import colors
from .exceptions import NoDataException
from plexnet import signalsmixin, plexapp

DEBUG = True
Expand Down Expand Up @@ -170,7 +171,7 @@ class AdvancedSettings(object):
("dbg_crossfade", True),
("subtitle_use_extended_title", True),
("dialog_flicker_fix", True),
("poster_resolution_scale", 1.0),
("poster_resolution_scale_perc", 100),
)

def __init__(self):
Expand Down Expand Up @@ -579,7 +580,7 @@ def durationToShortText(seconds):
def cleanLeadingZeros(text):
if not text:
return ''
return re.sub('(?<= )0(\d)', r'\1', text)
return re.sub(r'(?<= )0(\d)', r'\1', text)


def removeDups(dlist):
Expand Down Expand Up @@ -627,9 +628,12 @@ def shortenText(text, size):
return u'{0}\u2026'.format(text[:size - 1])


def scaleResolution(w, h, by=advancedSettings.posterResolutionScale):
if 0 < by != 1.0:
px = w * h * by
def scaleResolution(w, h, by=None):
if by is None:
by = advancedSettings.posterResolutionScalePerc

if 0 < by != 100.0:
px = w * h * (by / 100.0)
wratio = h / float(w)
hratio = w / float(h)
return int(round((px / wratio) ** .5)), int(round((px / hratio) ** .5))
Expand Down Expand Up @@ -966,6 +970,33 @@ def addURLParams(url, params):
return url


OSS_CHUNK = 65536


def getOpenSubtitlesHash(size, url):
long_long_format = "q" # long long
byte_size = struct.calcsize(long_long_format)
hash_ = filesize = size
if filesize < OSS_CHUNK * 2:
return

buffer = b''
for _range in ((0, OSS_CHUNK), (filesize-OSS_CHUNK, filesize)):
try:
r = requests.get(url, headers={"range": "bytes={0}-{1}".format(*_range)}, stream=True)
except:
return ''
buffer += r.raw.read(OSS_CHUNK)

for x in range(int(OSS_CHUNK / byte_size) * 2):
size = x * byte_size
(l_value,) = struct.unpack(long_long_format, buffer[size:size + byte_size])
hash_ += l_value
hash_ = hash_ & 0xFFFFFFFFFFFFFFFF

return format(hash_, "016x")


def garbageCollect():
gc.collect(2)

Expand Down
Loading

0 comments on commit 1a21617

Please sign in to comment.