Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Upnext addon integration #45

Open
wants to merge 7 commits into
base: nexus-staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions resources/language/resource.language.de_de/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ msgctxt "#30230"
msgid "Other"
msgstr "Sonstiges"

msgctxt "#30240"
msgid "Addons"
msgstr "Erweiterungen"

msgctxt "#30101"
msgid "Email"
msgstr "E-Mail"
Expand Down Expand Up @@ -267,3 +271,27 @@ msgstr "Profil auswählen"
msgctxt "#30080"
msgid "There are too many active streams. Please try again later."
msgstr "Es sind zu viele Streams aktiv. Bitte probiere es später noch einmal."

msgctxt "#30089"
msgid "UpNext fixed or unavailable end detection duration"
msgstr "Vorlaufzeit für UpNext wenn \"Statisch\" oder keine Credits/Vorschau"

msgctxt "#30090"
msgid "UpNext integration"
msgstr "UpNext Integration"

msgctxt "#30091"
msgid "At credits start, if nothing after"
msgstr "Zu Beginn der Credits, wenn danach keine Vorschau kommt"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to refine this, I wasn't sure what the english text was trying to tell me. :D

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I wrote in a previous comment, I change it to something more understandable.

In fact, it may be named like that (because, this is what it does):

"Show UpNext dialog at":

  • "credits start"
  • "preview start"
  • "fixed time before the end"
  • "never (disabled)"


msgctxt "#30092"
msgid "At preview start"
msgstr "Zu Beginn der Vorschau"

msgctxt "#30093"
msgid "Fixed"
msgstr "Statisch"

msgctxt "#30094"
msgid "Disabled"
msgstr "Deaktiviert"
28 changes: 28 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ msgctxt "#30230"
msgid "Other"
msgstr ""

msgctxt "#30240"
msgid "Addons"
msgstr ""

msgctxt "#30001"
msgid "Email"
msgstr ""
Expand Down Expand Up @@ -269,3 +273,27 @@ msgstr ""
msgctxt "#30080"
msgid "There are too many active streams. Please try again later."
msgstr ""

msgctxt "#30089"
msgid "UpNext fixed or unavailable end detection duration"
msgstr ""

msgctxt "#30090"
msgid "UpNext integration"
msgstr ""

msgctxt "#30091"
msgid "At credits start, if nothing after"
msgstr ""

msgctxt "#30092"
msgid "At preview start"
msgstr ""

msgctxt "#30093"
msgid "Fixed"
msgstr ""

msgctxt "#30094"
msgid "Disabled"
msgstr ""
28 changes: 28 additions & 0 deletions resources/language/resource.language.es_es/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ msgctxt "#30230"
msgid "Other"
msgstr "Otro"

msgctxt "#30240"
msgid "Addons"
msgstr ""

msgctxt "#30001"
msgid "Email"
msgstr "Email"
Expand Down Expand Up @@ -269,3 +273,27 @@ msgstr ""
msgctxt "#30080"
msgid "There are too many active streams. Please try again later."
msgstr ""

msgctxt "#30089"
msgid "UpNext fixed or unavailable end detection duration"
msgstr ""

msgctxt "#30090"
msgid "UpNext integration"
msgstr ""

msgctxt "#30091"
msgid "At credits start, if nothing after"
msgstr ""

msgctxt "#30092"
msgid "At preview start"
msgstr ""

msgctxt "#30093"
msgid "Fixed"
msgstr ""

msgctxt "#30094"
msgid "Disabled"
msgstr ""
30 changes: 29 additions & 1 deletion resources/language/resource.language.pt_br/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ msgctxt "#30230"
msgid "Other"
msgstr "Outros"

msgctxt "#30240"
msgid "Addons"
msgstr ""

msgctxt "#30001"
msgid "Username"
msgstr "E-mail"
Expand Down Expand Up @@ -265,4 +269,28 @@ msgstr ""

