[thvideo] Add support for THVideo
[youtube-dl] / youtube_dl / extractor / thvideo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     unified_strdate
9 )
10
11
12 class THVideoIE(InfoExtractor):
13     _VALID_URL = r'https?://(?:www\.)?thvideo\.tv/v/th(?P<id>[0-9]+)'
14     _TEST = {
15         'url': 'http://thvideo.tv/v/th1987/',
16         'md5': 'fa107b1f73817e325e9433505a70db50',
17         'info_dict': {
18             'id': '1987',
19             'ext': 'mp4',
20             'title': '【动画】秘封活动记录 ~ The Sealed Esoteric History.分镜稿预览',
21             'display_id': 'th1987',
22             'thumbnail': 'http://thvideo.tv/uploadfile/2014/0722/20140722013459856.jpg',
23             'description': '社团京都幻想剧团的第一个东方二次同人动画作品「秘封活动记录 ~ The Sealed Esoteric History.」 本视频是该动画第一期的分镜草稿...',
24             'upload_date': '20140722'
25         }
26     }
27
28     def _real_extract(self, url):
29         mobj = re.match(self._VALID_URL, url)
30         video_id = mobj.group('id')
31
32         # extract download link from mobile player page
33         webpage_player = self._download_webpage('http://thvideo.tv/mobile.php?cid=%s-0' % video_id, video_id)
34         video_url = self._html_search_regex(r'<source src="(.*?)" type', webpage_player, 'video url')
35
36         # extract video info from main page
37         webpage = self._download_webpage(url, video_id)
38         title = self._og_search_title(webpage)
39         display_id = 'th%s' % video_id
40         thumbnail = self._og_search_thumbnail(webpage)
41         description = self._og_search_description(webpage)
42         upload_date_raw = self._html_search_regex(r'span itemprop="datePublished" content="(.*?)">', webpage,
43                                                   'upload date', fatal=False)
44         upload_date = unified_strdate(upload_date_raw)
45
46         return {
47             'id': video_id,
48             'ext': 'mp4',
49             'url': video_url,
50             'title': title,
51             'display_id': display_id,
52             'thumbnail': thumbnail,
53             'description': description,
54             'upload_date': upload_date
55         }