damtomo.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import ExtractorError, clean_html, int_or_none, try_get, unified_strdate
  4. class DamtomoBaseIE(InfoExtractor):
  5. def _real_extract(self, url):
  6. video_id = self._match_id(url)
  7. webpage, handle = self._download_webpage_handle(self._WEBPAGE_URL_TMPL % video_id, video_id, encoding='sjis')
  8. if handle.url == 'https://www.clubdam.com/sorry/':
  9. raise ExtractorError('You are rate-limited. Try again later.', expected=True)
  10. if '<h2>予期せぬエラーが発生しました。</h2>' in webpage:
  11. raise ExtractorError('There is an error on server-side. Try again later.', expected=True)
  12. description = self._search_regex(r'(?m)<div id="public_comment">\s*<p>\s*([^<]*?)\s*</p>', webpage, 'description', default=None)
  13. uploader_id = self._search_regex(r'<a href="https://www\.clubdam\.com/app/damtomo/member/info/Profile\.do\?damtomoId=([^"]+)"', webpage, 'uploader_id', default=None)
  14. data_dict = {
  15. mobj.group('class'): re.sub(r'\s+', ' ', clean_html(mobj.group('value')))
  16. for mobj in re.finditer(r'(?s)<(p|div)\s+class="(?P<class>[^" ]+?)">(?P<value>.+?)</\1>', webpage)}
  17. # since videos do not have title, give the name of song instead
  18. data_dict['user_name'] = re.sub(r'\s*さん\s*$', '', data_dict['user_name'])
  19. title = data_dict.get('song_title')
  20. stream_tree = self._download_xml(
  21. self._DKML_XML_URL % video_id, video_id, note='Requesting stream information', encoding='sjis',
  22. # doing this has no problem since there is no character outside ASCII,
  23. # and never likely to happen in the future
  24. transform_source=lambda x: re.sub(r'\s*encoding="[^"]+?"', '', x))
  25. m3u8_url = try_get(stream_tree, lambda x: x.find(
  26. './/d:streamingUrl', {'d': self._DKML_XML_NS}).text.strip(), str)
  27. if not m3u8_url:
  28. raise ExtractorError('Failed to obtain m3u8 URL')
  29. formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
  30. return {
  31. 'id': video_id,
  32. 'title': title,
  33. 'uploader_id': uploader_id,
  34. 'description': description,
  35. 'uploader': data_dict.get('user_name'),
  36. 'upload_date': unified_strdate(self._search_regex(r'(\d{4}/\d{2}/\d{2})', data_dict.get('date'), 'upload_date', default=None)),
  37. 'view_count': int_or_none(self._search_regex(r'(\d+)', data_dict['audience'], 'view_count', default=None)),
  38. 'like_count': int_or_none(self._search_regex(r'(\d+)', data_dict['nice'], 'like_count', default=None)),
  39. 'track': title,
  40. 'artist': data_dict.get('song_artist'),
  41. 'formats': formats,
  42. }
  43. class DamtomoVideoIE(DamtomoBaseIE):
  44. IE_NAME = 'damtomo:video'
  45. _VALID_URL = r'https?://(?:www\.)?clubdam\.com/app/damtomo/(?:SP/)?karaokeMovie/StreamingDkm\.do\?karaokeMovieId=(?P<id>\d+)'
  46. _WEBPAGE_URL_TMPL = 'https://www.clubdam.com/app/damtomo/karaokeMovie/StreamingDkm.do?karaokeMovieId=%s'
  47. _DKML_XML_URL = 'https://www.clubdam.com/app/damtomo/karaokeMovie/GetStreamingDkmUrlXML.do?movieSelectFlg=2&karaokeMovieId=%s'
  48. _DKML_XML_NS = 'https://www.clubdam.com/app/damtomo/karaokeMovie/GetStreamingDkmUrlXML'
  49. _TESTS = [{
  50. 'url': 'https://www.clubdam.com/app/damtomo/karaokeMovie/StreamingDkm.do?karaokeMovieId=2414316',
  51. 'info_dict': {
  52. 'id': '2414316',
  53. 'title': 'Get Wild',
  54. 'uploader': 'Kドロン',
  55. 'uploader_id': 'ODk5NTQwMzQ',
  56. 'track': 'Get Wild',
  57. 'artist': 'TM NETWORK(TMN)',
  58. 'upload_date': '20201226',
  59. },
  60. }]
  61. class DamtomoRecordIE(DamtomoBaseIE):
  62. IE_NAME = 'damtomo:record'
  63. _VALID_URL = r'https?://(?:www\.)?clubdam\.com/app/damtomo/(?:SP/)?karaokePost/StreamingKrk\.do\?karaokeContributeId=(?P<id>\d+)'
  64. _WEBPAGE_URL_TMPL = 'https://www.clubdam.com/app/damtomo/karaokePost/StreamingKrk.do?karaokeContributeId=%s'
  65. _DKML_XML_URL = 'https://www.clubdam.com/app/damtomo/karaokePost/GetStreamingKrkUrlXML.do?karaokeContributeId=%s'
  66. _DKML_XML_NS = 'https://www.clubdam.com/app/damtomo/karaokePost/GetStreamingKrkUrlXML'
  67. _TESTS = [{
  68. 'url': 'https://www.clubdam.com/app/damtomo/karaokePost/StreamingKrk.do?karaokeContributeId=27376862',
  69. 'info_dict': {
  70. 'id': '27376862',
  71. 'title': 'イカSUMMER [良音]',
  72. 'uploader': 'NANA',
  73. 'uploader_id': 'MzAyMDExNTY',
  74. 'upload_date': '20210721',
  75. 'view_count': 4,
  76. 'like_count': 1,
  77. 'track': 'イカSUMMER [良音]',
  78. 'artist': 'ORANGE RANGE',
  79. },
  80. }, {
  81. 'url': 'https://www.clubdam.com/app/damtomo/karaokePost/StreamingKrk.do?karaokeContributeId=27489418',
  82. 'info_dict': {
  83. 'id': '27489418',
  84. 'title': '心みだれて〜say it with flowers〜(生音)',
  85. 'uploader_id': 'NjI1MjI2MjU',
  86. 'description': 'やっぱりキーを下げて正解だった感じ。リベンジ成功ということで。',
  87. 'uploader': '箱の「中の人」',
  88. 'upload_date': '20210815',
  89. 'view_count': 5,
  90. 'like_count': 3,
  91. 'track': '心みだれて〜say it with flowers〜(生音)',
  92. 'artist': '小林明子',
  93. },
  94. }]