You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
5.7 KiB

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