[beatenpro] Simplify

pull/8/head
Sergey M․ 10 years ago
parent ba1d4c0488
commit fcd877013e

@ -2,9 +2,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import re import re
import json
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_str
from ..utils import int_or_none from ..utils import int_or_none
@ -46,10 +46,11 @@ class BeatportProIE(InfoExtractor):
webpage = self._download_webpage(url, display_id) webpage = self._download_webpage(url, display_id)
playables = self._search_regex( playables = self._parse_json(
r'window\.Playables\s*=\s*({.*?});', webpage, self._search_regex(
'playables info', flags=re.DOTALL) r'window\.Playables\s*=\s*({.+?});', webpage,
playables = json.loads(playables) 'playables info', flags=re.DOTALL),
track_id)
track = next(t for t in playables['tracks'] if t['id'] == int(track_id)) track = next(t for t in playables['tracks'] if t['id'] == int(track_id))
@ -59,7 +60,7 @@ class BeatportProIE(InfoExtractor):
formats = [] formats = []
for ext, info in track['preview'].items(): for ext, info in track['preview'].items():
if info['url'] is None: if not info['url']:
continue continue
fmt = { fmt = {
'url': info['url'], 'url': info['url'],
@ -85,16 +86,16 @@ class BeatportProIE(InfoExtractor):
image_url = info.get('url') image_url = info.get('url')
if name == 'dynamic' or not image_url: if name == 'dynamic' or not image_url:
continue continue
img = { image = {
'id': name, 'id': name,
'url': image_url, 'url': image_url,
'height': int_or_none(info.get('height')), 'height': int_or_none(info.get('height')),
'width': int_or_none(info.get('width')), 'width': int_or_none(info.get('width')),
} }
images.append(img) images.append(image)
return { return {
'id': track['id'], 'id': compat_str(track.get('id')) or track_id,
'display_id': track.get('slug') or display_id, 'display_id': track.get('slug') or display_id,
'title': title, 'title': title,
'formats': formats, 'formats': formats,

Loading…
Cancel
Save