11
11
import re
12
12
from urllib .parse import urlparse
13
13
14
- from streamlink .plugin import Plugin , PluginError , pluginmatcher
14
+ from streamlink .plugin import Plugin , pluginmatcher
15
15
from streamlink .plugin .api import useragents , validate
16
16
from streamlink .stream .dash import DASHStream
17
17
from streamlink .stream .hls import HLSStream
31
31
)
32
32
class Pluzz (Plugin ):
33
33
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
+ )
36
77
37
78
def _get_streams (self ):
38
79
self .session .http .headers .update ({
39
80
"User-Agent" : useragents .CHROME ,
40
81
})
41
82
CHROME_VERSION = re .compile (r"Chrome/(\d+)" ).search (useragents .CHROME ).group (1 )
42
83
84
+ if not (video_id := self ._get_video_id ()):
85
+ return
86
+ log .debug (f"Video ID: { video_id } " )
87
+
43
88
# Retrieve geolocation data
44
89
country_code = self .session .http .get (
45
- self .GEO_URL ,
90
+ self ._URL_GEO ,
46
91
schema = validate .Schema (
47
92
validate .parse_json (),
48
93
{
@@ -57,57 +102,8 @@ def _get_streams(self):
57
102
)
58
103
log .debug (f"Country: { country_code } " )
59
104
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
-
109
105
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 ),
111
107
params = {
112
108
"country_code" : country_code ,
113
109
"w" : 1920 ,
0 commit comments