Skip to content

Commit

Permalink
[PATCH] plugins.cbsnews: fix regex, add metadata(streamlink#4743)
Browse files Browse the repository at this point in the history
  • Loading branch information
Billy2011 committed Aug 18, 2022
1 parent fe15f54 commit dec1499
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
36 changes: 18 additions & 18 deletions src/streamlink/plugins/cbsnews.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
$description 24-hour live streaming world news channel, based in the United States of America.
$description 24-hour live-streaming world news channel, based in the United States of America.
$url cbsnews.com
$type live
"""
Expand All @@ -12,33 +12,33 @@


@pluginmatcher(re.compile(
r"https?://www\.cbsnews\.com/live/"
r"https?://(?:www\.)?cbsnews\.com/(?:\w+/)?live/?"
))
class CBSNews(Plugin):
def _get_streams(self):
items = self.session.http.get(self.url, schema=validate.Schema(
re.compile(r"CBSNEWS.defaultPayload = (\{.*)"),
data = self.session.http.get(self.url, schema=validate.Schema(
re.compile(r"CBSNEWS\.defaultPayload\s*=\s*(\{.*?})\s*\n"),
validate.none_or_all(
validate.get(1),
validate.parse_json(),
{
"items": [
validate.all(
{
"video": validate.url(),
"format": "application/x-mpegURL",
},
validate.get("video"),
),
],
"items": [{
"id": validate.text,
"canonicalTitle": validate.text,
"video": validate.url(),
"format": "application/x-mpegURL",
}],
},
validate.get("items"),
validate.get(("items", 0)),
validate.union_get("id", "canonicalTitle", "video"),
),
))
if items:
for hls_url in items:
for s in HLSStream.parse_variant_playlist(self.session, hls_url).items():
yield s
if not data:
return

self.id, self.title, hls_url = data

return HLSStream.parse_variant_playlist(self.session, hls_url)


__plugin__ = CBSNews
13 changes: 11 additions & 2 deletions tests/plugins/test_cbsnews.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ class TestPluginCanHandleUrlCBSNews(PluginCanHandleUrl):
__plugin__ = CBSNews

should_match = [
"https://www.cbsnews.com/live/cbs-sports-hq/",
"https://www.cbsnews.com/live/cbsn-local-bay-area/",
"https://cbsnews.com/live",
"https://cbsnews.com/live/cbs-sports-hq",
"https://cbsnews.com/sanfrancisco/live",
"https://cbsnews.com/live/",
"https://cbsnews.com/live/cbs-sports-hq/",
"https://cbsnews.com/sanfrancisco/live/",
"https://www.cbsnews.com/live/",
"https://www.cbsnews.com/live/cbs-sports-hq/",
"https://www.cbsnews.com/sanfrancisco/live/",
"https://www.cbsnews.com/live/#x",
"https://www.cbsnews.com/live/cbs-sports-hq/#x",
"https://www.cbsnews.com/sanfrancisco/live/#x",
]

should_not_match = [
Expand Down

0 comments on commit dec1499

Please sign in to comment.