extract wat_id by parsing JSON
This commit is contained in:
parent
acda141738
commit
c381d37510
@ -3,6 +3,8 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
|
||||||
|
from ..utils import js_to_json
|
||||||
|
|
||||||
|
|
||||||
class TF1IE(InfoExtractor):
|
class TF1IE(InfoExtractor):
|
||||||
"""TF1 uses the wat.tv player."""
|
"""TF1 uses the wat.tv player."""
|
||||||
@ -61,15 +63,21 @@ class TF1IE(InfoExtractor):
|
|||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
slug = self._search_regex(
|
vids_data_string = self._html_search_regex(
|
||||||
r'(?<=/)(?P<slug>[^/]+)(?=\.html$)',
|
r'<script>\s*window.__APOLLO_STATE__\s*=\s*(?P<vids_data_string>.*?)\s*;*\s*</script>',
|
||||||
url, 'slug', group='slug', default='')
|
webpage, 'videos data string', group='vids_data_string', default=None)
|
||||||
|
wat_id = None
|
||||||
|
if vids_data_string is not None:
|
||||||
|
vids_data = self._parse_json(
|
||||||
|
vids_data_string, video_id,
|
||||||
|
transform_source=js_to_json)
|
||||||
|
video_data = [v for v in vids_data.values()
|
||||||
|
if 'slug' in v and v['slug'] == video_id]
|
||||||
|
if len(video_data) > 0 and 'streamId' in video_data[0]:
|
||||||
|
wat_id = video_data[0]['streamId']
|
||||||
|
if wat_id is None:
|
||||||
wat_id = self._html_search_regex(
|
wat_id = self._html_search_regex(
|
||||||
[r'(["\'])(?:https?:)?//www\.wat\.tv/embedframe/.*?(?P<id>\d{8})\1',
|
[r'(["\'])(?:https?:)?//www\.wat\.tv/embedframe/.*?(?P<id>\d{8})\1',
|
||||||
r'(["\']?)streamId\1\s*:\s*(["\']?)(?P<id>\d+)\2\s*,[^}}]*(["\']?)slug\4\s*:\s*(["\']){}\5'
|
|
||||||
.format(slug),
|
|
||||||
r'(["\']?)slug\1\s*:\s*(["\']){}\2,[^}}]*(["\']?)streamId\3\s*:\s*(["\']?)(?P<id>\d+)\4'
|
|
||||||
.format(slug),
|
|
||||||
r'(["\']?)streamId\1\s*:\s*(["\']?)(?P<id>\d+)\2'
|
r'(["\']?)streamId\1\s*:\s*(["\']?)(?P<id>\d+)\2'
|
||||||
],
|
],
|
||||||
webpage, 'wat id', group='id')
|
webpage, 'wat id', group='id')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user