-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1514 from melmorabity/idf1
Add support for IDF1
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
import re | ||
|
||
from streamlink.plugin import Plugin | ||
from streamlink.plugin.api import http, useragents, validate | ||
from streamlink.stream import HLSStream | ||
from streamlink.utils import parse_json, update_scheme | ||
|
||
|
||
class IDF1(Plugin): | ||
DACAST_API_URL = 'https://json.dacast.com/b/{}/{}/{}' | ||
DACAST_TOKEN_URL = 'https://services.dacast.com/token/i/b/{}/{}/{}' | ||
|
||
_url_re = re.compile(r'http://www\.idf1\.fr/(videos/[^/]+/[^/]+\.html|live\b)') | ||
_video_id_re = re.compile(r"dacast\('(?P<broadcaster_id>\d+)_(?P<video_type>[a-z]+)_(?P<video_id>\d+)', 'replay_content', data\);") | ||
_video_id_alt_re = re.compile(r'<script src="//player.dacast.com/js/player.js" id="(?P<broadcaster_id>\d+)_(?P<video_type>[cf])_(?P<video_id>\d+)"') | ||
_player_url = 'http://ssl.p.jwpcdn.com/player/v/7.12.6/jwplayer.flash.swf' | ||
|
||
_api_schema = validate.Schema( | ||
validate.transform(parse_json), | ||
{ | ||
validate.optional('html5'): validate.all( | ||
[ | ||
{ | ||
'src': validate.url() | ||
}, | ||
], | ||
), | ||
'hls': validate.url(), | ||
'hds': validate.url() | ||
}, | ||
validate.transform(lambda x: [update_scheme(IDF1.DACAST_API_URL, x['hls']), x['hds']] + [y['src'] for y in x.get('html5', [])]) | ||
) | ||
|
||
_token_schema = validate.Schema( | ||
validate.transform(parse_json), | ||
{'token': validate.text}, | ||
validate.get('token') | ||
) | ||
|
||
_user_agent = useragents.IE_11 | ||
|
||
@classmethod | ||
def can_handle_url(cls, url): | ||
return IDF1._url_re.match(url) | ||
|
||
def _get_streams(self): | ||
res = http.get(self.url) | ||
match = self._video_id_re.search(res.text) or self._video_id_alt_re.search(res.text) | ||
if match is None: | ||
return | ||
broadcaster_id = match.group('broadcaster_id') | ||
video_type = match.group('video_type') | ||
video_id = match.group('video_id') | ||
|
||
videos = http.get(self.DACAST_API_URL.format(broadcaster_id, video_type, video_id), schema=self._api_schema) | ||
token = http.get(self.DACAST_TOKEN_URL.format(broadcaster_id, video_type, video_id), schema=self._token_schema) | ||
parsed = [] | ||
|
||
for video_url in videos: | ||
video_url += token | ||
|
||
# Ignore duplicate video URLs | ||
if video_url in parsed: | ||
continue | ||
parsed.append(video_url) | ||
|
||
# Ignore HDS streams (broken) | ||
if '.m3u8' in video_url: | ||
for s in HLSStream.parse_variant_playlist(self.session, video_url).items(): | ||
yield s | ||
|
||
__plugin__ = IDF1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import unittest | ||
|
||
from streamlink.plugins.idf1 import IDF1 | ||
|
||
|
||
class TestPluginIDF1(unittest.TestCase): | ||
def test_can_handle_url(self): | ||
# should match | ||
self.assertTrue(IDF1.can_handle_url("http://www.idf1.fr/live")) | ||
self.assertTrue(IDF1.can_handle_url("http://www.idf1.fr/videos/jlpp/best-of-2018-02-24-partie-2.html")) | ||
self.assertTrue(IDF1.can_handle_url("http://www.idf1.fr/videos/buzz-de-noel/partie-2.html")) | ||
|
||
# shouldn't match | ||
self.assertFalse(IDF1.can_handle_url("http://www.idf1.fr/")) | ||
self.assertFalse(IDF1.can_handle_url("http://www.idf1.fr/videos")) | ||
self.assertFalse(IDF1.can_handle_url("http://www.idf1.fr/programmes/emissions/idf1-chez-vous.html")) | ||
self.assertFalse(IDF1.can_handle_url("http://www.tvcatchup.com/")) | ||
self.assertFalse(IDF1.can_handle_url("http://www.youtube.com/")) |