aboutsummaryrefslogtreecommitdiffhomepage
path: root/youtube_dl/extractor
diff options
context:
space:
mode:
authorYen Chi Hsuan <[email protected]>2015-03-19 01:47:07 +0800
committerYen Chi Hsuan <[email protected]>2015-04-16 17:34:54 +0800
commit5edea45fab73874c269655b4cf08da0bbc5ea479 (patch)
tree75685d2d0b2d8725cf91d2c82ff4b629a8d1c1ce /youtube_dl/extractor
parent8afff9f849e43c9c4194e302c06b5bec38edd83f (diff)
downloadyoutube-dl-5edea45fab73874c269655b4cf08da0bbc5ea479.tar.gz
youtube-dl-5edea45fab73874c269655b4cf08da0bbc5ea479.zip
[QQMusic] Add album info extractor
Diffstat (limited to 'youtube_dl/extractor')
-rw-r--r--youtube_dl/extractor/__init__.py3
-rw-r--r--youtube_dl/extractor/qqmusic.py72
2 files changed, 63 insertions, 12 deletions
diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py
index 65dbcb6cf..36860f72c 100644
--- a/youtube_dl/extractor/__init__.py
+++ b/youtube_dl/extractor/__init__.py
@@ -398,7 +398,8 @@ from .puls4 import Puls4IE
from .pyvideo import PyvideoIE
from .qqmusic import (
QQMusicIE,
- QQMusicSingerIE
+ QQMusicSingerIE,
+ QQMusicAlbumIE,
)
from .quickvid import QuickVidIE
from .r7 import R7IE
diff --git a/youtube_dl/extractor/qqmusic.py b/youtube_dl/extractor/qqmusic.py
index 1c22943a5..d0ea4a769 100644
--- a/youtube_dl/extractor/qqmusic.py
+++ b/youtube_dl/extractor/qqmusic.py
@@ -6,7 +6,10 @@ import time
import re
from .common import InfoExtractor
-from ..utils import strip_jsonp
+from ..utils import (
+ strip_jsonp,
+ unescapeHTML,
+)
from ..compat import compat_urllib_request
@@ -66,7 +69,28 @@ class QQMusicIE(InfoExtractor):
}
-class QQMusicSingerIE(InfoExtractor):
+class QQPlaylistBaseIE(InfoExtractor):
+ @staticmethod
+ def qq_static_url(category, mid):
+ return 'http://y.qq.com/y/static/%s/%s/%s/%s.html' % (category, mid[-2], mid[-1], mid)
+
+ @staticmethod
+ def qq_song_url(mid):
+ return 'http://y.qq.com/#type=song&mid=%s' % mid
+
+ @classmethod
+ def get_entries_from_page(cls, page):
+ entries = []
+
+ for item in re.findall(r'class="data"[^<>]*>([^<>]+)</', page):
+ song_mid = unescapeHTML(item).split('|')[-5]
+ entries.append(cls.url_result(
+ cls.qq_song_url(song_mid), 'QQMusic', song_mid))
+
+ return entries
+
+
+class QQMusicSingerIE(QQPlaylistBaseIE):
_VALID_URL = r'http://y.qq.com/#type=singer&mid=(?P<id>[0-9A-Za-z]+)'
_TEST = {
'url': 'http://y.qq.com/#type=singer&mid=001BLpXF2DyJe2',
@@ -82,15 +106,9 @@ class QQMusicSingerIE(InfoExtractor):
mid = self._match_id(url)
singer_page = self._download_webpage(
- 'http://y.qq.com/y/static/singer/%s/%s/%s.html' % (mid[-2], mid[-1], mid),
- 'Download singer page')
-
- entries = []
+ self.qq_static_url('singer', mid), mid, 'Download singer page')
- for item in re.findall(r'<span class="data">([^<>]+)</span>', singer_page):
- song_mid = item.split('|')[-5]
- entries.append(self.url_result(
- 'http://y.qq.com/#type=song&mid=' + song_mid, 'QQMusic', song_mid))
+ entries = self.get_entries_from_page(singer_page)
singer_name = self._html_search_regex(
r"singername\s*:\s*'([^']+)'", singer_page, 'singer name',
@@ -108,8 +126,40 @@ class QQMusicSingerIE(InfoExtractor):
req.add_header(
'Referer', 'http://s.plcloud.music.qq.com/xhr_proxy_utf8.html')
singer_desc_page = self._download_xml(
- req, 'Donwload singer description XML')
+ req, mid, 'Donwload singer description XML')
singer_desc = singer_desc_page.find('./data/info/desc').text
return self.playlist_result(entries, mid, singer_name, singer_desc)
+
+
+class QQMusicAlbumIE(QQPlaylistBaseIE):
+ _VALID_URL = r'http://y.qq.com/#type=album&mid=(?P<id>[0-9A-Za-z]+)'
+
+ _TEST = {
+ 'url': 'http://y.qq.com/#type=album&mid=000gXCTb2AhRR1&play=0',
+ 'info_dict': {
+ 'id': '000gXCTb2AhRR1',
+ 'title': '我们都是这样长大的',
+ 'description': 'md5:d216c55a2d4b3537fe4415b8767d74d6',
+ },
+ 'playlist_count': 4,
+ }
+
+ def _real_extract(self, url):
+ mid = self._match_id(url)
+
+ album_page = self._download_webpage(
+ self.qq_static_url('album', mid), mid, 'Download album page')
+
+ entries = self.get_entries_from_page(album_page)
+
+ album_name = self._html_search_regex(
+ r"albumname\s*:\s*'([^']+)',", album_page, 'album name',
+ default=None)
+
+ album_detail = self._html_search_regex(
+ r'<div class="album_detail close_detail">\s*<p>((?:[^<>]+(?:<br />)?)+)</p>',
+ album_page, 'album details', default=None)
+
+ return self.playlist_result(entries, mid, album_name, album_detail)