piapro.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. from .common import InfoExtractor
  2. from ..compat import compat_urlparse
  3. from ..utils import (
  4. ExtractorError,
  5. parse_duration,
  6. parse_filesize,
  7. str_to_int,
  8. unified_timestamp,
  9. urlencode_postdata,
  10. )
  11. class PiaproIE(InfoExtractor):
  12. _NETRC_MACHINE = 'piapro'
  13. _VALID_URL = r'https?://piapro\.jp/t/(?P<id>\w+)/?'
  14. _TESTS = [{
  15. 'url': 'https://piapro.jp/t/NXYR',
  16. 'md5': 'a9d52f27d13bafab7ee34116a7dcfa77',
  17. 'info_dict': {
  18. 'id': 'NXYR',
  19. 'ext': 'mp3',
  20. 'uploader': 'wowaka',
  21. 'uploader_id': 'wowaka',
  22. 'title': '裏表ラバーズ',
  23. 'thumbnail': r're:^https?://.*\.jpg$',
  24. }
  25. }, {
  26. 'note': 'There are break lines in description, mandating (?s) flag',
  27. 'url': 'https://piapro.jp/t/9cSd',
  28. 'md5': '952bb6d1e8de95050206408a87790676',
  29. 'info_dict': {
  30. 'id': '9cSd',
  31. 'ext': 'mp3',
  32. 'title': '青に溶けた風船 / 初音ミク',
  33. 'description': 'md5:d395a9bd151447631a5a1460bc7f9132',
  34. 'uploader': 'シアン・キノ',
  35. 'uploader_id': 'cyankino',
  36. }
  37. }]
  38. _login_status = False
  39. def _perform_login(self, username, password):
  40. login_ok = True
  41. login_form_strs = {
  42. '_username': username,
  43. '_password': password,
  44. '_remember_me': 'on',
  45. 'login': 'ログイン'
  46. }
  47. self._request_webpage('https://piapro.jp/login/', None)
  48. urlh = self._request_webpage(
  49. 'https://piapro.jp/login/exe', None,
  50. note='Logging in', errnote='Unable to log in',
  51. data=urlencode_postdata(login_form_strs))
  52. if urlh is False:
  53. login_ok = False
  54. else:
  55. parts = compat_urlparse.urlparse(urlh.geturl())
  56. if parts.path != '/':
  57. login_ok = False
  58. if not login_ok:
  59. self.report_warning(
  60. 'unable to log in: bad username or password')
  61. self._login_status = login_ok
  62. def _real_extract(self, url):
  63. video_id = self._match_id(url)
  64. webpage = self._download_webpage(url, video_id)
  65. category_id = self._search_regex(r'categoryId=(.+)">', webpage, 'category ID')
  66. if category_id not in ('1', '2', '21', '22', '23', '24', '25'):
  67. raise ExtractorError('The URL does not contain audio.', expected=True)
  68. str_duration, str_filesize = self._search_regex(
  69. r'サイズ:</span>(.+?)/\(([0-9,]+?[KMG]?B))', webpage, 'duration and size',
  70. group=(1, 2), default=(None, None))
  71. str_viewcount = self._search_regex(r'閲覧数:</span>([0-9,]+)\s+', webpage, 'view count', fatal=False)
  72. uploader_id, uploader = self._search_regex(
  73. r'<a\s+class="cd_user-name"\s+href="/(.*)">([^<]+)さん<', webpage, 'uploader',
  74. group=(1, 2), default=(None, None))
  75. content_id = self._search_regex(r'contentId\:\'(.+)\'', webpage, 'content ID')
  76. create_date = self._search_regex(r'createDate\:\'(.+)\'', webpage, 'timestamp')
  77. player_webpage = self._download_webpage(
  78. f'https://piapro.jp/html5_player_popup/?id={content_id}&cdate={create_date}',
  79. video_id, note='Downloading player webpage')
  80. return {
  81. 'id': video_id,
  82. 'title': self._html_search_regex(r'<h1\s+class="cd_works-title">(.+?)</h1>', webpage, 'title', fatal=False),
  83. 'description': self._html_search_regex(r'(?s)<p\s+class="cd_dtl_cap">(.+?)</p>\s*<div', webpage, 'description', fatal=False),
  84. 'uploader': uploader,
  85. 'uploader_id': uploader_id,
  86. 'timestamp': unified_timestamp(create_date, False),
  87. 'duration': parse_duration(str_duration),
  88. 'view_count': str_to_int(str_viewcount),
  89. 'thumbnail': self._html_search_meta('twitter:image', webpage),
  90. 'filesize_approx': parse_filesize(str_filesize.replace(',', '')),
  91. 'url': self._search_regex(r'mp3:\s*\'(.*?)\'\}', player_webpage, 'url'),
  92. 'ext': 'mp3',
  93. 'vcodec': 'none',
  94. }