changes accoring to review by @yan12125 at github pull #14687

This commit is contained in:
scil 2017-11-16 23:23:40 +08:00
parent 513ec05236
commit 714abc3278

View File

@ -1,13 +1,9 @@
# coding: utf-8
from __future__ import unicode_literals
import re
import itertools
from ..compat import (
compat_str,
)
import re
from .common import InfoExtractor
@ -24,7 +20,6 @@ class XimalayaIE(XimalayaBaseIE):
_TESTS = [
{
'url': 'http://www.ximalaya.com/61425525/sound/47740352/',
# 'md5': 'TODO: md5 sum of the first 10241 bytes of the video file (use --test)',
'info_dict': {
'id': '47740352',
'ext': 'm4a',
@ -61,7 +56,7 @@ class XimalayaIE(XimalayaBaseIE):
audio_info_file = 'http://m.ximalaya.com/tracks/%s.json' % audio_id
audio_info = self._download_json(audio_info_file, audio_id,
'Downloading info json %s' % audio_info_file,
'Unable to download info file', fatal=True)
'Unable to download info file')
formats = []
for bps, k in (('24k', 'play_path_32'), ('64k', 'play_path_64')):
@ -78,9 +73,9 @@ class XimalayaIE(XimalayaBaseIE):
audio_uploader_id = audio_info.get('uid')
if is_m:
intro = re.search(r'(?s)<section class=["\']content[^>]+>(.+)</section>', webpage)
intro = re.search(r'(?s)<section\s+class=["\']content[^>]+>(.+)</section>', webpage)
else:
intro = re.search(r'(?s)<div class="rich_intro"[^>]*>(.+?</article>)', webpage)
intro = re.search(r'(?s)<div\s+class=["\']rich_intro[^>]*>(.+?</article>)', webpage)
if intro:
audio_description = intro.group(1).strip()
@ -90,14 +85,14 @@ class XimalayaIE(XimalayaBaseIE):
note='Downloading description file %s' % audio_description_file,
errnote='Unable to download descrip file, try to parse web page',
fatal=False)
audio_description = audio_description.strip()
audio_description = audio_description.strip() if audio_description else None
return {
'id': audio_id,
'uploader': audio_info.get('nickname'),
'uploader_id': audio_uploader_id,
'uploader_url': self._USER_URL_FORMAT % audio_uploader_id,
'title': audio_info.get('title'),
'title': audio_info['title'],
'thumbnails': thumbnails,
'description': audio_description,
'categories': audio_info.get('category_title'),
@ -114,6 +109,7 @@ class XimalayaAlbumIE(XimalayaBaseIE):
_VALID_URL = r'https?://(?:www\.|m\.)?ximalaya\.com/(?P<uid>[0-9]+)/album/(?P<id>[0-9]+)/?'
_TEMPLATE_URL = 'http://www.ximalaya.com/%s/album/%s/'
_BASE_URL_TEMPL = 'http://www.ximalaya.com%s'
_LIST_VIDEO_RE = r'<a[^>]+?href="(?P<url>/%d/sound/(?P<id>\d+)/?)"[^>]+?title="(?P<title>[^>]+)">'
_TESTS = [{
'url': 'http://www.ximalaya.com/61425525/album/5534601/',
'info_dict': {
@ -132,15 +128,15 @@ class XimalayaAlbumIE(XimalayaBaseIE):
]
def _real_extract(self, url):
uid, playlist_id = self._match_uid_an_id(url)
assert uid.isdecimal()
mobj = re.match(self._VALID_URL, url)
uid, playlist_id = mobj.group('uid'), mobj.group('id')
webpage = self._download_webpage(self._TEMPLATE_URL % (uid, playlist_id), playlist_id,
note='Download album page for %s' % playlist_id,
errnote='Unable to get album info'
)
errnote='Unable to get album info')
mobj = re.search(r'detailContent_title(?:[^>]+)?><h1(?:[^>]+)?>([^<]+)</h1>', webpage)
title = mobj.group(1) if mobj else self._meta_regex('title')
title = mobj.group(1) if mobj else self._html_search_meta('title')
return self.playlist_result(self._entries(webpage, playlist_id, uid), playlist_id, title)
@ -150,7 +146,7 @@ class XimalayaAlbumIE(XimalayaBaseIE):
for entry in self._process_page(html, uid):
yield entry
mobj = re.search(r'<a href=(["\'])(?P<more>[^\'"]+)\1'
mobj = re.search(r'<a\s+href=(["\'])(?P<more>[^\'"]+)\1'
r'[^>]+rel=(["\'])next\3', html)
if not mobj:
break
@ -165,10 +161,7 @@ class XimalayaAlbumIE(XimalayaBaseIE):
def _process_page(self, html, uid):
find_from = html.index('album_soundlist')
for mobj in re.finditer(r'<a[^>]+?href="(?P<url>/' +
uid +
r'/sound/(?P<id>\d+)/?)"[^>]+?title="(?P<title>[^>]+)">',
html[find_from:]):
for mobj in re.finditer(self._LIST_VIDEO_RE % uid, html[find_from:]):
if 'url' in mobj.groupdict():
yield self.url_result(self._BASE_URL_TEMPL % mobj.group('url'),
'Ximalaya',
@ -179,6 +172,3 @@ class XimalayaAlbumIE(XimalayaBaseIE):
def _match_uid_an_id(cls, url):
if '_VALID_URL_RE' not in cls.__dict__:
cls._VALID_URL_RE = re.compile(cls._VALID_URL)
m = cls._VALID_URL_RE.match(url)
assert m
return compat_str(m.group('uid')), compat_str(m.group('id'))