Skip to content

Commit

Permalink
streaming - added a option to allow the user to set a maximum resilut…
Browse files Browse the repository at this point in the history
…ion to make use of stash's transcoding for low power devices like some google TVs. Due to the encoding delays on consumer hardware inputstream support has also been added to use the DASH streams from stash
  • Loading branch information
miawgogo authored and gitgiggety committed Jan 27, 2024
1 parent 1aa964b commit 74c77a7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
13 changes: 13 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,16 @@ msgstr ""
msgctxt "#30012"
msgid "Scene Tags"
msgstr ""


msgctxt "#30013"
msgid "Server Settings"
msgstr ""

msgctxt "#30014"
msgid "Playback Settings"
msgstr ""

msgctxt "#30015"
msgid "Max Resolution"
msgstr ""
46 changes: 45 additions & 1 deletion resources/lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,33 @@
api_key: str = ''
client: Optional[StashInterface] = None

res_map = {
"Original": "",
"4k": "FOUR_K",
"1440p": "QUAD_HD",
"FHD": "FULL_HD",
"720p": "STANDARD_HD",
"SD": "STANDARD",
"240p": "LOW",
}

res_height_map = {
"4k": 1920,
"1440p": 1440,
"FHD": 1080,
"720p": 720,
"SD": 480,
"240p": 240,
}


def run():
global api_key
global client
global playback_res
api_key = _ADDON.getSetting('api_key')
client = StashInterface(_ADDON.getSetting('base_url'), api_key)
playback_res = res_map.get(_ADDON.getSetting('res'), "")
router(sys.argv[2][1:])


Expand Down Expand Up @@ -80,9 +101,32 @@ def browse_for(params: dict):
navigation.list_items()


def get_mp4_stream(sceneStreams: dict) -> str:
for stream in sceneStreams:
if stream["label"] == "DASH":
return stream


def play(params: dict):
scene = client.find_scene(params['play'])
item = xbmcgui.ListItem(path=scene['paths']['stream'])
item = xbmcgui.ListItem()
if playback_res != "" and scene["files"][0]["height"] > res_height_map[_ADDON.getSetting('res')]:
stream = get_mp4_stream(scene["sceneStreams"])
url = stream["url"].replace("ORIGINAL", playback_res)
item.setMimeType('application/xml+dash')
item.setContentLookup(False)

item.setProperty('inputstream', 'inputstream.adaptive')
item.setProperty('inputstream.adaptive.manifest_type', 'mpd')
item.setProperty('inputstream.adaptive.stream_headers',
f'apikey={api_key}')
item.setProperty('inputstream.adaptive.manifest_headers',
f'apikey={api_key}')
item.setPath(url)
else:
streamurl = scene['paths']['stream']
item.setPath(streamurl)

xbmcplugin.setResolvedUrl(_HANDLE, True, listitem=item)


Expand Down
6 changes: 6 additions & 0 deletions resources/lib/stash_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def find_scene(self, id):
rating100
date
created_at
sceneStreams {
url
mime_type
label
__typename
}
paths {
stream
screenshot
Expand Down
6 changes: 5 additions & 1 deletion resources/settings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
<category>
<category label="30013">
<setting label="30000" type="text" id="base_url" default="http://localhost:9999/"/>
<setting label="30001" type="text" id="api_key" option="hidden" default=""/>
</category>
<category label="30014">
<setting id="res" type="select" label="30015" values="Original|4k|FHD|720p|SD" default="Original"/>
</category>

</settings>

0 comments on commit 74c77a7

Please sign in to comment.