Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mixcloud] Add support for new frontend #14132

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review issues
  • Loading branch information
ishitatsuyuki committed Sep 13, 2017
commit 7ab078eae9d34687e0a3db3e76e79cff6316a677
51 changes: 24 additions & 27 deletions youtube_dl/extractor/mixcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ExtractorError,
OnDemandPagedList,
str_to_int,
)
try_get)


class MixcloudIE(InfoExtractor):
Expand Down Expand Up @@ -81,12 +81,8 @@ def _real_extract(self, url):
full_info_json = self._parse_json(self._html_search_regex(
r'<script id="relay-data" type="text/x-mixcloud">([^<]+)</script>', webpage, 'play info'), 'play info')
for item in full_info_json:
item_data = item.get("cloudcast", {}) \
.get("data", {}) \
.get("cloudcastLookup", {})
if item_data \
.get("streamInfo", {}) \
.get("url", "") != "":
item_data = try_get(item, lambda x: x['cloudcast']['data']['cloudcastLookup'])
if try_get(item_data, lambda x: x['streamInfo']['url']) not in ['', None]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if try_get(item_data, lambda x: x['streamInfo']['url']) is enough.

info_json = item_data
break

Expand All @@ -108,7 +104,7 @@ def _real_extract(self, url):
kpa_target = encrypted_play_info
else:
kp = 'https://'
kpa_target = base64.b64decode(info_json["streamInfo"]["url"])
kpa_target = base64.b64decode(info_json['streamInfo']['url'])
partial_key = self._decrypt_xor_cipher(kpa_target, kp)
for quote in ["'", '"']:
key = self._search_regex(r'{0}({1}[^{0}]*){0}'.format(quote, re.escape(partial_key)), js,
Expand Down Expand Up @@ -142,25 +138,26 @@ def _real_extract(self, url):

else:
title = info_json['name']
thumbnail = 'https://thumbnailer.mixcloud.com/unsafe/600x600/' + info_json['picture']['urlRoot']
uploader = info_json['owner']['displayName']
uploader_id = info_json['owner']['username']
description = info_json['description']
view_count = info_json['plays']
formats = [
{
'format_id': 'normal',
'url': self._decrypt_xor_cipher(key, base64.b64decode(info_json['streamInfo']['url']))
},
{
'format_id': 'hls',
'url': self._decrypt_xor_cipher(key, base64.b64decode(info_json['streamInfo']['hlsUrl']))
},
{
'format_id': 'dash',
'url': self._decrypt_xor_cipher(key, base64.b64decode(info_json['streamInfo']['dashUrl']))
}
]
thumbnail = try_get(info_json,
lambda x: 'https://thumbnailer.mixcloud.com/unsafe/600x600/' + x['picture']['urlRoot'])
uploader = try_get(info_json, lambda x: x['owner']['displayName'])
uploader_id = try_get(info_json, lambda x: x['owner']['username'])
description = try_get(info_json, lambda x: x['description'])
view_count = try_get(info_json, lambda x: x['plays'])
formats = [{
'format_id': 'normal',
'url': self._decrypt_xor_cipher(key, base64.b64decode(info_json['streamInfo']['url']))
}]

hls_encrypted = try_get(info_json, lambda x: x['streamInfo']['hlsUrl'])
if hls_encrypted is not None:
hls_url = self._decrypt_xor_cipher(key, base64.b64decode(hls_encrypted))
formats.extend(self._extract_m3u8_formats(hls_url, title))

dash_encrypted = try_get(info_json, lambda x: x['streamInfo']['dashUrl'])
if dash_encrypted is not None:
dash_url = self._decrypt_xor_cipher(key, base64.b64decode(dash_encrypted))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

157, 160-162, 165-167 code duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you suggest then? The duplication is minimal.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracting duplicate code into a function obviously.

formats.extend(self._extract_mpd_formats(dash_url, title))

return {
'id': track_id,
Expand Down