Skip to content

Commit 0c6cf54

Browse files
committed
plugins.pluzz: fix video ID schemas
1 parent 362654d commit 0c6cf54

File tree

1 file changed

+50
-54
lines changed

1 file changed

+50
-54
lines changed

src/streamlink/plugins/pluzz.py

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import re
1212
from urllib.parse import urlparse
1313

14-
from streamlink.plugin import Plugin, PluginError, pluginmatcher
14+
from streamlink.plugin import Plugin, pluginmatcher
1515
from streamlink.plugin.api import useragents, validate
1616
from streamlink.stream.dash import DASHStream
1717
from streamlink.stream.hls import HLSStream
@@ -31,18 +31,63 @@
3131
)
3232
class Pluzz(Plugin):
3333
PLAYER_VERSION = "5.51.35"
34-
GEO_URL = "https://geoftv-a.akamaihd.net/ws/edgescape.json"
35-
API_URL = "https://k7.ftven.fr/videos/{video_id}"
34+
35+
_URL_GEO = "https://geoftv-a.akamaihd.net/ws/edgescape.json"
36+
_URL_API = "https://k7.ftven.fr/videos/{video_id}"
37+
38+
_SCHEMA_VIDEOID_FRANCETV = validate.Schema(
39+
validate.regex(
40+
re.compile(r"""\\"options\\":\{\\"id\\":\\"(?P<video_id>[\dA-Fa-f-]{36})\\","""),
41+
method="search",
42+
),
43+
validate.get("video_id"),
44+
)
45+
_SCHEMA_VIDEOID_FRANCETVINFOFR = validate.Schema(
46+
validate.parse_html(),
47+
validate.any(
48+
# overseas live stream
49+
validate.all(
50+
validate.xml_xpath_string(""".//script[contains(text(),'"data":{content:{player:{id:"')][1]/text()"""),
51+
str,
52+
validate.regex(
53+
re.compile(r""""data":\{content:\{player:\{id:"(?P<video_id>[\dA-Fa-f-]{36})","""),
54+
method="search",
55+
),
56+
validate.get("video_id"),
57+
),
58+
# news article
59+
validate.all(
60+
validate.xml_xpath_string(".//*[@id][contains(@class,'francetv-player-wrapper')][1]/@id"),
61+
str,
62+
),
63+
# videos
64+
validate.all(
65+
validate.xml_xpath_string(".//*[@data-id][contains(@class,'magneto')][1]/@data-id"),
66+
str,
67+
),
68+
validate.transform(lambda *_: None),
69+
),
70+
)
71+
72+
def _get_video_id(self):
73+
return self.session.http.get(
74+
self.url,
75+
schema=self._SCHEMA_VIDEOID_FRANCETV if self.matches["francetv"] else self._SCHEMA_VIDEOID_FRANCETVINFOFR,
76+
)
3677

3778
def _get_streams(self):
3879
self.session.http.headers.update({
3980
"User-Agent": useragents.CHROME,
4081
})
4182
CHROME_VERSION = re.compile(r"Chrome/(\d+)").search(useragents.CHROME).group(1)
4283

84+
if not (video_id := self._get_video_id()):
85+
return
86+
log.debug(f"Video ID: {video_id}")
87+
4388
# Retrieve geolocation data
4489
country_code = self.session.http.get(
45-
self.GEO_URL,
90+
self._URL_GEO,
4691
schema=validate.Schema(
4792
validate.parse_json(),
4893
{
@@ -57,57 +102,8 @@ def _get_streams(self):
57102
)
58103
log.debug(f"Country: {country_code}")
59104

60-
# Retrieve URL page and search for video ID
61-
video_id = None
62-
try:
63-
video_id = self.session.http.get(
64-
self.url,
65-
schema=validate.Schema(
66-
validate.parse_html(),
67-
validate.any(
68-
# default francetv player
69-
validate.all(
70-
validate.xml_xpath_string(".//script[contains(text(),'window.FTVPlayerVideos')][1]/text()"),
71-
str,
72-
validate.regex(
73-
re.compile(
74-
r"window\.FTVPlayerVideos\s*=\s*(?P<json>\[{.+?}])\s*;\s*(?:$|var)",
75-
re.DOTALL,
76-
),
77-
),
78-
validate.get("json"),
79-
validate.parse_json(),
80-
[{"videoId": str}],
81-
validate.get((0, "videoId")),
82-
),
83-
# francetvinfo.fr overseas live stream
84-
validate.all(
85-
validate.xml_xpath_string(".//script[contains(text(),'magneto:{videoId:')][1]/text()"),
86-
str,
87-
validate.regex(re.compile(r"""magneto:\{videoId:(?P<q>['"])(?P<video_id>.+?)(?P=q)""")),
88-
validate.get("video_id"),
89-
),
90-
# francetvinfo.fr news article
91-
validate.all(
92-
validate.xml_xpath_string(".//*[@id][contains(@class,'francetv-player-wrapper')][1]/@id"),
93-
str,
94-
),
95-
# francetvinfo.fr videos
96-
validate.all(
97-
validate.xml_xpath_string(".//*[@data-id][contains(@class,'magneto')][1]/@data-id"),
98-
str,
99-
),
100-
),
101-
),
102-
)
103-
except PluginError:
104-
pass
105-
if not video_id:
106-
return
107-
log.debug(f"Video ID: {video_id}")
108-
109105
video_format, token_url, url, self.title = self.session.http.get(
110-
self.API_URL.format(video_id=video_id),
106+
self._URL_API.format(video_id=video_id),
111107
params={
112108
"country_code": country_code,
113109
"w": 1920,

0 commit comments

Comments
 (0)