]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/asiancrush.py
Prepare to upload
[youtubedl] / 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 extract_attributes
9
10
11 class AsianCrushIE(InfoExtractor):
12 _VALID_URL_BASE = r'https?://(?:www\.)?(?P<host>(?:(?:asiancrush|yuyutv|midnightpulp)\.com|cocoro\.tv))'
13 _VALID_URL = r'%s/video/(?:[^/]+/)?0+(?P<id>\d+)v\b' % _VALID_URL_BASE
14 _TESTS = [{
15 'url': 'https://www.asiancrush.com/video/012869v/women-who-flirt/',
16 'md5': 'c3b740e48d0ba002a42c0b72857beae6',
17 'info_dict': {
18 'id': '1_y4tmjm5r',
19 'ext': 'mp4',
20 'title': 'Women Who Flirt',
21 'description': 'md5:7e986615808bcfb11756eb503a751487',
22 'timestamp': 1496936429,
23 'upload_date': '20170608',
24 'uploader_id': 'craig@crifkin.com',
25 },
26 }, {
27 'url': 'https://www.asiancrush.com/video/she-was-pretty/011886v-pretty-episode-3/',
28 'only_matching': True,
29 }, {
30 'url': 'https://www.yuyutv.com/video/013886v/the-act-of-killing/',
31 'only_matching': True,
32 }, {
33 'url': 'https://www.yuyutv.com/video/peep-show/013922v-warring-factions/',
34 'only_matching': True,
35 }, {
36 'url': 'https://www.midnightpulp.com/video/010400v/drifters/',
37 'only_matching': True,
38 }, {
39 'url': 'https://www.midnightpulp.com/video/mononoke/016378v-zashikiwarashi-part-1/',
40 'only_matching': True,
41 }, {
42 'url': 'https://www.cocoro.tv/video/the-wonderful-wizard-of-oz/008878v-the-wonderful-wizard-of-oz-ep01/',
43 'only_matching': True,
44 }]
45
46 def _real_extract(self, url):
47 mobj = re.match(self._VALID_URL, url)
48 host = mobj.group('host')
49 video_id = mobj.group('id')
50
51 webpage = self._download_webpage(url, video_id)
52
53 entry_id, partner_id, title = [None] * 3
54
55 vars = self._parse_json(
56 self._search_regex(
57 r'iEmbedVars\s*=\s*({.+?})', webpage, 'embed vars',
58 default='{}'), video_id, fatal=False)
59 if vars:
60 entry_id = vars.get('entry_id')
61 partner_id = vars.get('partner_id')
62 title = vars.get('vid_label')
63
64 if not entry_id:
65 entry_id = self._search_regex(
66 r'\bentry_id["\']\s*:\s*["\'](\d+)', webpage, 'entry id')
67
68 player = self._download_webpage(
69 'https://api.%s/embeddedVideoPlayer' % host, video_id,
70 query={'id': entry_id})
71
72 kaltura_id = self._search_regex(
73 r'entry_id["\']\s*:\s*(["\'])(?P<id>(?:(?!\1).)+)\1', player,
74 'kaltura id', group='id')
75
76 if not partner_id:
77 partner_id = self._search_regex(
78 r'/p(?:artner_id)?/(\d+)', player, 'partner id',
79 default='513551')
80
81 description = self._html_search_regex(
82 r'(?s)<div[^>]+\bclass=["\']description["\'][^>]*>(.+?)</div>',
83 webpage, 'description', fatal=False)
84
85 return {
86 '_type': 'url_transparent',
87 'url': 'kaltura:%s:%s' % (partner_id, kaltura_id),
88 'ie_key': KalturaIE.ie_key(),
89 'id': video_id,
90 'title': title,
91 'description': description,
92 }
93
94
95 class AsianCrushPlaylistIE(InfoExtractor):
96 _VALID_URL = r'%s/series/0+(?P<id>\d+)s\b' % AsianCrushIE._VALID_URL_BASE
97 _TESTS = [{
98 'url': 'https://www.asiancrush.com/series/012481s/scholar-walks-night/',
99 'info_dict': {
100 'id': '12481',
101 'title': 'Scholar Who Walks the Night',
102 'description': 'md5:7addd7c5132a09fd4741152d96cce886',
103 },
104 'playlist_count': 20,
105 }, {
106 'url': 'https://www.yuyutv.com/series/013920s/peep-show/',
107 'only_matching': True,
108 }, {
109 'url': 'https://www.midnightpulp.com/series/016375s/mononoke/',
110 'only_matching': True,
111 }, {
112 'url': 'https://www.cocoro.tv/series/008549s/the-wonderful-wizard-of-oz/',
113 'only_matching': True,
114 }]
115
116 def _real_extract(self, url):
117 playlist_id = self._match_id(url)
118
119 webpage = self._download_webpage(url, playlist_id)
120
121 entries = []
122
123 for mobj in re.finditer(
124 r'<a[^>]+href=(["\'])(?P<url>%s.*?)\1[^>]*>' % AsianCrushIE._VALID_URL,
125 webpage):
126 attrs = extract_attributes(mobj.group(0))
127 if attrs.get('class') == 'clearfix':
128 entries.append(self.url_result(
129 mobj.group('url'), ie=AsianCrushIE.ie_key()))
130
131 title = self._html_search_regex(
132 r'(?s)<h1\b[^>]\bid=["\']movieTitle[^>]+>(.+?)</h1>', webpage,
133 'title', default=None) or self._og_search_title(
134 webpage, default=None) or self._html_search_meta(
135 'twitter:title', webpage, 'title',
136 default=None) or self._search_regex(
137 r'<title>([^<]+)</title>', webpage, 'title', fatal=False)
138 if title:
139 title = re.sub(r'\s*\|\s*.+?$', '', title)
140
141 description = self._og_search_description(
142 webpage, default=None) or self._html_search_meta(
143 'twitter:description', webpage, 'description', fatal=False)
144
145 return self.playlist_result(entries, playlist_id, title, description)