add suport for songtaste

This commit is contained in:
zhuhuotui[codepongo] 2013-04-11 10:12:40 +08:00 committed by Mort Yao
parent 3a3dd740f5
commit f0a21e8ea5
4 changed files with 50 additions and 0 deletions

4
.gitignore vendored
View File

@ -17,3 +17,7 @@ _*/
*.mpg *.mpg
*.ts *.ts
*.webm *.webm
*.DS_Store
*.swp
*~

View File

@ -57,6 +57,7 @@ def url_to_module(url):
'youku': youku, 'youku': youku,
'youtu': youtube, 'youtu': youtube,
'youtube': youtube, 'youtube': youtube,
'songtaste':songtaste,
#TODO #TODO
} }
if k in downloads: if k in downloads:

View File

@ -35,3 +35,4 @@ from .baidu import *
from .yinyuetai import * from .yinyuetai import *
from .youku import * from .youku import *
from .youtube import * from .youtube import *
from .songtaste import *

View File

@ -0,0 +1,44 @@
#!/usr/bin/env python
__all__ = ['songtaste_download']
from ..common import *
import urllib.error
def songtaste_download(url, output_dir = '.', merge = True, info_only = False):
if re.match(r'http://www.songtaste.com/song/\d+', url):
old_fake_headers = fake_headers
id = r1(r'http://www.songtaste.com/song/(\d+)', url)
player_url = 'http://www.songtaste.com/playmusic.php?song_id='+str(id)
fake_headers['Referer'] = player_url
html = get_response(player_url).data
r = '''^WrtSongLine\((.*)\)'''
reg = re.compile(r , re.M)
m = reg.findall(html.decode('gbk'))
l = m[0].replace('"', '').replace(' ', '').split(',')
title = l[2] + '-' + l[1]
for i in range(0, 10):
real_url = l[5].replace('http://mg', 'http://m%d' % i)
try:
type, ext, size = url_info(real_url, True)
except urllib.error.HTTPError as e:
if 403 == e.code:
continue
else:
raise e
break
print_info(site_info, title, type, size)
if not info_only:
download_urls([real_url], title, ext, size, output_dir, refer = url, merge = merge, faker = True)
fake_hreaders = old_fake_headers
site_info = "www.songtaste.com"
download = songtaste_download
download_playlist = playlist_not_supported('songtaste')