<commit_before>#!/usr/bin/env python

__all__ = ['qq_download']

from ..common import *
import uuid
#QQMUSIC
#SINGLE
#1. http://y.qq.com/#type=song&mid=000A9lMb0iEqwN
#2. http://y.qq.com/#type=song&id=4754713
#3. http://s.plcloud.music.qq.com/fcgi-bin/fcg_yqq_song_detail_info.fcg?songmid=002NqCeX3owQIw
#4. http://s.plcloud.music.qq.com/fcgi-bin/fcg_yqq_song_detail_info.fcg?songid=4754713
#ALBUM
#1. http://y.qq.com/y/static/album/3/c/00385vBa0n3O3c.html?pgv_ref=qqmusic.y.index.music.pic1
#2. http://y.qq.com/#type=album&mid=004c62RC2uujor
#MV
#can download as video through qq_download_by_id
#1. http://y.qq.com/y/static/mv/mv_play.html?vid=i0014ufczcw

def qq_download_by_id(id, title=None, output_dir='.', merge=True, info_only=False):
    xml = get_html('http://www.acfun.tv/getinfo?vids=%s' % id)
    from xml.dom.minidom import parseString
    doc = parseString(xml)
    doc_root = doc.getElementsByTagName('root')[0]
    doc_vl = doc_root.getElementsByTagName('vl')[0]
    doc_vi = doc_vl.getElementsByTagName('vi')[0]
    fn = doc_vi.getElementsByTagName('fn')[0].firstChild.data
    # fclip = doc_vi.getElementsByTagName('fclip')[0].firstChild.data
    # fc=doc_vi.getElementsByTagName('fc')[0].firstChild.data
    fvkey = doc_vi.getElementsByTagName('fvkey')[0].firstChild.data
    doc_ul = doc_vi.getElementsByTagName('ul')


    url = doc_ul[0].getElementsByTagName('url')[1].firstChild.data

    # print(i.firstChild.data)
    urls=[]
    ext=fn[-3:]
    size=0
    for i in doc.getElementsByTagName("cs"):
        size+=int(i.firstChild.data)

    # size=sum(map(int,doc.getElementsByTagName("cs")))
    locid=str(uuid.uuid4())
    for i in doc.getElementsByTagName("ci"):
        urls.append(url+fn[:-4] + "." + i.getElementsByTagName("idx")[0].firstChild.data + fn[-4:] + '?vkey=' + fvkey+ '&sdtfrom=v1000&type='+ fn[-3:0] +'&locid=' + locid + "&&level=1&platform=11&br=133&fmt=hd&sp=0")
        
    print(urls)    
    # if int(fclip) > 0:
    #     fn = fn[:-4] + "." + fclip + fn[-4:]
    # url = url + fn + '?vkey=' + fvkey

    # _, ext, size = url_info(url)

    print_info(site_info, title, ext, size)
    if not info_only:
        download_urls(urls, title, ext, size, output_dir=output_dir, merge=merge)

def qq_download(url, output_dir = '.', merge = True, info_only = False):
    if re.match(r'http://v.qq.com/([^\?]+)\?vid', url):
        aid = r1(r'(.*)\.html', url)
        vid = r1(r'http://v.qq.com/[^\?]+\?vid=(\w+)', url)
        url = 'http://sns.video.qq.com/tvideo/fcgi-bin/video?vid=%s' % vid<commit_msg>QQ: remove print debugging<commit_after>#!/usr/bin/env python

__all__ = ['qq_download']

from ..common import *
import uuid
#QQMUSIC
#SINGLE
#1. http://y.qq.com/#type=song&mid=000A9lMb0iEqwN
#2. http://y.qq.com/#type=song&id=4754713
#3. http://s.plcloud.music.qq.com/fcgi-bin/fcg_yqq_song_detail_info.fcg?songmid=002NqCeX3owQIw
#4. http://s.plcloud.music.qq.com/fcgi-bin/fcg_yqq_song_detail_info.fcg?songid=4754713
#ALBUM
#1. http://y.qq.com/y/static/album/3/c/00385vBa0n3O3c.html?pgv_ref=qqmusic.y.index.music.pic1
#2. http://y.qq.com/#type=album&mid=004c62RC2uujor
#MV
#can download as video through qq_download_by_id
#1. http://y.qq.com/y/static/mv/mv_play.html?vid=i0014ufczcw

def qq_download_by_id(id, title=None, output_dir='.', merge=True, info_only=False):
    xml = get_html('http://www.acfun.tv/getinfo?vids=%s' % id)
    from xml.dom.minidom import parseString
    doc = parseString(xml)
    doc_root = doc.getElementsByTagName('root')[0]
    doc_vl = doc_root.getElementsByTagName('vl')[0]
    doc_vi = doc_vl.getElementsByTagName('vi')[0]
    fn = doc_vi.getElementsByTagName('fn')[0].firstChild.data
    # fclip = doc_vi.getElementsByTagName('fclip')[0].firstChild.data
    # fc=doc_vi.getElementsByTagName('fc')[0].firstChild.data
    fvkey = doc_vi.getElementsByTagName('fvkey')[0].firstChild.data
    doc_ul = doc_vi.getElementsByTagName('ul')


    url = doc_ul[0].getElementsByTagName('url')[1].firstChild.data

    # print(i.firstChild.data)
    urls=[]
    ext=fn[-3:]
    size=0
    for i in doc.getElementsByTagName("cs"):
        size+=int(i.firstChild.data)

    # size=sum(map(int,doc.getElementsByTagName("cs")))
    locid=str(uuid.uuid4())
    for i in doc.getElementsByTagName("ci"):
        urls.append(url+fn[:-4] + "." + i.getElementsByTagName("idx")[0].firstChild.data + fn[-4:] + '?vkey=' + fvkey+ '&sdtfrom=v1000&type='+ fn[-3:0] +'&locid=' + locid + "&&level=1&platform=11&br=133&fmt=hd&sp=0")

    # if int(fclip) > 0:
    #     fn = fn[:-4] + "." + fclip + fn[-4:]
    # url = url + fn + '?vkey=' + fvkey

    # _, ext, size = url_info(url)

    print_info(site_info, title, ext, size)
    if not info_only:
        download_urls(urls, title, ext, size, output_dir=output_dir, merge=merge)

def qq_download(url, output_dir = '.', merge = True, info_only = False):
    if re.match(r'http://v.qq.com/([^\?]+)\?vid', url):
        aid = r1(r'(.*)\.html', url)
        vid = r1(r'http://v.qq.com/[^\?]+\?vid=(\w+)', url)
        url = 'http://sns.video.qq.com/tvideo/fcgi-bin/video?vid=%s' % vid
{'fraction_non_alphanumeric': 0.1951940122119362, 'fraction_numerical': 0.032696474295844005, 'mean_word_length': 3.9444985394352483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7433790', 'n_tokens_mistral': 2255, 'n_tokens_neox': 2142, 'n_words': 277}