1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-11-25 12:45:34 +08:00
youtube-dl/youtube_dl/extractor/toutv.py

75 lines
2.6 KiB
Python
Raw Normal View History

2013-11-20 13:13:19 +08:00
# coding: utf-8
2014-02-05 20:02:03 +08:00
from __future__ import unicode_literals
2013-11-20 13:13:19 +08:00
import re
from .common import InfoExtractor
from ..utils import (
ExtractorError,
unified_strdate,
)
class TouTvIE(InfoExtractor):
2014-02-05 20:02:03 +08:00
IE_NAME = 'tou.tv'
2013-11-20 13:13:19 +08:00
_VALID_URL = r'https?://www\.tou\.tv/(?P<id>[a-zA-Z0-9_-]+(?:/(?P<episode>S[0-9]+E[0-9]+)))'
_TEST = {
2014-02-05 20:02:03 +08:00
'url': 'http://www.tou.tv/30-vies/S04E41',
'info_dict': {
2015-02-01 22:01:33 +08:00
'id': '30-vies_S04E41',
'ext': 'mp4',
2014-02-05 20:02:03 +08:00
'title': '30 vies Saison 4 / Épisode 41',
'description': 'md5:da363002db82ccbe4dafeb9cab039b09',
'age_limit': 8,
'uploader': 'Groupe des Nouveaux Médias',
'duration': 1296,
'upload_date': '20131118',
'thumbnail': 'http://static.tou.tv/medias/images/2013-11-18_19_00_00_30VIES_0341_01_L.jpeg',
2013-11-20 13:13:19 +08:00
},
2014-02-05 20:02:03 +08:00
'params': {
'skip_download': True, # Requires rtmpdump
2013-11-20 13:13:19 +08:00
},
2014-02-05 20:02:03 +08:00
'skip': 'Only available in Canada'
2013-11-20 13:13:19 +08:00
}
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
webpage = self._download_webpage(url, video_id)
mediaId = self._search_regex(
2014-02-05 20:02:03 +08:00
r'"idMedia":\s*"([^"]+)"', webpage, 'media ID')
2013-11-20 13:13:19 +08:00
2014-02-05 20:02:03 +08:00
streams_url = 'http://release.theplatform.com/content.select?pid=' + mediaId
streams_doc = self._download_xml(
2014-02-05 20:02:03 +08:00
streams_url, video_id, note='Downloading stream list')
2013-11-20 13:13:19 +08:00
video_url = next(n.text
for n in streams_doc.findall('.//choice/url')
2014-02-05 20:02:03 +08:00
if '//ad.doubleclick' not in n.text)
2013-11-20 13:13:19 +08:00
if video_url.endswith('/Unavailable.flv'):
raise ExtractorError(
2014-02-05 20:02:03 +08:00
'Access to this video is blocked from outside of Canada',
2013-11-20 13:13:19 +08:00
expected=True)
duration_str = self._html_search_meta(
2014-02-05 20:02:03 +08:00
'video:duration', webpage, 'duration')
2013-11-20 13:13:19 +08:00
duration = int(duration_str) if duration_str else None
upload_date_str = self._html_search_meta(
2014-02-05 20:02:03 +08:00
'video:release_date', webpage, 'upload date')
2013-11-20 13:13:19 +08:00
upload_date = unified_strdate(upload_date_str) if upload_date_str else None
return {
'id': video_id,
'title': self._og_search_title(webpage),
'url': video_url,
'description': self._og_search_description(webpage),
'uploader': self._dc_search_uploader(webpage),
'thumbnail': self._og_search_thumbnail(webpage),
'age_limit': self._media_rating_search(webpage),
'duration': duration,
'upload_date': upload_date,
'ext': 'mp4',
}