mirror of
https://github.com/vinefeeder/TwinVine.git
synced 2026-07-15 18:10:04 +02:00
Plex/other updates
This commit is contained in:
@@ -36,7 +36,7 @@ except ImportError:
|
|||||||
from envied.core.titles import Episode, Movie, Movies, Series
|
from envied.core.titles import Episode, Movie, Movies, Series
|
||||||
from envied.core.tracks import Chapter, Chapters, Tracks
|
from envied.core.tracks import Chapter, Chapters, Tracks
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError("PLEX service requires devine or unshackle to be installed")
|
raise ImportError("PLEX service requires devine, envied or unshackle to be installed")
|
||||||
|
|
||||||
from requests import Request
|
from requests import Request
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import json
|
|||||||
import httpx
|
import httpx
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
|
|
||||||
@@ -442,6 +443,13 @@ class BaseLoader:
|
|||||||
# direct download
|
# direct download
|
||||||
self.receive(1, url)
|
self.receive(1, url)
|
||||||
return
|
return
|
||||||
|
if category.lower() in [
|
||||||
|
"show",
|
||||||
|
]:
|
||||||
|
search = url.split('show/')[1]
|
||||||
|
search = search.split('/')[0].split('?')[0].replace('-', ' ').replace('.','') # tricky fullstop
|
||||||
|
|
||||||
|
self.receive(3, search)
|
||||||
|
|
||||||
if "https" not in url: # browse entry
|
if "https" not in url: # browse entry
|
||||||
self.receive(3, url)
|
self.receive(3, url)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import re
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
@@ -19,8 +20,8 @@ class PlexLoader(BaseLoader):
|
|||||||
headers = {
|
headers = {
|
||||||
"Accept": "*/*",
|
"Accept": "*/*",
|
||||||
"user-agent": "Dalvik/2.9.8 (Linux; U; Android 9.9.2; ALE-L94 Build/NJHGGF)",
|
"user-agent": "Dalvik/2.9.8 (Linux; U; Android 9.9.2; ALE-L94 Build/NJHGGF)",
|
||||||
"Origin": "https://www.itv.com",
|
"Origin": "https://plex.tv",
|
||||||
"Referer": "https://www.itv.com/",
|
"Referer": "https://plex.tv/",
|
||||||
}
|
}
|
||||||
super().__init__(headers)
|
super().__init__(headers)
|
||||||
|
|
||||||
@@ -264,3 +265,91 @@ class PlexLoader(BaseLoader):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def fetch_videos_by_category(self, browse_url):
|
||||||
|
"""
|
||||||
|
Fetches videos from a category Plex
|
||||||
|
Args:
|
||||||
|
browse_url (str): URL of the category page.
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
|
"""
|
||||||
|
category = browse_url.split('/')[-1]
|
||||||
|
browse_url = f"https://luma.plex.tv/api/screen/on-demand/category/{category}"
|
||||||
|
beaupylist = [] # hold beaupy data for display and programme selection
|
||||||
|
headers = {
|
||||||
|
"Accept": "application/json",
|
||||||
|
"X-Plex-Product": "Plex Mediaverse",
|
||||||
|
"X-Plex-Version": "1.0",
|
||||||
|
"X-Plex-Client-Identifier": str(uuid.uuid4()),
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
myjson = self.parse_data(self.get_data(browse_url))
|
||||||
|
res = jmespath.search(
|
||||||
|
"""
|
||||||
|
ui.list.content[].{
|
||||||
|
label: label,
|
||||||
|
link: link.url,
|
||||||
|
duration: link.previewData.facts[1].accessibilityLabel,
|
||||||
|
pay: link.external
|
||||||
|
}
|
||||||
|
""",
|
||||||
|
myjson,
|
||||||
|
)
|
||||||
|
|
||||||
|
for item in res:
|
||||||
|
title = item["label"]
|
||||||
|
duration= item["duration"]
|
||||||
|
url = f"https://watch.plex.tv{item.get("link")}"
|
||||||
|
|
||||||
|
episode = {
|
||||||
|
"title": title,
|
||||||
|
"url": url,
|
||||||
|
"synopsis": duration,
|
||||||
|
}
|
||||||
|
self.add_episode(title, episode)
|
||||||
|
|
||||||
|
|
||||||
|
# Build the beaupylist for display
|
||||||
|
for i, item in enumerate(res):
|
||||||
|
title = (item["label"].replace("-", " ")).title()
|
||||||
|
url = f"https://watch.plex.tv{item["link"]}"
|
||||||
|
synopsis = item["duration"]
|
||||||
|
beaupylist.append(
|
||||||
|
f"{i} {title.replace('_',' ')}\n\t{synopsis}"
|
||||||
|
) # \t used to split text later
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error fetching category data: {e}")
|
||||||
|
return
|
||||||
|
|
||||||
|
# super
|
||||||
|
found = self.display_beaupylist(beaupylist)
|
||||||
|
|
||||||
|
if found:
|
||||||
|
ind = found.split(" ")[0]
|
||||||
|
url = f"https://watch.plex.tv{res[int(ind)]["link"]}"
|
||||||
|
# url may be for series or single Film
|
||||||
|
url = url.encode("utf-8", "ignore").decode().strip() # has spaces!
|
||||||
|
# process short-cut download or do greedy search on url
|
||||||
|
if 'movie' in url:
|
||||||
|
self.options_list = split_options(self.options)
|
||||||
|
try:
|
||||||
|
if self.options_list[0] == "":
|
||||||
|
command = ['uv', 'run', 'envied', "dl", "PLEX", url]
|
||||||
|
else:
|
||||||
|
command = ['uv', 'run', 'envied', "dl", *self.options_list, "PLEX", url]
|
||||||
|
self.runsubprocess(command)
|
||||||
|
except Exception as e:
|
||||||
|
print(
|
||||||
|
"Error downloading video:",
|
||||||
|
e,
|
||||||
|
"Is the package for vinefeeder/envied installed correctly ?",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
category = "show"
|
||||||
|
return self.process_received_url_from_category(url, category=category)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("No video selected.")
|
||||||
|
return
|
||||||
Reference in New Issue
Block a user