Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins.vimeo: Fix unable to find configuration URL on some pages #5331

Merged
merged 8 commits into from May 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/streamlink/plugins/vimeo.py
Expand Up @@ -8,14 +8,16 @@
import logging
import re
from html import unescape as html_unescape
from urllib.parse import urlparse
from typing import Optional
from urllib.parse import urljoin, urlparse

from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream.dash import DASHStream
from streamlink.stream.ffmpegmux import MuxedStream
from streamlink.stream.hls import HLSStream
from streamlink.stream.http import HTTPStream
from streamlink.utils.url import update_scheme


log = logging.getLogger(__name__)
Expand All @@ -25,6 +27,8 @@
r"https?://(player\.vimeo\.com/video/\d+|(www\.)?vimeo\.com/.+)",
))
class Vimeo(Plugin):
VIEWER_URL = "https://vimeo.com/_next/viewer"
OEMBED_URL = "https://vimeo.com/api/oembed.json"
_config_url_re = re.compile(r'(?:"config_url"|\bdata-config-url)\s*[:=]\s*(".+?")')
_config_re = re.compile(r"playerConfig\s*=\s*({.+?})\s*var")
_config_url_schema = validate.Schema(
Expand Down Expand Up @@ -61,11 +65,45 @@ class Vimeo(Plugin):
validate.any(None, validate.Schema(validate.get(1), _config_schema)),
)

def get_config_url(self) -> Optional[str]:
viewer = self.session.http.get(
self.VIEWER_URL,
schema=validate.Schema(
validate.parse_json(),
{
"jwt": str,
"apiUrl": str,
},
),
)

uri = self.session.http.get(
self.OEMBED_URL,
params={"url": self.url},
schema=validate.Schema(
validate.parse_json(),
{
"uri": str,
},
),
)

return self.session.http.get(
urljoin(update_scheme("https://", viewer["apiUrl"]), uri["uri"]),
params={"fields": "config_url"},
headers={"Authorization": "jwt {}".format(viewer["jwt"])},
schema=self._config_url_schema,
)
skulblakka marked this conversation as resolved.
Show resolved Hide resolved

def _get_streams(self):
if "player.vimeo.com" in self.url:
data = self.session.http.get(self.url, schema=self._player_schema)
else:
api_url = self.session.http.get(self.url, schema=self._config_url_schema)

if not api_url:
api_url = self.get_config_url()

if not api_url:
return
data = self.session.http.get(api_url, schema=self._config_schema)
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/test_vimeo.py
Expand Up @@ -12,6 +12,7 @@ class TestPluginCanHandleUrlVimeo(PluginCanHandleUrl):
"https://vimeo.com/ondemand/surveyopenspace/92630739",
"https://vimeo.com/ondemand/100footsurfingdays",
"https://player.vimeo.com/video/176894130",
"https://vimeo.com/771745400/840d05200c",
]

should_not_match = [
Expand Down