msgctxt "#30080"
msgid "There are too many active streams. Please try again later."
msgstr "Muitas streams ativas. Por favor, tente mais tarde"
msgstr "Muitas streams ativas. Por favor, tente mais tarde"

msgctxt "#30089"
msgid "UpNext fixed or unavailable end detection duration"
msgstr ""

msgctxt "#30090"
msgid "UpNext integration"
msgstr ""

msgctxt "#30091"
msgid "At credits start, if nothing after"
msgstr ""

msgctxt "#30092"
msgid "At preview start"
msgstr ""

msgctxt "#30093"
msgid "Fixed"
msgstr ""

msgctxt "#30094"
msgid "Disabled"
msgstr ""
23 changes: 17 additions & 6 deletions resources/lib/addons/upnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,39 @@

from base64 import b64encode
from json import dumps
from typing import Optional

from resources.lib.model import Args, PlayableItem, SeriesData

from . import utils

def send_next_info(args: Args, current_episode: PlayableItem, next_episode: PlayableItem, play_url: str, notification_offset: int | None = None, series: SeriesData | None = None):

def send_next_info(
args: Args,
current_episode: PlayableItem,
next_episode: PlayableItem,
play_url: str,
notification_offset: Optional[int] = None,
series: Optional[SeriesData] = None
):
"""
Notify next episode info to upnext.
See https://github.com/im85288/service.upnext/wiki/Integration#sending-data-to-up-next for implementation details.
"""
current = UpnextEpisode(current_episode, series)
next = UpnextEpisode(next_episode, series)
current_upnext_episode = UpnextEpisode(current_episode, series)
next_upnext_episode = UpnextEpisode(next_episode, series)
next_info = {
"current_episode": current.__dict__,
"next_episode": next.__dict__,
"current_episode": current_upnext_episode.__dict__,
"next_episode": next_upnext_episode.__dict__,
"play_url": play_url,
}
if notification_offset is not None:
next_info["notification_offset"] = notification_offset
upnext_signal(args.addon_id, next_info)


class UpnextEpisode:
def __init__(self, dto: PlayableItem, series_dto: SeriesData | None):
def __init__(self, dto: PlayableItem, series_dto: Optional[SeriesData]):
self.episodeid: str | None = dto.episode_id
self.tvshowid: str | None = dto.series_id
self.title: str = dto.title_unformatted
Expand All @@ -62,6 +72,7 @@ def __init__(self, dto: PlayableItem, series_dto: SeriesData | None):
self.firstaired: str = dto.year
self.runtime: int = dto.duration


def upnext_signal(sender, next_info):
"""Send upnext_data to Kodi using JSON RPC"""
data = [utils.to_unicode(b64encode(dumps(next_info).encode()))]
Expand Down
21 changes: 17 additions & 4 deletions resources/lib/videoplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,23 @@ def _handle_upnext(self):
"video_episode_play"
)
show_next_at_seconds = self._compute_when_episode_ends()
# Needs to wait 1s, otherwise, upnext will show next dialog at episode start...
xbmc.sleep(1000)
utils.crunchy_log("_handle_upnext: Next URL (shown at %ds): %s" % (show_next_at_seconds, next_url))
upnext.send_next_info(G.args, self._stream_data.playable_item, next_episode, next_url, show_next_at_seconds, self._stream_data.playable_item_parent)
if show_next_at_seconds is not None:
# Needs to wait 1s, otherwise, upnext will show next dialog at episode start...
xbmc.sleep(1000)
utils.crunchy_log("_handle_upnext: Next URL (shown at %ds / %ds): %s" % (
show_next_at_seconds,
self._stream_data.playable_item.duration,
next_url
))

upnext.send_next_info(
G.args,
self._stream_data.playable_item,
next_episode,
next_url,
show_next_at_seconds,
self._stream_data.playable_item_parent
)
except Exception:
utils.crunchy_log("_handle_upnext: Cannot send upnext notification", xbmc.LOGERROR)

Expand Down