Merge remote-tracking branch 'diffycat/jpopsuki'
[youtube-dl] / youtube_dl / extractor / jpopsukitv.py
1 # coding=utf-8
2 import re
3 from ..utils import unified_strdate
4 from .common import InfoExtractor
5
6
7 class JpopsukiIE(InfoExtractor):
8     IE_NAME = u'jpopsuki.tv'
9     _VALID_URL = r'https?://(?:www\.)?jpopsuki\.tv/video/(.*?)/(?P<id>\S+)'
10
11     _TEST = {
12         u'url': u'http://www.jpopsuki.tv/video/ayumi-hamasaki---evolution/00be659d23b0b40508169cdee4545771',
13         u'md5': u'88018c0c1a9b1387940e90ec9e7e198e',
14         u'file': u'00be659d23b0b40508169cdee4545771.mp4',
15         u'info_dict': {
16             u'id': u'00be659d23b0b40508169cdee4545771',
17             u'title': u'ayumi hamasaki - evolution',
18             'description': u'Release date: 2001.01.31\r 浜崎あゆみ - evolution',
19             'thumbnail': u'http://www.jpopsuki.tv/cache/89722c74d2a2ebe58bcac65321c115b2.jpg',
20             'uploader': u'plama_chan',
21             'uploader_id': u'404',
22             'upload_date': u'20121101'
23         }
24     }
25
26     def _real_extract(self, url):
27         mobj = re.match(self._VALID_URL, url)
28         video_id = mobj.group('id')
29
30         webpage = self._download_webpage(url, video_id)
31
32         video_url = 'http://www.jpopsuki.tv' + self._html_search_regex(
33             r'<source src="(.*?)" type', webpage, u'video url')
34
35         video_title = self._html_search_regex(
36             r'<meta name="og:title" content="(.*?)" />', webpage, u'video title')
37         description = self._html_search_regex(
38             r'<meta name="og:description" content="(.*?)" />', webpage, u'video description', flags=re.DOTALL)
39         thumbnail = self._html_search_regex(
40             r'<meta name="og:image" content="(.*?)" />', webpage, u'video thumbnail')
41         uploader = self._html_search_regex(
42             r'<li>from: <a href="/user/view/user/(.*?)/uid/', webpage, u'video uploader')
43         uploader_id = self._html_search_regex(
44             r'<li>from: <a href="/user/view/user/\S*?/uid/(\d*)', webpage, u'video uploader_id')
45         upload_date = self._html_search_regex(
46             r'<li>uploaded: (.*?)</li>', webpage, u'video upload_date')
47         if upload_date is not None:
48             upload_date = unified_strdate(upload_date)
49         view_count = self._html_search_regex(
50             r'<li>Hits: (\d*?)</li>', webpage, u'video view_count')
51         comment_count = self._html_search_regex(
52             r'<h2>(\d*?) comments</h2>', webpage, u'video comment_count')
53
54         return {
55             'id': video_id,
56             'url': video_url,
57             'title': video_title,
58             'description': description,
59             'thumbnail': thumbnail,
60             'uploader': uploader,
61             'uploader_id': uploader_id,
62             'upload_date': upload_date,
63             'view_count': view_count,
64             'comment_count': comment_count,
65         }