Skip to content

Commit

Permalink
Version 0.5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Paco8 committed Jun 26, 2024
1 parent fc210a7 commit f138e27
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 9 deletions.
2 changes: 1 addition & 1 deletion 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="plugin.video.skyott"
name="SkyOtt"
version="0.5.7"
version="0.5.8"
provider-name="Paco8">
<requires>
<!--- <import addon="xbmc.python" version="2.25.0"/> -->
Expand Down
85 changes: 85 additions & 0 deletions resources/lib/mpd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python
# encoding: utf-8
#
# SPDX-License-Identifier: LGPL-2.1-or-later

from __future__ import unicode_literals, absolute_import, division

import xml.dom.minidom as minidom
import datetime
import re

def parse_duration(duration_str):
# Regular expression to parse ISO 8601 duration format (e.g., PT1H2M3S)
pattern = re.compile(r'PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?')
match = pattern.match(duration_str)
if not match:
return 0

hours, minutes, seconds = match.groups()
hours = int(hours) if hours else 0
minutes = int(minutes) if minutes else 0
seconds = float(seconds) if seconds else 0

return datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds)

def find_unprotected_periods(doc):
unprotected_periods = []
protected_periods = []

periods = doc.getElementsByTagNameNS("urn:mpeg:dash:schema:mpd:2011", "Period")
for period in periods:
content_protection = period.getElementsByTagNameNS("urn:mpeg:dash:schema:mpd:2011", "ContentProtection")
if not content_protection:
unprotected_periods.append(period)
else:
protected_periods.append(period)

return unprotected_periods, protected_periods

def format_start_time(timedelta_obj):
total_seconds = timedelta_obj.total_seconds()
minutes = int(total_seconds // 60)
seconds = total_seconds % 60
# Format seconds to 6 decimal places
return "PT{}M{:.6f}S".format(minutes, seconds)

def set_period_start_times(periods):
current_time = datetime.timedelta()
for period in periods:
start_time = format_start_time(current_time)
period.setAttribute("start", start_time)

duration_str = period.getAttribute("duration")
if duration_str:
duration = parse_duration(duration_str)
current_time += duration
else:
# If no duration is provided, assume a default duration (e.g., 0 seconds)
duration = datetime.timedelta(seconds=0)
current_time += duration

def move_unprotected_periods(content):
doc = minidom.parseString(content)

# Find unprotected and protected periods
unprotected_periods, protected_periods = find_unprotected_periods(doc)

if not unprotected_periods:
return content

# Remove all periods
mpd = doc.getElementsByTagNameNS("urn:mpeg:dash:schema:mpd:2011", "MPD")[0]
periods = doc.getElementsByTagNameNS("urn:mpeg:dash:schema:mpd:2011", "Period")
for period in periods:
mpd.removeChild(period)

# Insert unprotected periods at the beginning
all_periods = unprotected_periods + protected_periods
for period in all_periods:
mpd.appendChild(period)

# Set the start times for all periods
set_period_start_times(all_periods)

return doc.toprettyxml()
9 changes: 2 additions & 7 deletions resources/lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ def play(params):

LOG('play - slug: {} service_key: {}'.format(slug, service_key))

#if sky.platform['name'] == 'SkyShowtime':
# if 'NO_ADS' not in sky.account['account_type']:
# show_notification(addon.getLocalizedString(30209))
# return

if slug:
info = sky.get_video_info(slug)
LOG('video info: {}'.format(info))
Expand Down Expand Up @@ -91,8 +86,8 @@ def play(params):
return

url = data['manifest_url']
#if 'NO_ADS' not in sky.account['account_type'] and slug:
if addon.getSettingBool('ads') and slug:
if 'NO_ADS' not in sky.account['account_type'] and slug:
#if addon.getSettingBool('ads') and slug:
try:
new_url = sky.get_manifest_with_ads(data)
if new_url:
Expand Down
5 changes: 5 additions & 0 deletions resources/lib/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ def do_GET(self):
pattern = r'(mimeType="text/vtt".*?)presentationTimeOffset="\d+"'
content = re.sub(pattern, r'\1', content, flags=re.DOTALL)

if addon.getSetting('platform_id') == 'PeacockTV': # and addon.getSettingBool('ads'):
# Due to Kodi bugs, ads are moved to the beginning of the video
from .mpd import move_unprotected_periods
content = move_unprotected_periods(content)

#LOG('content: {}'.format(content))
self.send_response(200)
self.send_header('Content-type', 'application/xml')
Expand Down
2 changes: 1 addition & 1 deletion resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<setting id="hdr10" type="bool" label="HDR10" default="false" visible="eq(-2,true)" subsetting="true"/>
<setting id="hdcp_enabled" type="bool" label="30037" default="false"/>
<setting id="only_subscribed" type="bool" label="30017" default="false"/>
<setting id="ads" type="bool" label="Commercial breaks" default="false"/>
<!-- <setting id="ads" type="bool" label="Commercial breaks" default="false"/> -->
<setting label="30019" type="action" id="is_settings" action="Addon.OpenSettings(inputstream.adaptive)" enable="System.HasAddon(inputstream.adaptive)" option="close"/>
<!--
<setting type="sep"/>
Expand Down

0 comments on commit f138e27

Please sign in to comment.