Beispiel #1
0
def get_captcha_token(path):
    human_url = 'http://douban.fm/j/new_captcha'
    captcha_token = h(human_url)[1:-1]
    pic_url = 'http://douban.fm/misc/captcha?size=m&id=' + captcha_token
    c = h(pic_url)
    with open(path, 'wb') as f:
        f.write(c)
    return captcha_token
Beispiel #2
0
def get_captcha_token(path):
    human_url = 'https://douban.fm/j/new_captcha'
    captcha_token = h(human_url)[1:-1]
    pic_url = 'http://douban.fm/misc/captcha?size=m&id=' + captcha_token
    c = h(pic_url)
    with open(path, 'wb') as f:
        f.write(c)
    return captcha_token
Beispiel #3
0
def _db_h(url, v=None, auth=False):
    if auth:
        token, ck = get_douban_token_ck()
        if token is None or ck is None:
            return None
        cookie = 'dbcl2="' + token + '"; fmNlogin="******";' + \
            ' ck="' + ck + '";'
    else:
        cookie = 'ac="1460193849";'
    # http request
    extra_headers = {
        'Accept':
        'text/javascript, text/html, application/xml, text/xml, */*',
        'Accept-Encoding':
        'gzip,deflate,sdch',
        'Accept-Language':
        'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
        'Connection':
        'keep-alive',
        'Content-Type':
        'application/x-www-form-urlencoded',
        'Host':
        'douban.fm',
        'Referer':
        'http://douban.fm/search',
        'User-Agent':
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2)' +
        ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome' +
        '/33.0.1750.152 Safari/537.36',
        'Cookie':
        cookie,
    }
    return h(url, v=v, extra_headers=extra_headers)
Beispiel #4
0
def _get_qqtoken():
    token_url = 'http://base.music.qq.com/fcgi-bin/fcg_musicexpress.fcg?' + \
        'json=3&guid=780782017&g_tk=938407465&loginUin=0&hostUin=0&' + \
        'format=jsonp&inCharset=GB2312&outCharset=GB2312&notice=0&' + \
        'platform=yqq&jsonpCallback=jsonCallback&needNewCode=0'
    jc = h(token_url)[len("jsonCallback("):-len(");")]
    return json.loads(jc)["key"]
Beispiel #5
0
def _get_qqtoken():
    token_url = 'http://base.music.qq.com/fcgi-bin/fcg_musicexpress.fcg?' + \
        'json=3&guid=780782017&g_tk=938407465&loginUin=0&hostUin=0&' + \
        'format=jsonp&inCharset=GB2312&outCharset=GB2312&notice=0&' + \
        'platform=yqq&jsonpCallback=jsonCallback&needNewCode=0'
    jc = h(token_url)[len("jsonCallback("):-len(");")]
    return json.loads(jc)["key"]
Beispiel #6
0
def _qq_h(url, v=None):
    '''
    http request
    '''
    extra_headers = {
        'Accept':
        '*/*',
        'Accept-Encoding':
        'gzip,deflate,sdch',
        'Accept-Language':
        'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
        'Connection':
        'keep-alive',
        'Content-Type':
        'application/x-www-form-urlencoded',
        'Host':
        'i.y.qq.com',
        'Referer':
        'http://y.qq.com/y/static/taoge/taoge_list.html' +
        '?pgv_ref=qqmusic.y.topmenu',
        'User-Agent':
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2)' +
        ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome' +
        '/33.0.1750.152 Safari/537.36'
    }
    return h(url, v=v, extra_headers=extra_headers)
Beispiel #7
0
def _xm_h(url, v=None):
    '''
    http request
    '''
    extra_headers = {
        'Accept':
        '*/*',
        'Accept-Encoding':
        'gzip,deflate,sdch',
        'Accept-Language':
        'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
        'Connection':
        'keep-alive',
        'Content-Type':
        'application/x-www-form-urlencoded',
        'Host':
        'api.xiami.com',
        'Referer':
        'http://m.xiami.com/',
        'User-Agent':
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2)' +
        ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome' +
        '/33.0.1750.152 Safari/537.36',
    }
    return h(url, v=v, extra_headers=extra_headers)
Beispiel #8
0
def get_url_by_id(song_id):
    url = 'http://www.xiami.com/song/playlist/id/%s' % song_id + \
        '/object_name/default/object_id/0/cat/json'
    response = h(url)
    secret = json.loads(response)['data']['trackList'][0]['location']
    url = caesar(secret)
    return url
Beispiel #9
0
def get_url_by_id(song_id):
    url = 'http://www.xiami.com/song/playlist/id/%s' % song_id + \
        '/object_name/default/object_id/0/cat/json'
    response = h(url)
    secret = json.loads(response)['data']['trackList'][0]['location']
    url = caesar(secret)
    return url
