fix increment operator
[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'http://(?:www\.)?thvideo\.tv/(?:v/th|mobile\.php\?cid=)(?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(
34             'http://thvideo.tv/mobile.php?cid=%s-0' % (video_id),
35             video_id, note='Downloading video source page')
36         video_url = self._html_search_regex(
37             r'<source src="(.*?)" type', webpage_player, 'video url')
38
39         # extract video info from main page
40         webpage = self._download_webpage(
41             'http://thvideo.tv/v/th%s' % (video_id), video_id)
42         title = self._og_search_title(webpage)
43         display_id = 'th%s' % video_id
44         thumbnail = self._og_search_thumbnail(webpage)
45         description = self._og_search_description(webpage)
46         upload_date = unified_strdate(self._html_search_regex(
47             r'span itemprop="datePublished" content="(.*?)">', webpage,
48             'upload date', fatal=False))
49
50         return {
51             'id': video_id,
52             'ext': 'mp4',
53             'url': video_url,
54             'title': title,
55             'display_id': display_id,
56             'thumbnail': thumbnail,
57             'description': description,
58             'upload_date': upload_date
59         }