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.

99 lines
3.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_urllib_parse_urlparse
  5. from ..utils import (
  6. int_or_none,
  7. mimetype2ext,
  8. remove_end,
  9. url_or_none,
  10. )
  11. class IwaraIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.|ecchi\.)?iwara\.tv/videos/(?P<id>[a-zA-Z0-9]+)'
  13. _TESTS = [{
  14. 'url': 'http://iwara.tv/videos/amVwUl1EHpAD9RD',
  15. # md5 is unstable
  16. 'info_dict': {
  17. 'id': 'amVwUl1EHpAD9RD',
  18. 'ext': 'mp4',
  19. 'title': '【MMD R-18】ガールフレンド carry_me_off',
  20. 'age_limit': 18,
  21. },
  22. }, {
  23. 'url': 'http://ecchi.iwara.tv/videos/Vb4yf2yZspkzkBO',
  24. 'md5': '7e5f1f359cd51a027ba4a7b7710a50f0',
  25. 'info_dict': {
  26. 'id': '0B1LvuHnL-sRFNXB1WHNqbGw4SXc',
  27. 'ext': 'mp4',
  28. 'title': '[3D Hentai] Kyonyu × Genkai × Emaki Shinobi Girls.mp4',
  29. 'age_limit': 18,
  30. },
  31. 'add_ie': ['GoogleDrive'],
  32. }, {
  33. 'url': 'http://www.iwara.tv/videos/nawkaumd6ilezzgq',
  34. # md5 is unstable
  35. 'info_dict': {
  36. 'id': '6liAP9s2Ojc',
  37. 'ext': 'mp4',
  38. 'age_limit': 18,
  39. 'title': '[MMD] Do It Again Ver.2 [1080p 60FPS] (Motion,Camera,Wav+DL)',
  40. 'description': 'md5:590c12c0df1443d833fbebe05da8c47a',
  41. 'upload_date': '20160910',
  42. 'uploader': 'aMMDsork',
  43. 'uploader_id': 'UCVOFyOSCyFkXTYYHITtqB7A',
  44. },
  45. 'add_ie': ['Youtube'],
  46. }]
  47. def _real_extract(self, url):
  48. video_id = self._match_id(url)
  49. webpage, urlh = self._download_webpage_handle(url, video_id)
  50. hostname = compat_urllib_parse_urlparse(urlh.geturl()).hostname
  51. # ecchi is 'sexy' in Japanese
  52. age_limit = 18 if hostname.split('.')[0] == 'ecchi' else 0
  53. video_data = self._download_json('http://www.iwara.tv/api/video/%s' % video_id, video_id)
  54. if not video_data:
  55. iframe_url = self._html_search_regex(
  56. r'<iframe[^>]+src=([\'"])(?P<url>[^\'"]+)\1',
  57. webpage, 'iframe URL', group='url')
  58. return {
  59. '_type': 'url_transparent',
  60. 'url': iframe_url,
  61. 'age_limit': age_limit,
  62. }
  63. title = remove_end(self._html_search_regex(
  64. r'<title>([^<]+)</title>', webpage, 'title'), ' | Iwara')
  65. formats = []
  66. for a_format in video_data:
  67. format_uri = url_or_none(a_format.get('uri'))
  68. if not format_uri:
  69. continue
  70. format_id = a_format.get('resolution')
  71. height = int_or_none(self._search_regex(
  72. r'(\d+)p', format_id, 'height', default=None))
  73. formats.append({
  74. 'url': self._proto_relative_url(format_uri, 'https:'),
  75. 'format_id': format_id,
  76. 'ext': mimetype2ext(a_format.get('mime')) or 'mp4',
  77. 'height': height,
  78. 'width': int_or_none(height / 9.0 * 16.0 if height else None),
  79. 'quality': 1 if format_id == 'Source' else 0,
  80. })
  81. self._sort_formats(formats)
  82. return {
  83. 'id': video_id,
  84. 'title': title,
  85. 'age_limit': age_limit,
  86. 'formats': formats,
  87. }