Beispiel #10
0
def login(user, password, token, solution):
    login_url = 'http://douban.fm/j/login'
    v = dict(source='radio',
             alias=user,
             form_password=password,
             captcha_id=token,
             captcha_solution=solution,
             task="sync_channel_list")
    cookie = r'openExpPan=Y; flag="ok"; ac="1448675235"; bid="2dLYThA' + \
        'DnhQ";_pk_ref.100002.6447=%5B%22%22%2C%22%22%2C1448714740%2C' + \
        '%22http%3A%2F%2Fwww.douban.com%2F%22%5D; _ga=GA1.2.16347733' + \
        '49.1402330632; _pk_id.100002.6447=7d9729e0b4385d49.14023306' + \
        '33.88.1448714753.1448700119.; _pk_ses.100002.6447=*; dbcl2="' + \
        token + '"; fmNlogin="******"; ck="boPw"; _gat=1'

    user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) ' + \
        'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490' + \
        '.86 Safari/537.36'
    referer = 'http://douban.fm/'
    xwith = 'ShockwaveFlash/19.0.0.245'
    xwith = 'XMLHttpRequest'
    headers = {
        'User-Agent': user_agent,
        'Cookie': cookie,
        'Referer': referer,
        'X-Requested-With': xwith,
        'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6,ja;q=0.4,zh-TW;q=0.2',
        'Accept-Encoding': 'gzip, deflate, sdch',
    }

    def post_handler(response, result):
        try:
            ck = json.loads(result)['user_info']['ck']
        except:
            ck = None
        cookie = response.info().getheader('Set-Cookie')
        if cookie and ck is not None:
            r = re.findall(r'dbcl2="([^"]+)"', cookie)
            if r:
                token = r[0]
                return token + '|' + ck
        else:
            return None

    return h(login_url,
             v,
             progress=False,
             extra_headers=headers,
             post_handler=post_handler,
             return_post=True)
Beispiel #11
0
def _ne_h(url, v=None):
    # http request
    extra_headers = {
        'Accept': '*/*',
        'Accept-Encoding': 'gzip,deflate,sdch',
        'Accept-Language': 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
        'Connection': 'keep-alive',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Host': 'music.163.com',
        'Referer': 'http://music.163.com/search/',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2)' +
        ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome' +
        '/33.0.1750.152 Safari/537.36'
    }
    return h(url, v=v, extra_headers=extra_headers)
Beispiel #12
0
def _qq_h(url, v=None):
    '''
    http request
    '''
    extra_headers = {
        'Accept': '*/*',
        'Accept-Encoding': 'gzip,deflate,sdch',
        'Accept-Language': 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
        'Connection': 'keep-alive',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Host': 'i.y.qq.com',
        'Referer': 'http://y.qq.com/y/static/taoge/taoge_list.html' +
        '?pgv_ref=qqmusic.y.topmenu',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2)' +
        ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome' +
        '/33.0.1750.152 Safari/537.36'
    }
    return h(url, v=v, extra_headers=extra_headers)
Beispiel #13
0
def login(user, password, token, solution):
    login_url = 'https://douban.fm/j/login'
    v = dict(
        source='radio', alias=user, form_password=password,
        captcha_id=token, captcha_solution=solution, task="sync_channel_list")
    cookie = r'openExpPan=Y; flag="ok"; ac="1448675235"; bid="2dLYThA' + \
        'DnhQ";_pk_ref.100002.6447=%5B%22%22%2C%22%22%2C1448714740%2C' + \
        '%22http%3A%2F%2Fwww.douban.com%2F%22%5D; _ga=GA1.2.16347733' + \
        '49.1402330632; _pk_id.100002.6447=7d9729e0b4385d49.14023306' + \
        '33.88.1448714753.1448700119.; _pk_ses.100002.6447=*; dbcl2="' + \
        token + '"; fmNlogin="******"; ck="boPw"; _gat=1'

    user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) ' + \
        'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490' + \
        '.86 Safari/537.36'
    referer = 'http://douban.fm/'
    xwith = 'ShockwaveFlash/19.0.0.245'
    xwith = 'XMLHttpRequest'
    headers = {
        'User-Agent': user_agent,
        'Cookie': cookie,
        'Referer': referer,
        'X-Requested-With': xwith,
        'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6,ja;q=0.4,zh-TW;q=0.2',
        'Accept-Encoding': 'gzip, deflate, sdch',
    }

    def post_handler(response, result):
        try:
            ck = json.loads(result)['user_info']['ck']
        except:
            ck = None
        cookie = response.info().getheader('Set-Cookie')
        if cookie and ck is not None:
            r = re.findall(r'dbcl2="([^"]+)"', cookie)
            if r:
                token = r[0]
                return token + '|' + ck
        else:
            return None

    return h(
        login_url, v, progress=False, extra_headers=headers,
        post_handler=post_handler, return_post=True)
Beispiel #14
0
def _db_h(url, v=None, auth=False):
    if auth:
        token, ck = get_douban_token_ck()
        if token is None or ck is None:
            return None
        cookie = 'dbcl2="' + token + '"; fmNlogin="******";' + \
            ' ck="' + ck + '";'
    else:
        cookie = 'ac="1460193849";'
    # http request
    extra_headers = {
        'Accept': 'text/javascript, text/html, application/xml, text/xml, */*',
        'Accept-Encoding': 'gzip,deflate,sdch',
        'Accept-Language': 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
        'Connection': 'keep-alive',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Host': 'douban.fm',
        'Referer': 'http://douban.fm/search',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2)' +
        ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome' +
        '/33.0.1750.152 Safari/537.36',
        'Cookie': cookie,
    }
    return h(url, v=v, extra_headers=extra_headers)