skeb.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. from .common import InfoExtractor
  2. from ..utils import ExtractorError, determine_ext, parse_qs, traverse_obj
  3. class SkebIE(InfoExtractor):
  4. _VALID_URL = r'https?://skeb\.jp/@[^/]+/works/(?P<id>\d+)'
  5. _TESTS = [{
  6. 'url': 'https://skeb.jp/@riiru_wm/works/10',
  7. 'info_dict': {
  8. 'id': '466853',
  9. 'title': '内容はおまかせします! by 姫ノ森りぃる@一周年',
  10. 'description': 'md5:1ec50901efc3437cfbfe3790468d532d',
  11. 'uploader': '姫ノ森りぃる@一周年',
  12. 'uploader_id': 'riiru_wm',
  13. 'age_limit': 0,
  14. 'tags': [],
  15. 'url': r're:https://skeb.+',
  16. 'thumbnail': r're:https://skeb.+',
  17. 'subtitles': {
  18. 'jpn': [{
  19. 'url': r're:https://skeb.+',
  20. 'ext': 'vtt',
  21. }],
  22. },
  23. 'width': 720,
  24. 'height': 405,
  25. 'duration': 313,
  26. 'fps': 30,
  27. 'ext': 'mp4',
  28. },
  29. }, {
  30. 'url': 'https://skeb.jp/@furukawa_nob/works/3',
  31. 'info_dict': {
  32. 'id': '489408',
  33. 'title': 'いつもお世話になってお... by 古川ノブ@音楽とVlo...',
  34. 'description': 'md5:5adc2e41d06d33b558bf7b1faeb7b9c2',
  35. 'uploader': '古川ノブ@音楽とVlogのVtuber',
  36. 'uploader_id': 'furukawa_nob',
  37. 'age_limit': 0,
  38. 'tags': [
  39. 'よろしく', '大丈夫', 'お願い', 'でした',
  40. '是非', 'O', 'バー', '遊び', 'おはよう',
  41. 'オーバ', 'ボイス',
  42. ],
  43. 'url': r're:https://skeb.+',
  44. 'thumbnail': r're:https://skeb.+',
  45. 'subtitles': {
  46. 'jpn': [{
  47. 'url': r're:https://skeb.+',
  48. 'ext': 'vtt',
  49. }],
  50. },
  51. 'duration': 98,
  52. 'ext': 'mp3',
  53. 'vcodec': 'none',
  54. 'abr': 128,
  55. },
  56. }, {
  57. 'url': 'https://skeb.jp/@mollowmollow/works/6',
  58. 'info_dict': {
  59. 'id': '6',
  60. 'title': 'ヒロ。\n\n私のキャラク... by 諸々',
  61. 'description': 'md5:aa6cbf2ba320b50bce219632de195f07',
  62. '_type': 'playlist',
  63. 'entries': [{
  64. 'id': '486430',
  65. 'title': 'ヒロ。\n\n私のキャラク... by 諸々',
  66. 'description': 'md5:aa6cbf2ba320b50bce219632de195f07',
  67. }, {
  68. 'id': '486431',
  69. 'title': 'ヒロ。\n\n私のキャラク... by 諸々',
  70. }],
  71. },
  72. }]
  73. def _real_extract(self, url):
  74. video_id = self._match_id(url)
  75. nuxt_data = self._search_nuxt_data(self._download_webpage(url, video_id), video_id)
  76. parent = {
  77. 'id': video_id,
  78. 'title': nuxt_data.get('title'),
  79. 'description': nuxt_data.get('description'),
  80. 'uploader': traverse_obj(nuxt_data, ('creator', 'name')),
  81. 'uploader_id': traverse_obj(nuxt_data, ('creator', 'screen_name')),
  82. 'age_limit': 18 if nuxt_data.get('nsfw') else 0,
  83. 'tags': nuxt_data.get('tag_list'),
  84. }
  85. entries = []
  86. for item in nuxt_data.get('previews') or []:
  87. vid_url = item.get('url')
  88. given_ext = traverse_obj(item, ('information', 'extension'))
  89. preview_ext = determine_ext(vid_url, default_ext=None)
  90. if not preview_ext:
  91. content_disposition = parse_qs(vid_url)['response-content-disposition'][0]
  92. preview_ext = self._search_regex(
  93. r'filename="[^"]+\.([^\.]+?)"', content_disposition,
  94. 'preview file extension', fatal=False, group=1)
  95. if preview_ext not in ('mp4', 'mp3'):
  96. continue
  97. if not vid_url or not item.get('id'):
  98. continue
  99. width, height = traverse_obj(item, ('information', 'width')), traverse_obj(item, ('information', 'height'))
  100. if width is not None and height is not None:
  101. # the longest side is at most 720px for non-client viewers
  102. max_size = max(width, height)
  103. width, height = (x * 720 // max_size for x in (width, height))
  104. entries.append({
  105. **parent,
  106. 'id': str(item['id']),
  107. 'url': vid_url,
  108. 'thumbnail': item.get('poster_url'),
  109. 'subtitles': {
  110. 'jpn': [{
  111. 'url': item.get('vtt_url'),
  112. 'ext': 'vtt',
  113. }],
  114. } if item.get('vtt_url') else None,
  115. 'width': width,
  116. 'height': height,
  117. 'duration': traverse_obj(item, ('information', 'duration')),
  118. 'fps': traverse_obj(item, ('information', 'frame_rate')),
  119. 'ext': preview_ext or given_ext,
  120. 'vcodec': 'none' if preview_ext == 'mp3' else None,
  121. # you'll always get 128kbps MP3 for non-client viewers
  122. 'abr': 128 if preview_ext == 'mp3' else None,
  123. })
  124. if not entries:
  125. raise ExtractorError('No video/audio attachment found in this commission.', expected=True)
  126. elif len(entries) == 1:
  127. return entries[0]
  128. else:
  129. parent.update({
  130. '_type': 'playlist',
  131. 'entries': entries,
  132. })
  133. return parent