Skip to content

Commit

Permalink
playback fix for playing from playlist
Browse files Browse the repository at this point in the history
* fetch stream id from __links__ property which should be in users desired language already
* change exception log level to error
  • Loading branch information
smirgol committed Dec 18, 2023
1 parent 91dd5b2 commit 6ea691a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
21 changes: 19 additions & 2 deletions resources/lib/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from .api import API
from . import view
from . import utils

import json

Expand Down Expand Up @@ -70,6 +71,14 @@ def showQueue(args, api: API):

meta = item["panel"]["episode_metadata"]

stream_id = utils.get_stream_id_from_url(item["panel"]["__links__"]["streams"]["href"])
if stream_id is None:
xbmc.log(
"[PLUGIN] Crunchyroll | Error : failed to fetch stream_id for %s" % (meta["series_title"]),
xbmc.LOGINFO
)
continue

view.add_item(
args,
{
Expand All @@ -94,7 +103,7 @@ def showQueue(args, api: API):
"fanart": item["panel"]["images"]["thumbnail"][-1][-1]["source"],
"mode": "videoplay",
# note that for fetching streams we need a special guid, not the episode_id
"stream_id": meta["versions"][0]["media_guid"] # @todo that points to jp-JP for me, maybe too static
"stream_id": stream_id
},
is_folder=False
)
Expand Down Expand Up @@ -432,6 +441,14 @@ def viewEpisodes(args, api: API):

# display media
for item in req["items"]:
stream_id = utils.get_stream_id_from_url(item["__links__"]["streams"]["href"])
if stream_id is None:
xbmc.log(
"[PLUGIN] Crunchyroll | Error : failed to fetch stream_id for %s" % (item["series_title"]),
xbmc.LOGINFO
)
continue

# add to view
view.add_item(
args,
Expand All @@ -453,7 +470,7 @@ def viewEpisodes(args, api: API):
"fanart": args.fanart,
"mode": "videoplay",
# note that for fetching streams we need a special guid, not the episode_id
"stream_id": item["versions"][0]["media_guid"] # @todo that points to jp-JP for me, maybe too static
"stream_id": stream_id
},
is_folder=False
)
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def __init__(self, data: dict):


class CrunchyrollError(Exception):
xbmc.log("[PLUGIN] Crunchyroll: CrunchyrollError : %s" % (str(Exception)), xbmc.LOGINFO)
xbmc.log("[PLUGIN] Crunchyroll: CrunchyrollError : %s" % (str(Exception)), xbmc.LOGERROR)
pass


class LoginError(CrunchyrollError):
xbmc.log("[PLUGIN] Crunchyroll: LoginError : %s" % (str(CrunchyrollError)), xbmc.LOGINFO)
xbmc.log("[PLUGIN] Crunchyroll: LoginError : %s" % (str(CrunchyrollError)), xbmc.LOGERROR)
pass
8 changes: 8 additions & 0 deletions resources/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from requests import Response
import re

try:
from urlparse import parse_qs
Expand Down Expand Up @@ -77,3 +78,10 @@ def get_json_from_response(r: Response) -> Optional[Dict]:
if code != 200:
raise CrunchyrollError(f"[{code}] {r.text}")
return r_json


def get_stream_id_from_url(url: str):
stream_id = re.search('/videos/([^/]+)/streams', url)
if stream_id is None:
return None
return stream_id[1]

0 comments on commit 6ea691a

Please sign in to comment.