]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
fe7710cb YCH |
2 | from __future__ import unicode_literals |
3 | ||
fe7710cb | 4 | from .common import InfoExtractor |
fe7710cb YCH |
5 | from ..utils import ( |
6 | ExtractorError, | |
babbc04d YCH |
7 | float_or_none, |
8 | get_element_by_attribute, | |
fe7710cb | 9 | parse_iso8601, |
babbc04d | 10 | remove_end, |
fe7710cb YCH |
11 | ) |
12 | ||
fe7710cb YCH |
13 | |
14 | class XuiteIE(InfoExtractor): | |
4fa5f402 | 15 | IE_DESC = '隨意窩Xuite影音' |
affd04a4 | 16 | _REGEX_BASE64 = r'(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?' |
21933799 | 17 | _VALID_URL = r'https?://vlog\.xuite\.net/(?:play|embed)/(?P<id>%s)' % _REGEX_BASE64 |
fe7710cb YCH |
18 | _TESTS = [{ |
19 | # Audio | |
20 | 'url': 'http://vlog.xuite.net/play/RGkzc1ZULTM4NjA5MTQuZmx2', | |
75bb5c70 | 21 | 'md5': 'e79284c87b371424885448d11f6398c8', |
fe7710cb | 22 | 'info_dict': { |
affd04a4 | 23 | 'id': '3860914', |
fe7710cb | 24 | 'ext': 'mp3', |
a2838383 | 25 | 'title': '孤單南半球-歐德陽', |
babbc04d | 26 | 'description': '孤單南半球-歐德陽', |
ec85ded8 | 27 | 'thumbnail': r're:^https?://.*\.jpg$', |
affd04a4 S |
28 | 'duration': 247.246, |
29 | 'timestamp': 1314932940, | |
30 | 'upload_date': '20110902', | |
31 | 'uploader': '阿能', | |
32 | 'uploader_id': '15973816', | |
a2838383 | 33 | 'categories': ['個人短片'], |
affd04a4 | 34 | }, |
fe7710cb YCH |
35 | }, { |
36 | # Video with only one format | |
231ea2a3 YCH |
37 | 'url': 'http://vlog.xuite.net/play/WUxxR2xCLTI1OTI1MDk5LmZsdg==', |
38 | 'md5': '21f7b39c009b5a4615b4463df6eb7a46', | |
fe7710cb | 39 | 'info_dict': { |
231ea2a3 | 40 | 'id': '25925099', |
fe7710cb | 41 | 'ext': 'mp4', |
231ea2a3 | 42 | 'title': 'BigBuckBunny_320x180', |
ec85ded8 | 43 | 'thumbnail': r're:^https?://.*\.jpg$', |
231ea2a3 YCH |
44 | 'duration': 596.458, |
45 | 'timestamp': 1454242500, | |
46 | 'upload_date': '20160131', | |
babbc04d | 47 | 'uploader': '屁姥', |
231ea2a3 YCH |
48 | 'uploader_id': '12158353', |
49 | 'categories': ['個人短片'], | |
50 | 'description': 'http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4', | |
affd04a4 | 51 | }, |
fe7710cb YCH |
52 | }, { |
53 | # Video with two formats | |
54 | 'url': 'http://vlog.xuite.net/play/bWo1N1pLLTIxMzAxMTcwLmZsdg==', | |
55 | 'md5': '1166e0f461efe55b62e26a2d2a68e6de', | |
56 | 'info_dict': { | |
affd04a4 | 57 | 'id': '21301170', |
fe7710cb | 58 | 'ext': 'mp4', |
fe7710cb | 59 | 'title': '暗殺教室 02', |
affd04a4 | 60 | 'description': '字幕:【極影字幕社】', |
ec85ded8 | 61 | 'thumbnail': r're:^https?://.*\.jpg$', |
affd04a4 S |
62 | 'duration': 1384.907, |
63 | 'timestamp': 1421481240, | |
64 | 'upload_date': '20150117', | |
65 | 'uploader': '我只是想認真點', | |
66 | 'uploader_id': '242127761', | |
a2838383 | 67 | 'categories': ['電玩動漫'], |
affd04a4 | 68 | }, |
506d0e96 | 69 | 'skip': 'Video removed', |
c6054e32 YCH |
70 | }, { |
71 | # Video with encoded media id | |
72 | # from http://forgetfulbc.blogspot.com/2016/06/date.html | |
73 | 'url': 'http://vlog.xuite.net/embed/cE1xbENoLTI3NDQ3MzM2LmZsdg==?ar=0&as=0', | |
74 | 'info_dict': { | |
babbc04d | 75 | 'id': '27447336', |
c6054e32 YCH |
76 | 'ext': 'mp4', |
77 | 'title': '男女平權只是口號?專家解釋約會時男生是否該幫女生付錢 (中字)', | |
babbc04d | 78 | 'description': 'md5:1223810fa123b179083a3aed53574706', |
c6054e32 YCH |
79 | 'timestamp': 1466160960, |
80 | 'upload_date': '20160617', | |
81 | 'uploader': 'B.C. & Lowy', | |
82 | 'uploader_id': '232279340', | |
83 | }, | |
affd04a4 S |
84 | }, { |
85 | 'url': 'http://vlog.xuite.net/play/S1dDUjdyLTMyOTc3NjcuZmx2/%E5%AD%AB%E7%87%95%E5%A7%BF-%E7%9C%BC%E6%B7%9A%E6%88%90%E8%A9%A9', | |
86 | 'only_matching': True, | |
fe7710cb YCH |
87 | }] |
88 | ||
fe7710cb | 89 | def _real_extract(self, url): |
babbc04d YCH |
90 | # /play/ URLs provide embedded video URL and more metadata |
91 | url = url.replace('/embed/', '/play/') | |
fe7710cb YCH |
92 | video_id = self._match_id(url) |
93 | ||
affd04a4 S |
94 | webpage = self._download_webpage(url, video_id) |
95 | ||
96 | error_msg = self._search_regex( | |
97 | r'<div id="error-message-content">([^<]+)', | |
98 | webpage, 'error message', default=None) | |
99 | if error_msg: | |
100 | raise ExtractorError( | |
101 | '%s returned error: %s' % (self.IE_NAME, error_msg), | |
102 | expected=True) | |
fe7710cb | 103 | |
babbc04d YCH |
104 | media_info = self._parse_json(self._search_regex( |
105 | r'var\s+mediaInfo\s*=\s*({.*});', webpage, 'media info'), video_id) | |
fe7710cb | 106 | |
babbc04d | 107 | video_id = media_info['MEDIA_ID'] |
affd04a4 S |
108 | |
109 | formats = [] | |
babbc04d YCH |
110 | for key in ('html5Url', 'html5HQUrl'): |
111 | video_url = media_info.get(key) | |
affd04a4 S |
112 | if not video_url: |
113 | continue | |
114 | format_id = self._search_regex( | |
babbc04d | 115 | r'\bq=(.+?)\b', video_url, 'format id', default=None) |
affd04a4 S |
116 | formats.append({ |
117 | 'url': video_url, | |
babbc04d | 118 | 'ext': 'mp4' if format_id.isnumeric() else format_id, |
affd04a4 S |
119 | 'format_id': format_id, |
120 | 'height': int(format_id) if format_id.isnumeric() else None, | |
121 | }) | |
122 | self._sort_formats(formats) | |
123 | ||
babbc04d | 124 | timestamp = media_info.get('PUBLISH_DATETIME') |
affd04a4 S |
125 | if timestamp: |
126 | timestamp = parse_iso8601(timestamp + ' +0800', ' ') | |
127 | ||
babbc04d | 128 | category = media_info.get('catName') |
affd04a4 S |
129 | categories = [category] if category else [] |
130 | ||
babbc04d YCH |
131 | uploader = media_info.get('NICKNAME') |
132 | uploader_url = None | |
133 | ||
134 | author_div = get_element_by_attribute('itemprop', 'author', webpage) | |
135 | if author_div: | |
136 | uploader = uploader or self._html_search_meta('name', author_div) | |
137 | uploader_url = self._html_search_regex( | |
138 | r'<link[^>]+itemprop="url"[^>]+href="([^"]+)"', author_div, | |
139 | 'uploader URL', fatal=False) | |
140 | ||
affd04a4 | 141 | return { |
fe7710cb | 142 | 'id': video_id, |
babbc04d YCH |
143 | 'title': media_info['TITLE'], |
144 | 'description': remove_end(media_info.get('metaDesc'), ' (Xuite 影音)'), | |
145 | 'thumbnail': media_info.get('ogImageUrl'), | |
affd04a4 | 146 | 'timestamp': timestamp, |
babbc04d YCH |
147 | 'uploader': uploader, |
148 | 'uploader_id': media_info.get('MEMBER_ID'), | |
149 | 'uploader_url': uploader_url, | |
150 | 'duration': float_or_none(media_info.get('MEDIA_DURATION'), 1000000), | |
affd04a4 S |
151 | 'categories': categories, |
152 | 'formats': formats, | |
fe7710cb | 153 | } |