diff --git a/youtube_dl/downloader/http.py b/youtube_dl/downloader/http.py index f79e6a995..d01d1897e 100644 --- a/youtube_dl/downloader/http.py +++ b/youtube_dl/downloader/http.py @@ -27,8 +27,16 @@ class HttpFD(FileDownloader): headers['Youtubedl-user-agent'] = info_dict['user_agent'] if 'http_referer' in info_dict: headers['Referer'] = info_dict['http_referer'] - basic_request = compat_urllib_request.Request(url, None, headers) - request = compat_urllib_request.Request(url, None, headers) + add_headers = info_dict.get('http_headers') + if add_headers: + headers.update(add_headers) + data = info_dict.get('http_post_data') + http_method = info_dict.get('http_method') + basic_request = compat_urllib_request.Request(url, data, headers) + request = compat_urllib_request.Request(url, data, headers) + if http_method is not None: + basic_request.get_method = lambda: http_method + request.get_method = lambda: http_method is_test = self.params.get('test', False) diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index 2e6eeac08..9d85a538c 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -84,6 +84,12 @@ class InfoExtractor(object): format, irrespective of the file format. -1 for default (order by other properties), -2 or smaller for less than default. + * http_referer HTTP Referer header value to set. + * http_method HTTP method to use for the download. + * http_headers A dictionary of additional HTTP headers + to add to the request. + * http_post_data Additional data to send with a POST + request. url: Final video URL. ext: Video filename extension. format: The video format, defaults to ext (used for --get-format) diff --git a/youtube_dl/extractor/grooveshark.py b/youtube_dl/extractor/grooveshark.py index 77c5a9172..1f2c65afe 100644 --- a/youtube_dl/extractor/grooveshark.py +++ b/youtube_dl/extractor/grooveshark.py @@ -12,7 +12,7 @@ from .common import InfoExtractor from ..utils import ExtractorError, compat_urllib_request, compat_html_parser from ..utils import compat_urlparse -urlparse = compat_urlparse.urlparse + urlunparse = compat_urlparse.urlunparse urldefrag = compat_urlparse.urldefrag @@ -52,7 +52,7 @@ class GroovesharkIE(InfoExtractor): 'id': '6SS1DW', 'title': 'Jolene (Tenth Key Remix ft. Will Sessions)', 'ext': 'mp3', - 'duration': 227 + 'duration': 227, } } @@ -60,7 +60,7 @@ class GroovesharkIE(InfoExtractor): do_bootstrap_request = True def _parse_target(self, target): - uri = urlparse(target) + uri = compat_urlparse.urlparse(target) hash = uri.fragment[1:].split('?')[0] token = basename(hash.rstrip('/')) return (uri, hash, token) @@ -123,22 +123,36 @@ class GroovesharkIE(InfoExtractor): def _get_playerpage(self, target): (_, _, token) = self._parse_target(target) - res = self._download_webpage( + + webpage = self._download_webpage( target, token, note='Downloading player page', errnote='Unable to download player page', fatal=False) - if res is not None: - o = GroovesharkHtmlParser.extract_object_tags(res) - return (res, [x for x in o if x['attrs']['id'] == 'jsPlayerEmbed']) + if webpage is not None: + # Search (for example German) error message + error_msg = self._html_search_regex( + r'