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.

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