2 from __future__ import unicode_literals
4 from .common import InfoExtractor
8 from ..utils import extract_attributes
10 class VTVIE(InfoExtractor):
11 _VALID_URL = r'https?://(au|ca|cz|de|jp|kr|tw|us|vn)\.tvnet\.gov\.vn/[^/]*/(?P<id>[0-9]+)/?'
13 # Livestream. Channel: VTV 1
14 'url': 'http://us.tvnet.gov.vn/kenh-truyen-hinh/1011/vtv1',
18 'title': r're:^VTV1 | LiveTV - TV Net [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
19 'thumbnail': r're:https?://.*\.png$',
22 # Downloading a video.
23 'url': 'http://de.tvnet.gov.vn/video/109788/vtv1---bac-tuyet-tai-lao-cai-va-ha-giang/tin-nong-24h',
24 'md5': '5263c63d738569ed507980f1e49ebc03',
28 'title': 'VTV1 - Bắc tuyết tại Lào Cai và Hà Giang - TV Net',
29 'thumbnail': r're:https?://.*\.JPG$',
32 # Radio live stream. Channel: VOV 1
33 'url': 'http://vn.tvnet.gov.vn/kenh-truyen-hinh/1014',
38 'title': r're:VOV1 | LiveTV - TV Net [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
39 'thumbnail': r're:https?://.*\.png$',
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
46 webpage = self._download_webpage(url, video_id)
48 title = self._html_search_regex(r'<title>(.+?)</title>', webpage, 'title', default=None, fatal=False)
50 title = self._og_search_title(webpage)
53 mediaplayer_div = self._search_regex(r'(<div[^>]*id="mediaplayer"[^>]*>)', webpage, 'mediaplayer element')
54 mediaplayer_div_attributes = extract_attributes(mediaplayer_div)
56 thumbnail = mediaplayer_div_attributes.get("data-image")
58 json_url = mediaplayer_div_attributes["data-file"]
59 video_streams = self._download_json(json_url, video_id)
62 # get any working playlist from streams. Currently there's 2 and the first always works,
63 # but you never know in the future
64 for stream in video_streams:
65 formats = self._extract_m3u8_formats(stream.get("url"), video_id, ext="mp4", fatal=False)
69 # better support radio streams
70 if title.startswith("VOV"):
75 if "/video/" in url or "/radio/" in url:
77 elif "/kenh-truyen-hinh/" in url:
83 title = self._live_title(title)
88 'thumbnail': thumbnail,