Skip to content

Commit

Permalink
Merge pull request #2143 from glensc/l.plex.tv-link
Browse files Browse the repository at this point in the history
Feature: Add l.plex.tv and watch.plex.tv url support to inspect
  • Loading branch information
glensc authored Jan 8, 2025
2 parents f838a1c + 73ff8b0 commit 32c036f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions plextraktsync/plex/PlexIdFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def create(cls, key: str | int):
return PlexId(int(key))
elif key.startswith("https://trakt.tv/"):
return cls.from_trakt_url(key)
elif key.startswith("https://l.plex.tv/"):
return cls.from_plex_redirect_url(key)
elif key.startswith("https://watch.plex.tv/"):
return cls.from_plex_watch_url(key)
elif key.startswith("https:") or key.startswith("http:"):
return cls.from_url(key)
elif key.startswith("plex://"):
Expand Down Expand Up @@ -88,3 +92,36 @@ def from_trakt_url(cls, url: str):
pm = results[0]

return PlexId(pm.key, server=pm.plex.server.machineIdentifier)

@classmethod
def from_plex_watch_url(cls, url: str):
"""
Extracts id from urls like:
https://watch.plex.tv/movie/heavier-trip
"""

query = parse_qs(urlparse(url).query)
if "utm_content" not in query:
raise RuntimeError(f"Required 'utm_content' query missing from url: {url}")

plex_id = ",".join(query["utm_content"])
key = f"/library/metadata/{plex_id}"
location = f"https://app.plex.tv/desktop/#!/provider/tv.plex.provider.discover/details?key={key}"

return cls.create(location)

@classmethod
def from_plex_redirect_url(cls, url: str):
"""
Extracts id from urls like:
https://l.plex.tv/Nd7JNtC
"""
from plextraktsync.factory import factory

session = factory.session
response = session.head(url)
location = session.get_redirect_target(response)
if location is None:
raise RuntimeError(f"Failed to find redirect from url: {url}")

return cls.create(location)

0 comments on commit 32c036f

Please sign in to comment.