[mixcloud] Fix extraction by decrypting play info

Fixes #7521
This commit is contained in:
Yen Chi Hsuan 2016-04-15 15:42:00 +08:00
parent c773082692
commit dd91dfcd67
No known key found for this signature in database
GPG Key ID: 3FDDD575826C5C30

View File

@ -1,19 +1,20 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import base64
import functools import functools
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import ( from ..compat import (
compat_chr,
compat_ord,
compat_urllib_parse_unquote, compat_urllib_parse_unquote,
compat_urlparse, compat_urlparse,
) )
from ..utils import ( from ..utils import (
clean_html, clean_html,
ExtractorError, ExtractorError,
HEADRequest,
OnDemandPagedList, OnDemandPagedList,
NO_DEFAULT,
parse_count, parse_count,
str_to_int, str_to_int,
) )
@ -45,22 +46,22 @@ class MixcloudIE(InfoExtractor):
'description': 'md5:2b8aec6adce69f9d41724647c65875e8', 'description': 'md5:2b8aec6adce69f9d41724647c65875e8',
'uploader': 'Gilles Peterson Worldwide', 'uploader': 'Gilles Peterson Worldwide',
'uploader_id': 'gillespeterson', 'uploader_id': 'gillespeterson',
'thumbnail': 're:https?://.*/images/', 'thumbnail': 're:https?://.*',
'view_count': int, 'view_count': int,
'like_count': int, 'like_count': int,
}, },
}] }]
def _check_url(self, url, track_id, ext): # See https://www.mixcloud.com/media/js2/www_js_2.9e23256562c080482435196ca3975ab5.js
try: @staticmethod
# We only want to know if the request succeed def _decrypt_play_info(play_info):
# don't download the whole file KEY = 'pleasedontdownloadourmusictheartistswontgetpaid'
self._request_webpage(
HEADRequest(url), track_id, play_info = base64.b64decode(play_info.encode('ascii'))
'Trying %s URL' % ext)
return True return ''.join([
except ExtractorError: compat_chr(compat_ord(ch) ^ compat_ord(KEY[idx % len(KEY)]))
return False for idx, ch in enumerate(play_info)])
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
@ -74,19 +75,15 @@ class MixcloudIE(InfoExtractor):
r'(?s)<div[^>]+class="global-message cloudcast-disabled-notice-light"[^>]*>(.+?)<(?:a|/div)', r'(?s)<div[^>]+class="global-message cloudcast-disabled-notice-light"[^>]*>(.+?)<(?:a|/div)',
webpage, 'error message', default=None) webpage, 'error message', default=None)
preview_url = self._search_regex( encrypted_play_info = self._search_regex(
r'\s(?:data-preview-url|m-preview)="([^"]+)"', r'm-play-info="([^"]+)"', webpage, 'play info')
webpage, 'preview url', default=None if message else NO_DEFAULT) play_info = self._parse_json(
self._decrypt_play_info(encrypted_play_info), track_id)
if message: if message and 'stream_url' not in play_info:
raise ExtractorError('%s said: %s' % (self.IE_NAME, message), expected=True) raise ExtractorError('%s said: %s' % (self.IE_NAME, message), expected=True)
song_url = re.sub(r'audiocdn(\d+)', r'stream\1', preview_url) song_url = play_info['stream_url']
song_url = song_url.replace('/previews/', '/c/originals/')
if not self._check_url(song_url, track_id, 'mp3'):
song_url = song_url.replace('.mp3', '.m4a').replace('originals/', 'm4a/64/')
if not self._check_url(song_url, track_id, 'm4a'):
raise ExtractorError('Unable to extract track url')
PREFIX = ( PREFIX = (
r'm-play-on-spacebar[^>]+' r'm-play-on-spacebar[^>]+'