[thisav] Recognize jwplayers (closes #10447)
[youtube-dl] / youtube_dl / extractor / thisav.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .jwplatform import JWPlatformBaseIE
7
8
9 class ThisAVIE(JWPlatformBaseIE):
10     _VALID_URL = r'https?://(?:www\.)?thisav\.com/video/(?P<id>[0-9]+)/.*'
11     _TESTS = [{
12         'url': 'http://www.thisav.com/video/47734/%98%26sup1%3B%83%9E%83%82---just-fit.html',
13         'md5': '0480f1ef3932d901f0e0e719f188f19b',
14         'info_dict': {
15             'id': '47734',
16             'ext': 'flv',
17             'title': '高樹マリア - Just fit',
18             'uploader': 'dj7970',
19             'uploader_id': 'dj7970'
20         }
21     }, {
22         'url': 'http://www.thisav.com/video/242352/nerdy-18yo-big-ass-tattoos-and-glasses.html',
23         'md5': 'ba90c076bd0f80203679e5b60bf523ee',
24         'info_dict': {
25             'id': '242352',
26             'ext': 'mp4',
27             'title': 'Nerdy 18yo Big Ass Tattoos and Glasses',
28             'uploader': 'cybersluts',
29             'uploader_id': 'cybersluts',
30         },
31     }]
32
33     def _real_extract(self, url):
34         mobj = re.match(self._VALID_URL, url)
35
36         video_id = mobj.group('id')
37         webpage = self._download_webpage(url, video_id)
38         title = self._html_search_regex(r'<h1>([^<]*)</h1>', webpage, 'title')
39         video_url = self._html_search_regex(
40             r"addVariable\('file','([^']+)'\);", webpage, 'video url', default=None)
41         if video_url:
42             info_dict = {
43                 'formats': [{
44                     'url': video_url,
45                 }],
46             }
47         else:
48             info_dict = self._extract_jwplayer_data(
49                 webpage, video_id, require_title=False)
50         uploader = self._html_search_regex(
51             r': <a href="http://www.thisav.com/user/[0-9]+/(?:[^"]+)">([^<]+)</a>',
52             webpage, 'uploader name', fatal=False)
53         uploader_id = self._html_search_regex(
54             r': <a href="http://www.thisav.com/user/[0-9]+/([^"]+)">(?:[^<]+)</a>',
55             webpage, 'uploader id', fatal=False)
56
57         info_dict.update({
58             'id': video_id,
59             'uploader': uploader,
60             'uploader_id': uploader_id,
61             'title': title,
62         })
63
64         return info_dict