[generic] Try parsing JWPlayer embedded videos (closes #12030)
[youtube-dl] / youtube_dl / extractor / thisav.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 remove_end
8
9
10 class ThisAVIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?thisav\.com/video/(?P<id>[0-9]+)/.*'
12     _TESTS = [{
13         'url': 'http://www.thisav.com/video/47734/%98%26sup1%3B%83%9E%83%82---just-fit.html',
14         'md5': '0480f1ef3932d901f0e0e719f188f19b',
15         'info_dict': {
16             'id': '47734',
17             'ext': 'flv',
18             'title': '高樹マリア - Just fit',
19             'uploader': 'dj7970',
20             'uploader_id': 'dj7970'
21         }
22     }, {
23         'url': 'http://www.thisav.com/video/242352/nerdy-18yo-big-ass-tattoos-and-glasses.html',
24         'md5': 'ba90c076bd0f80203679e5b60bf523ee',
25         'info_dict': {
26             'id': '242352',
27             'ext': 'mp4',
28             'title': 'Nerdy 18yo Big Ass Tattoos and Glasses',
29             'uploader': 'cybersluts',
30             'uploader_id': 'cybersluts',
31         },
32     }]
33
34     def _real_extract(self, url):
35         mobj = re.match(self._VALID_URL, url)
36
37         video_id = mobj.group('id')
38         webpage = self._download_webpage(url, video_id)
39         title = remove_end(self._html_search_regex(
40             r'<title>([^<]+)</title>', webpage, 'title'),
41             ' - 視頻 - ThisAV.com-世界第一中文成人娛樂網站')
42         video_url = self._html_search_regex(
43             r"addVariable\('file','([^']+)'\);", webpage, 'video url', default=None)
44         if video_url:
45             info_dict = {
46                 'formats': [{
47                     'url': video_url,
48                 }],
49             }
50         else:
51             info_dict = self._extract_jwplayer_data(
52                 webpage, video_id, require_title=False)
53         uploader = self._html_search_regex(
54             r': <a href="http://www.thisav.com/user/[0-9]+/(?:[^"]+)">([^<]+)</a>',
55             webpage, 'uploader name', fatal=False)
56         uploader_id = self._html_search_regex(
57             r': <a href="http://www.thisav.com/user/[0-9]+/([^"]+)">(?:[^<]+)</a>',
58             webpage, 'uploader id', fatal=False)
59
60         info_dict.update({
61             'id': video_id,
62             'uploader': uploader,
63             'uploader_id': uploader_id,
64             'title': title,
65         })
66
67         return info_dict