Skip to content

Commit 528ce8e

Browse files
committed
Automatically seek to the right starting position of video
1 parent 9d8a420 commit 528ce8e

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

lib/play.py

+8-23
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
# along with script.module.srgssr.
1818
# If not, see <http://www.gnu.org/licenses/>.
1919

20-
from urllib.parse import parse_qsl, ParseResult
21-
from urllib.parse import urlparse as urlps
22-
2320
import json
21+
import xbmc
2422
import xbmcgui
2523
import xbmcplugin
2624

@@ -133,28 +131,15 @@ def play_video(self, media_id_or_urn):
133131
end_time = end_time // 1000
134132
break
135133

136-
if start_time and end_time:
137-
parsed_url = urlps(auth_url)
138-
query_list = parse_qsl(parsed_url.query)
139-
updated_query_list = []
140-
for query in query_list:
141-
if query[0] == "start" or query[0] == "end":
142-
continue
143-
updated_query_list.append(query)
144-
updated_query_list.append(("start", str(start_time)))
145-
updated_query_list.append(("end", str(end_time)))
146-
new_query = utils.assemble_query_string(updated_query_list)
147-
surl_result = ParseResult(
148-
parsed_url.scheme,
149-
parsed_url.netloc,
150-
parsed_url.path,
151-
parsed_url.params,
152-
new_query,
153-
parsed_url.fragment,
154-
)
155-
auth_url = surl_result.geturl()
156134
self.srgssr.log(f"play_video, auth_url = {auth_url}")
157135
play_item = xbmcgui.ListItem(title, path=auth_url)
136+
if self.srgssr.get_kodi_major_version() >= 20 and start_time and end_time:
137+
info_tag = play_item.getVideoInfoTag()
138+
duration = end_time - start_time
139+
info_tag.setResumePoint(start_time, duration)
140+
info_tag.addVideoStream(xbmc.VideoStreamDetail(duration=duration))
141+
info_tag.setDuration(duration)
142+
158143
subs = self.srgssr.get_subtitles(stream_url, urn)
159144
if subs:
160145
play_item.setSubtitles(subs)

lib/srgssr.py

+14
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ def open_url(self, url, use_cache=True):
200200
return response.text
201201
return self.cache.get(f"{ADDON_NAME}.open_url, url = {url}")
202202

203+
def get_kodi_major_version(self):
204+
"""
205+
Returns the major version number of Kodi (e.g., 20 for Kodi 20 Nexus).
206+
"""
207+
version = xbmc.getInfoLabel("System.BuildVersion")
208+
try:
209+
major_version = int(version.split(".")[0])
210+
return major_version
211+
except (IndexError, ValueError):
212+
self.log(
213+
"get_kodi_major_version: Failed to parse Kodi version, assuming version 19"
214+
)
215+
return 19
216+
203217
def get_youtube_icon(self):
204218
path = os.path.join(
205219
# https://github.com/xbmc/xbmc/pull/19301

0 commit comments

Comments
 (0)