Skip to content

Commit

Permalink
added inputstream setting and fix recache clean crash (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
TermeHansen authored Jun 1, 2022
1 parent 5f793bd commit 421bd65
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 19 deletions.
6 changes: 5 additions & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="plugin.video.drnu" version="5.1.1+matrix.1" name="DR TV" provider-name="TermeHansen">
<addon id="plugin.video.drnu" version="5.1.2+matrix.1" name="DR TV" provider-name="TermeHansen">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="2.25.1+matrix.1" />
Expand All @@ -26,6 +26,10 @@
<icon>resources/icon.png</icon>
<fanart>resources/fanart.jpg</fanart>
</assets>
<news>[B]Version 5.1.2 - 2022-06-01[/B]
- catch failure in recache cleanup
- add setting for inputstream api
</news>
<news>[B]Version 5.1.1 - 2022-04-20[/B]
- hot-fix to use hls inputstreams</news>
<news>[B]Version 5.1.0 - 2022-04-01[/B]
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[B]Version 5.1.2 - 2022-06-01[/B]
- catch failure in recache cleanup
- add setting for inputstream api

[B]Version 5.1.1 - 2022-04-20[/B]
- hot-fix to use hls inputstreams

Expand Down
4 changes: 4 additions & 0 deletions resources/language/resource.language.da_dk/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ msgctxt "#30520"
msgid "Fanart image resolution"
msgstr "Størrelse på fanart billeder"

msgctxt "#30521"
msgid "Inputstream type"
msgstr "Inputstream type"

msgctxt "#30900"
msgid "There was an error while communicating with DR NU."
msgstr "Der er sket en fejl i kommunikationen med DR NU."
Expand Down
4 changes: 4 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ msgctxt "#30520"
msgid "Fanart image resolution"
msgstr ""

msgctxt "#30521"
msgid "Inputstream type"
msgstr "Inputstream type"

msgctxt "#30900"
msgid "There was an error while communicating with DR NU."
msgstr ""
Expand Down
24 changes: 12 additions & 12 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def __init__(self, plugin_url, plugin_handle):
self.recentlyWatched = list()

self.menuItems = list()
runScript = "RunAddon(plugin.video.drnu,?show=areaselector&random={:d})".format(
self._plugin_handle)
runScript = "RunAddon(plugin.video.drnu,?show=areaselector)"
self.menuItems.append((tr(30511), runScript))

# Area Selector
Expand Down Expand Up @@ -381,11 +380,11 @@ def playVideo(self, slug):
video = self.api.getVideoUrl(api_item['PrimaryAsset']['Uri'])
item = xbmcgui.ListItem(path=video['Uri'], offscreen=True)
item.setArt({'thumb': api_item['PrimaryImageUri']})
is_helper = Helper('hls')
if is_helper.check_inputstream():
item.setProperty('inputstreamaddon', is_helper.inputstream_addon)
item.setProperty('inputstream', 'inputstream.adaptive')
item.setProperty('inputstream.adaptive.manifest_type', 'hls')
if get_setting('inputstream') == 'adaptive':
is_helper = Helper('hls')
if is_helper.check_inputstream():
item.setProperty('inputstream', is_helper.inputstream_addon)
item.setProperty('inputstream.adaptive.manifest_type', 'hls')

if not all([bool_setting('disable.kids.subtitles') and kids_channel]):
if video['SubtitlesUri']:
Expand Down Expand Up @@ -415,11 +414,12 @@ def playLiveTV(self, slug):
item = xbmcgui.ListItem(channel['Title'], path=url, offscreen=True)
item.setArt({'fanart': channel['PrimaryImageUri'],
'icon': channel['PrimaryImageUri']})
is_helper = Helper('hls')
if is_helper.check_inputstream():
item.setProperty('inputstreamaddon', is_helper.inputstream_addon)
item.setProperty('inputstream', 'inputstream.adaptive')
item.setProperty('inputstream.adaptive.manifest_type', 'hls')
if get_setting('inputstream') == 'adaptive':
is_helper = Helper('hls')
if is_helper.check_inputstream():
item.setProperty('inputstream', is_helper.inputstream_addon)
item.setProperty('inputstream.adaptive.manifest_type', 'hls')

item.addContextMenuItems(self.menuItems, False)
break
if item:
Expand Down
18 changes: 12 additions & 6 deletions resources/lib/tvapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ def __init__(self, cachePath, getLocalizedString):
self.tr = getLocalizedString

# cache expires after: 3600 = 1hour
requests_cache.install_cache(os.path.join(
self.session = requests_cache.CachedSession(os.path.join(
cachePath, 'requests.cache'), backend='sqlite', expire_after=3600*8)
requests_cache.remove_expired_responses()
try:
self.session.remove_expired_responses()
except Exception:
if Path(self.cachePath, 'requests.cache.sqlite').exists():
Path(self.cachePath, 'requests.cache.sqlite').unlink()
self.session = requests_cache.CachedSession(os.path.join(
self.cachePath, 'requests.cache'), backend='sqlite', expire_after=3600*8)
self.session.remove_expired_responses()
self.empty_srt = f'{self.cachePath}/{self.tr(30508)}.da.srt'

# we need to have something in the srt to make kodi use it
Expand Down Expand Up @@ -164,7 +171,7 @@ def getVideoUrl(self, assetUri):
else:
foreign = True
name = f'{self.cachePath}/{self.tr(30507)}.da.srt'
u = requests.get(sub['Uri'], timeout=10)
u = self.session.get(sub['Uri'], timeout=10)
if u.status_code != 200:
u.close()
break
Expand Down Expand Up @@ -203,10 +210,9 @@ def _http_request(self, url, params=None, cache=True):
url += '?' + urlparse.urlencode(params, doseq=True)

if not cache:
with requests_cache.disabled():
u = requests.get(url, timeout=30)
else:
u = requests.get(url, timeout=30)
else:
u = self.session.get(url, timeout=30)
if u.status_code == 200:
content = u.text
u.close()
Expand Down
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<setting id="enable.areaitem" label="30515" type="bool" default="false" />
<setting id="disable.kids" label="30505" type="bool" default="true" />
<setting id="disable.kids.subtitles" label="30509" type="bool" default="true" />
<setting id="inputstream" label="30521" type="labelenum" default="adaptive" values="adaptive|ffmpegdirect" />
<setting label="30504" type="action" action="RunScript($CWD/resources/lib/clearfavorites.py)" />
</category>
</settings>

0 comments on commit 421bd65

Please sign in to comment.