Skip to content

Commit

Permalink
plugins.euronews: rewrite and fix using XPath
Browse files Browse the repository at this point in the history
  • Loading branch information
bastimeyer committed Sep 1, 2021
1 parent a680242 commit b24f2f5
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/streamlink/plugins/euronews.py
Expand Up @@ -3,9 +3,8 @@

from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.plugin.api.utils import itertags
from streamlink.stream import HLSStream, HTTPStream
from streamlink.utils import parse_json, update_scheme
from streamlink.utils import update_scheme


@pluginmatcher(re.compile(
Expand All @@ -15,41 +14,39 @@ class Euronews(Plugin):
API_URL = "https://{subdomain}.euronews.com/api/watchlive.json"

def _get_vod_stream(self):
def find_video_url(content):
for elem in itertags(content, "meta"):
if elem.attributes.get("property") == "og:video":
return elem.attributes.get("content")

video_url = self.session.http.get(self.url, schema=validate.Schema(
validate.transform(find_video_url),
validate.any(None, validate.url())
root = self.session.http.get(self.url, schema=validate.Schema(
validate.parse_html()
))

if video_url is not None:
video_url = root.xpath("string(.//meta[@property='og:video'][1]/@content)")
if video_url:
return dict(vod=HTTPStream(self.session, video_url))

def _get_live_streams(self):
def find_video_id(content):
for elem in itertags(content, "div"):
if elem.attributes.get("id") == "pfpPlayer" and elem.attributes.get("data-google-src") is not None:
return elem.attributes.get("data-video-id")
video_id = root.xpath("string(.//div[@data-google-src]/@data-video-id)")
if video_id:
return self.session.streams(f"https://www.youtube.com/watch?v={video_id}")

video_url = root.xpath("string(.//iframe[@id='pfpPlayer'][starts-with(@src,'https://www.youtube.com/')][1]/@src)")
if video_url:
return self.session.streams(video_url)

def _get_live_streams(self):
video_id = self.session.http.get(self.url, schema=validate.Schema(
validate.transform(find_video_id),
validate.any(None, str)
validate.parse_html(),
validate.xml_xpath_string(".//div[@data-google-src]/@data-video-id")
))

if video_id is not None:
if video_id:
return self.session.streams(f"https://www.youtube.com/watch?v={video_id}")

info_url = self.session.http.get(self.API_URL.format(subdomain=self.match.group("subdomain")), schema=validate.Schema(
validate.transform(parse_json),
validate.parse_json(),
{"url": validate.url()},
validate.get("url"),
validate.transform(lambda url: update_scheme("https://", url))
))
hls_url = self.session.http.get(info_url, schema=validate.Schema(
validate.transform(parse_json),
validate.parse_json(),
{
"status": "ok",
"protocol": "hls",
Expand Down

0 comments on commit b24f2f5

Please sign in to comment.