Пример #1
0
def query_pianyuan_font(mv=None):
    global myheaders,BASE_URL
    r = BaseHttpGet.getSessionPool().get(mv.pub_font_url, headers=myheaders, timeout=10)
    html = r.content.decode("gbk", 'replace')
    soup = BeautifulSoup(html, "lxml")
    links = soup.find_all("a")

    font_name=None
    down_url=None
    for link in links:
        href = link.get("href")
        if href is None or href.find("mod=attachment")==-1 :
            continue
        font_name = link.string
        if font_name is None or font_name.find("rar")==-1:
            continue
        down_url=href
    if down_url is None:
        print("字幕下载地址获取失败", down_url)
        return False
    pass
    #下载字幕哦
    dr = BaseHttpGet.getSessionPool().get(BASE_URL+down_url, headers=myheaders, stream=True)
    f = open("D:/temp/"+font_name, "wb")
    for chunk in dr.iter_content(chunk_size=512):
        if chunk:
            f.write(chunk)
    f.close()
    mv.save()

    return True
Пример #2
0
def query_xp_torrent(mv=None):
    try:
        #如果下载地址是种子,则截取种子HASH码
        #http://www1.downsx.net/torrent/D27DF676675F54E82A2294FE71AAE720F45B6634
        if (mv.pub_down_url.find("torrent") != -1):
            mv.pub_down_url = "magnet:?xt=urn:btih:" + mv.pub_down_url[
                mv.pub_down_url.find("torrent") + 8:]
            print(mv.pub_down_url)
            return True
        #如果是下载地址,则下载种子
        if (mv.pub_down_url.find("updowm/file.php/") > 0):

            r = BaseHttpGet.getSessionPool().get(mv.pub_down_url,
                                                 headers=headers,
                                                 timeout=10)
            html = r.content.decode("utf-8", 'replace')
            soup = BeautifulSoup(html, "lxml")

            down_id = soup.find("input", id="id").get("value")
            down_name = soup.find("input", id="name").get("value")
            down_type = soup.find("input", id="type").get("value")
            d = {'id': down_id, 'name': down_name, 'type': down_type}

            #下载资源
            headers2 = {
                'User-Agent':
                'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
                'Referer': mv.pub_down_url
            }
            down_url = mv.pub_down_url[0:mv.pub_down_url.find("file.php"
                                                              )] + "down.php"
            print("开始下载种子", down_url)
            down_r = BaseHttpGet.getSessionPool().post(down_url,
                                                       data=d,
                                                       headers=headers2,
                                                       timeout=15)

            if (len(down_r.content) < 10):
                print("下载种子失败")
                return False

            fileObject = open(
                'd:/moviedata/torrent/1024xp_' + mv.pub_id + ".torrent", 'wb')
            fileObject.write(down_r.content)
            fileObject.flush()
            fileObject.close()
            #把种子转换成磁性链接
            down_r.pub_down_url = BTBencode.BTByteToCode(down_r.content)
            print("种子已转换为磁性链接", down_r.pub_down_url)
            return True

        pass
    except Exception as e:  # 远程文件不存在
        print("下载种子失败", e)
        return False

    return False
Пример #3
0
def query_pianyuan_info(mv=None):
    global myheaders
    r = BaseHttpGet.getSessionPool().get(mv.pub_info_url, headers=myheaders, timeout=10)
    html = r.content.decode("gbk", 'replace')
    soup = BeautifulSoup(html, "lxml")
    hdiv = soup.find("div",class_="showhide")
    sidx = hdiv.text.find("magnet:")
    if sidx==-1:
        sidx = hdiv.text.find("http://gdl.lixian.vip.xunlei.com")
    if sidx==-1:
        print("下载地址无效",hdiv.text)
        return False

    mv.pub_down_url = hdiv.text[sidx:]
    if(len(mv.pub_down_url)>1000):
        print("下载地址无效2" ,len(mv.pub_down_url),mv.pub_down_url)
        return False
    td = hdiv.parent.parent
    links = td.find_all("a")

    for link in links:
        href = link.get("href")
        if href is not None and href.find("thread-")>0:
            mv.pub_font_url=href
            break
    if mv.pub_font_url is None:
        #没有字幕,直接保存
        mv.save()
        return False
    else:
        query_pianyuan_font(mv)
    pass
    return True
Пример #4
0
def getRemoteFileSize(url):
    """ 通过content-length头获取远程文件大小
        url - 目标文件URL
        """
    if url is None or len(url) < 5:
        return 0
    try:
        r = BaseHttpGet.getSessionPool().get(url, headers=headers, timeout=10)
        return len(r.content)
    except Exception as e:  # 远程文件不存在
        return 0