]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/asiancrush.py
[youtube] Fix controversy videos extraction (closes #14027, closes #14029)
[youtube-dl] / youtube_dl / extractor / asiancrush.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from .kaltura import KalturaIE
8 from ..utils import (
9     extract_attributes,
10     remove_end,
11     urlencode_postdata,
12 )
13
14
15 class AsianCrushIE(InfoExtractor):
16     _VALID_URL = r'https?://(?:www\.)?asiancrush\.com/video/(?:[^/]+/)?0+(?P<id>\d+)v\b'
17     _TESTS = [{
18         'url': 'https://www.asiancrush.com/video/012869v/women-who-flirt/',
19         'md5': 'c3b740e48d0ba002a42c0b72857beae6',
20         'info_dict': {
21             'id': '1_y4tmjm5r',
22             'ext': 'mp4',
23             'title': 'Women Who Flirt',
24             'description': 'md5:3db14e9186197857e7063522cb89a805',
25             'timestamp': 1496936429,
26             'upload_date': '20170608',
27             'uploader_id': 'craig@crifkin.com',
28         },
29     }, {
30         'url': 'https://www.asiancrush.com/video/she-was-pretty/011886v-pretty-episode-3/',
31         'only_matching': True,
32     }]
33
34     def _real_extract(self, url):
35         video_id = self._match_id(url)
36
37         data = self._download_json(
38             'https://www.asiancrush.com/wp-admin/admin-ajax.php', video_id,
39             data=urlencode_postdata({
40                 'postid': video_id,
41                 'action': 'get_channel_kaltura_vars',
42             }))
43
44         entry_id = data['entry_id']
45
46         return self.url_result(
47             'kaltura:%s:%s' % (data['partner_id'], entry_id),
48             ie=KalturaIE.ie_key(), video_id=entry_id,
49             video_title=data.get('vid_label'))
50
51
52 class AsianCrushPlaylistIE(InfoExtractor):
53     _VALID_URL = r'https?://(?:www\.)?asiancrush\.com/series/0+(?P<id>\d+)s\b'
54     _TEST = {
55         'url': 'https://www.asiancrush.com/series/012481s/scholar-walks-night/',
56         'info_dict': {
57             'id': '12481',
58             'title': 'Scholar Who Walks the Night',
59             'description': 'md5:7addd7c5132a09fd4741152d96cce886',
60         },
61         'playlist_count': 20,
62     }
63
64     def _real_extract(self, url):
65         playlist_id = self._match_id(url)
66
67         webpage = self._download_webpage(url, playlist_id)
68
69         entries = []
70
71         for mobj in re.finditer(
72                 r'<a[^>]+href=(["\'])(?P<url>%s.*?)\1[^>]*>' % AsianCrushIE._VALID_URL,
73                 webpage):
74             attrs = extract_attributes(mobj.group(0))
75             if attrs.get('class') == 'clearfix':
76                 entries.append(self.url_result(
77                     mobj.group('url'), ie=AsianCrushIE.ie_key()))
78
79         title = remove_end(
80             self._html_search_regex(
81                 r'(?s)<h1\b[^>]\bid=["\']movieTitle[^>]+>(.+?)</h1>', webpage,
82                 'title', default=None) or self._og_search_title(
83                 webpage, default=None) or self._html_search_meta(
84                 'twitter:title', webpage, 'title',
85                 default=None) or self._search_regex(
86                 r'<title>([^<]+)</title>', webpage, 'title', fatal=False),
87             ' | AsianCrush')
88
89         description = self._og_search_description(
90             webpage, default=None) or self._html_search_meta(
91             'twitter:description', webpage, 'description', fatal=False)
92
93         return self.playlist_result(entries, playlist_id, title, description)