xiami_downloader辅助脚本

xiami_downloader 本体见 https://github.com/latyas/xiami-downloader

获取某歌手的所有专辑

# -*- coding: utf-8 -*-
"""
Created on Tue Nov 12 04:25:17 2013

@author: latyas
"""

import requests
from bs4 import BeautifulSoup
import math
import re
import sys

url = 'http://www.xiami.com/artist/album/id/%s/d//p/pub/page/%s'
key_id = sys.argv[1]

s = requests.session()

lists = []

header = {'user-agent':'Mozilla/5.0'}
ret = s.get(url % (key_id,'1'),headers=header)

bs = BeautifulSoup(ret.text)

foo = bs.find('p',attrs={'class':'counts'})

amount = int(re.findall('[0-9]+',foo.text)[0])
pages = int(math.ceil(amount/9.0))

for n in range(1,pages+1):
    ret = s.get(url % (key_id,str(n)),headers=header)
    bs = BeautifulSoup(ret.text)
    bar = bs.findAll('p',attrs={'class':'name'})
    for i in bar[:len(bar)/2]:
        barbar = i.find('a')
        lists.append(barbar.get('href').replace('/album/',''))

for i in lists:
    print 'python xiami2.py --type=album --320k --remove %s' % i

instruction:

如:http://www.xiami.com/artist/93341?spm=0.0.0.0.zSSjGT

python get_artist_albums.py 93341

输出:

python xiami2.py --type=album --320k --remove 1675369573
python xiami2.py --type=album --320k --remove 175768473
python xiami2.py --type=album --320k --remove 1862708947
python xiami2.py --type=album --320k --remove 557319
python xiami2.py --type=album --320k --remove 533626
python xiami2.py --type=album --320k --remove 548355
python xiami2.py --type=album --320k --remove 490416
python xiami2.py --type=album --320k --remove 501976
python xiami2.py --type=album --320k --remove 451818
python xiami2.py --type=album --320k --remove 545283

 

精选集相关搜索

# -*- coding: utf-8 -*-
"""
Created on Tue Nov 12 04:25:17 2013

@author: latyas
"""

import requests
from bs4 import BeautifulSoup
import math
import sys

keyword = sys.argv[1]

url ='http://www.xiami.com/collect/search/orderstatus/play_count/key/%s/page/' % keyword

s = requests.session()

lists = []

header = {'user-agent':'Mozilla/5.0'}
ret = s.get(url,headers=header)
bs = BeautifulSoup(ret.text)
foo = bs.find('div',attrs={'class':'collectSort'})
amount = int(foo.find('i').contents[0])
pages = int(math.ceil(amount/30.0))

for n in range(1,pages+1):
    ret = s.get(url+str(n),headers=header)
    bs = BeautifulSoup(ret.text)
    foofoo = bs.findAll('div',attrs={'class':'block_cover'})
    for i in foofoo:
        foobar = i.findAll('a')
        lists.append(foobar[0].get('href').replace('/song/showcollect/id/',''))

for i in lists:
    print 'python xiami2.py --type=songlist --320k --onefolder --remove %s' % i
    
print 'total:',len(lists)

INSTRUCTION:

python songlist.py "C81"

 

专辑名相关搜索

# -*- coding: utf-8 -*-
"""
Created on Tue Nov 12 04:25:17 2013

@author: latyas
"""

import requests
from bs4 import BeautifulSoup
import math
import sys

keyword = sys.argv[1]

url ='http://www.xiami.com/search/album/page/%s?key=%s&is_pub=y'

s = requests.session()

lists = []

header = {'user-agent':'Mozilla/5.0'}
ret = s.get(url % ('1',keyword),headers=header)
bs = BeautifulSoup(ret.text)
foo = bs.find('p',attrs={'class':'seek_counts ok'})
amount = int(foo.find('b').contents[0])
pages = int(math.ceil(amount/12.0))

for n in range(1,pages+1):
    ret = s.get(url % (str(n),keyword),headers=header)
    bs = BeautifulSoup(ret.text)
    bar = bs.findAll('p',attrs={'class':'name'})
    for i in bar:
        barbar = i.find('a')
        lists.append(barbar.get('href').replace('/album/',''))

for i in lists:
    print 'python xiami2.py --type=album --remove --320k %s' % i

instruction:

python album_name.py "Little Buster!"

 

 

posted @ 2013-11-30 08:29  latyas  阅读(923)  评论(0编辑  收藏  举报