From e3fc3290f3673e486bb88d770e077ca014b1a6a6 Mon Sep 17 00:00:00 2001 From: Koki Takahashi Date: Sun, 15 Jan 2017 14:07:32 +0900 Subject: [PATCH 1/4] [Iwara] Fix download --- youtube_dl/extractor/iwara.py | 57 ++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/youtube_dl/extractor/iwara.py b/youtube_dl/extractor/iwara.py index 8d7e7f472..193260ea6 100644 --- a/youtube_dl/extractor/iwara.py +++ b/youtube_dl/extractor/iwara.py @@ -52,26 +52,49 @@ class IwaraIE(InfoExtractor): # ecchi is 'sexy' in Japanese age_limit = 18 if hostname.split('.')[0] == 'ecchi' else 0 - entries = self._parse_html5_media_entries(url, webpage, video_id) - - if not entries: - iframe_url = self._html_search_regex( - r']+src=([\'"])(?P[^\'"]+)\1', - webpage, 'iframe URL', group='url') - return { - '_type': 'url_transparent', - 'url': iframe_url, - 'age_limit': age_limit, - } - title = remove_end(self._html_search_regex( r'([^<]+)', webpage, 'title'), ' | Iwara') - info_dict = entries[0] - info_dict.update({ + api_url = 'http://%s/api/video/%s' % (hostname, video_id) + + raw_formats = self._download_json( + api_url, video_id, + note='Downloading formats') + + formats = [] + + for raw_format in raw_formats: + new_format = { + 'url': raw_format['uri'], + 'resolution': raw_format['resolution'], + 'format_id': raw_format['resolution'], + } + + if raw_format['resolution'] == '1080p': + height = 1080 + elif raw_format['resolution'] == '720p': + height = 720 + elif raw_format['resolution'] == '540p': + height = 540 + elif raw_format['resolution'] == '360p': + height = 360 + else: + height = None + + if height is not None: + new_format['width'] = int(height / 9.0 * 16.0) + new_format['height'] = height + + if raw_format['mime'] == 'video/mp4': + new_format['ext'] = 'mp4' + + formats.append(new_format) + + self._sort_formats(formats) + + return { 'id': video_id, 'title': title, 'age_limit': age_limit, - }) - - return info_dict + 'formats': formats, + } From c44ba1935a49d0ecc70cc81f7698187a23ea1515 Mon Sep 17 00:00:00 2001 From: Koki Takahashi Date: Sun, 15 Jan 2017 14:27:37 +0900 Subject: [PATCH 2/4] [Iwara] Fix test assets and restore url_transparent extraction --- youtube_dl/extractor/iwara.py | 40 +++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/iwara.py b/youtube_dl/extractor/iwara.py index 193260ea6..425d17ba4 100644 --- a/youtube_dl/extractor/iwara.py +++ b/youtube_dl/extractor/iwara.py @@ -10,13 +10,22 @@ class IwaraIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.|ecchi\.)?iwara\.tv/videos/(?P[a-zA-Z0-9]+)' _TESTS = [{ 'url': 'http://iwara.tv/videos/amVwUl1EHpAD9RD', - 'md5': '1d53866b2c514b23ed69e4352fdc9839', + 'md5': 'c9c35657eff2fda5af7f78e69637d2d6', 'info_dict': { 'id': 'amVwUl1EHpAD9RD', 'ext': 'mp4', 'title': '【MMD R-18】ガールフレンド carry_me_off', 'age_limit': 18, }, + }, { + 'url': 'http://www.iwara.tv/videos/64zbul0qujvjavm', + 'md5': '727d0f869035247781469aa7a06e2365', + 'info_dict': { + 'id': '64zbul0qujvjavm', + 'ext': 'mp4', + 'title': 'レアさん Dark Sea Adventure', + 'age_limit': 0, + }, }, { 'url': 'http://ecchi.iwara.tv/videos/Vb4yf2yZspkzkBO', 'md5': '7e5f1f359cd51a027ba4a7b7710a50f0', @@ -28,12 +37,12 @@ class IwaraIE(InfoExtractor): }, 'add_ie': ['GoogleDrive'], }, { - 'url': 'http://www.iwara.tv/videos/nawkaumd6ilezzgq', - 'md5': '1d85f1e5217d2791626cff5ec83bb189', + 'url': 'http://ecchi.iwara.tv/videos/nawkaumd6ilezzgq', + 'md5': '729a1e0a830469fe2c56d20aed06f852', 'info_dict': { 'id': '6liAP9s2Ojc', 'ext': 'mp4', - 'age_limit': 0, + 'age_limit': 18, 'title': '[MMD] Do It Again Ver.2 [1080p 60FPS] (Motion,Camera,Wav+DL)', 'description': 'md5:590c12c0df1443d833fbebe05da8c47a', 'upload_date': '20160910', @@ -55,6 +64,29 @@ class IwaraIE(InfoExtractor): title = remove_end(self._html_search_regex( r'([^<]+)', webpage, 'title'), ' | Iwara') + entries = self._parse_html5_media_entries(url, webpage, video_id) + + if entries: + info_dict = entries[0] + info_dict.update({ + 'id': video_id, + 'title': title, + 'age_limit': age_limit, + }) + + return info_dict + + iframe_url = self._html_search_regex( + r']+src=([\'"])(?P[^\'"]+)\1', + webpage, 'iframe URL', group='url', default=None) + + if iframe_url: + return { + '_type': 'url_transparent', + 'url': iframe_url, + 'age_limit': age_limit, + } + api_url = 'http://%s/api/video/%s' % (hostname, video_id) raw_formats = self._download_json( From 39cca0ef397007329f6993d12330153de1eef017 Mon Sep 17 00:00:00 2001 From: Koki Takahashi Date: Sun, 15 Jan 2017 14:36:09 +0900 Subject: [PATCH 3/4] [Iwara] Fix coding style --- youtube_dl/extractor/iwara.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/youtube_dl/extractor/iwara.py b/youtube_dl/extractor/iwara.py index 425d17ba4..2d47d184c 100644 --- a/youtube_dl/extractor/iwara.py +++ b/youtube_dl/extractor/iwara.py @@ -102,13 +102,13 @@ class IwaraIE(InfoExtractor): 'format_id': raw_format['resolution'], } - if raw_format['resolution'] == '1080p': + if raw_format.get('resolution') == '1080p': height = 1080 - elif raw_format['resolution'] == '720p': + elif raw_format.get('resolution') == '720p': height = 720 - elif raw_format['resolution'] == '540p': + elif raw_format.get('resolution') == '540p': height = 540 - elif raw_format['resolution'] == '360p': + elif raw_format.get('resolution') == '360p': height = 360 else: height = None @@ -117,7 +117,7 @@ class IwaraIE(InfoExtractor): new_format['width'] = int(height / 9.0 * 16.0) new_format['height'] = height - if raw_format['mime'] == 'video/mp4': + if raw_format.get('mime') == 'video/mp4': new_format['ext'] = 'mp4' formats.append(new_format) From 04f5d7a32cd5296961f8678b8f70e219dac6dcd5 Mon Sep 17 00:00:00 2001 From: Koki Takahashi Date: Sun, 15 Jan 2017 15:11:21 +0900 Subject: [PATCH 4/4] [Iwara] Fix coding styles --- youtube_dl/extractor/iwara.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/youtube_dl/extractor/iwara.py b/youtube_dl/extractor/iwara.py index 2d47d184c..2b6cb27b0 100644 --- a/youtube_dl/extractor/iwara.py +++ b/youtube_dl/extractor/iwara.py @@ -3,7 +3,10 @@ from __future__ import unicode_literals from .common import InfoExtractor from ..compat import compat_urllib_parse_urlparse -from ..utils import remove_end +from ..utils import ( + remove_end, + mimetype2ext, +) class IwaraIE(InfoExtractor): @@ -97,9 +100,9 @@ class IwaraIE(InfoExtractor): for raw_format in raw_formats: new_format = { - 'url': raw_format['uri'], - 'resolution': raw_format['resolution'], - 'format_id': raw_format['resolution'], + 'url': raw_format.get('uri'), + 'resolution': raw_format.get('resolution'), + 'format_id': raw_format.get('resolution'), } if raw_format.get('resolution') == '1080p': @@ -117,8 +120,8 @@ class IwaraIE(InfoExtractor): new_format['width'] = int(height / 9.0 * 16.0) new_format['height'] = height - if raw_format.get('mime') == 'video/mp4': - new_format['ext'] = 'mp4' + if raw_format.get('mime'): + new_format['ext'] = mimetype2ext(raw_format.get('mime')) formats.append(new_format)