mirror of
https://github.com/soimort/you-get.git
synced 2025-02-02 16:24:00 +03:00
add support for Baidu Music (with lyrics), fix #1
This commit is contained in:
parent
215ce0fdbc
commit
e4f10358bc
@ -44,6 +44,7 @@ Fork me on GitHub: <https://github.com/soimort/you-get>
|
||||
* Sohu (搜狐视频) <http://tv.sohu.com>
|
||||
* 56 (56网) <http://www.56.com>
|
||||
* Xiami (虾米) <http://www.xiami.com>
|
||||
* Baidu (百度音乐) <http://music.baidu.com>
|
||||
|
||||
## Dependencies
|
||||
|
||||
@ -255,6 +256,8 @@ You-Get基于优酷下载脚本[iambus/youku-lixian](https://github.com/iambus/y
|
||||
* 搜狐视频 <http://tv.sohu.com>
|
||||
* 56网 <http://www.56.com>
|
||||
* 虾米 <http://www.xiami.com>
|
||||
* 百度音乐 <http://music.baidu.com>
|
||||
|
||||
|
||||
## 依赖
|
||||
|
||||
|
@ -47,6 +47,7 @@ Supported Sites (As of Now)
|
||||
* Sohu (搜狐视频) http://tv.sohu.com
|
||||
* 56 (56网) http://www.56.com
|
||||
* Xiami (虾米) http://www.xiami.com
|
||||
* Baidu (百度音乐) <http://music.baidu.com>
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
@ -50,6 +50,7 @@ def url_to_module(url):
|
||||
'vimeo': vimeo,
|
||||
'vine': vine,
|
||||
'xiami': xiami,
|
||||
'baidu': baidu,
|
||||
'yinyuetai': yinyuetai,
|
||||
'youku': youku,
|
||||
'youtu': youtube,
|
||||
|
@ -29,6 +29,7 @@ from .vimeo import *
|
||||
from .vine import *
|
||||
from .w56 import *
|
||||
from .xiami import *
|
||||
from .baidu import *
|
||||
from .yinyuetai import *
|
||||
from .youku import *
|
||||
from .youtube import *
|
||||
|
78
src/you_get/downloader/baidu.py
Executable file
78
src/you_get/downloader/baidu.py
Executable file
@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
__all__ = ['baidu_download']
|
||||
|
||||
from ..common import *
|
||||
|
||||
from urllib import parse
|
||||
|
||||
def baidu_get_song_html(sid):
|
||||
return get_html('http://music.baidu.com/song/%s/download?__o=%%2Fsong%%2F%s' % (sid, sid), faker = True)
|
||||
|
||||
def baidu_get_song_url(html):
|
||||
return r1(r'<a href="/data/music/file\?link=(.*)" id="download"', html)
|
||||
|
||||
def baidu_get_song_artist(html):
|
||||
return r1(r'singer_name:"(.*)"', html)
|
||||
|
||||
def baidu_get_song_album(html):
|
||||
return r1(r'ablum_name:"(.*)"', html)
|
||||
|
||||
def baidu_get_song_title(html):
|
||||
return r1(r'song_title:"(.*)"', html)
|
||||
|
||||
def baidu_download_lyric(sid, file_name, output_dir):
|
||||
html = get_html('http://music.baidu.com/song/' + sid)
|
||||
href = r1(r'<a class="down-lrc-btn" data-lyricdata=\'{ "href":"(.*)" }\' href="#">', html)
|
||||
if href:
|
||||
lrc = get_html('http://music.baidu.com' + href)
|
||||
if len(lrc) > 0:
|
||||
with open(output_dir + "/" + file_name.replace('/', '-') + '.lrc', 'w') as x:
|
||||
x.write(lrc)
|
||||
|
||||
def baidu_download_song(sid, output_dir = '.', merge = True, info_only = False):
|
||||
html = baidu_get_song_html(sid)
|
||||
url = baidu_get_song_url(html)
|
||||
title = baidu_get_song_title(html)
|
||||
artist = baidu_get_song_artist(html)
|
||||
album = baidu_get_song_album(html)
|
||||
type, ext, size = url_info(url, faker = True)
|
||||
print_info(site_info, title, type, size)
|
||||
if not info_only:
|
||||
file_name = "%s - %s - %s" % (title, album, artist)
|
||||
download_urls([url], file_name, ext, size, output_dir, merge = merge, faker = True)
|
||||
baidu_download_lyric(sid, file_name, output_dir)
|
||||
|
||||
def baidu_download_album(aid, output_dir = '.', merge = True, info_only = False):
|
||||
html = get_html('http://music.baidu.com/album/%s' % aid, faker = True)
|
||||
album_name = r1(r'<h2 class="album-name">(.*)<\/h2>', html)
|
||||
artist = r1(r'<span class="author_list" title="(.*)">', html)
|
||||
output_dir = '%s/%s - %s' % (output_dir, artist, album_name)
|
||||
ids = json.loads(r1(r'<span class="album-add" data-adddata=\'(.*)\'>', html).replace('"', '').replace(';', '"'))['ids']
|
||||
track_nr = 1
|
||||
for id in ids:
|
||||
song_html = baidu_get_song_html(id)
|
||||
song_url = baidu_get_song_url(song_html)
|
||||
song_title = baidu_get_song_title(song_html)
|
||||
file_name = '%02d.%s' % (track_nr, song_title)
|
||||
type, ext, size = url_info(song_url, faker = True)
|
||||
print_info(site_info, song_title, type, size)
|
||||
if not info_only:
|
||||
download_urls([song_url], file_name, ext, size, output_dir, merge = merge, faker = True)
|
||||
baidu_download_lyric(id, file_name, output_dir)
|
||||
track_nr += 1
|
||||
|
||||
def baidu_download(url, output_dir = '.', stream_type = None, merge = True, info_only = False):
|
||||
|
||||
if re.match(r'http://music.baidu.com/album/\d+', url):
|
||||
id = r1(r'http://music.baidu.com/album/(\d+)', url)
|
||||
baidu_download_album(id, output_dir, merge, info_only)
|
||||
|
||||
if re.match('http://music.baidu.com/song/\d+', url):
|
||||
id = r1(r'http://music.baidu.com/song/(\d+)', url)
|
||||
baidu_download_song(id, output_dir, merge, info_only)
|
||||
|
||||
site_info = "Baidu.com"
|
||||
download = baidu_download
|
||||
download_playlist = playlist_not_supported("baidu")
|
Loading…
Reference in New Issue
Block a user