簡體   English   中英

使用硬盤上的文件而不是python的url

[英]Use of files on hard drives instead of url with python

我想修改此腳本以使用脫機文件,如果我從url下載文件,但是如果我從硬盤驅動器中提取的文件沒有打開,有人可以幫助我了解原因和操作方法,謝謝。

    def INDEX():
    TVLIST('https://www.*********/playlist/*******/test.m3u')


def TVLIST(url):
    try:
        m3u = getHtml(url)
        parsem3u(m3u)
    except:
        addDir('Nothing found', '', '', '', Folder=False)
    xbmcplugin.endOfDirectory(int(sys.argv[1]))

urlopen = urllib2.urlopen
Request = urllib2.Request

def getHtml(url, referer=None, hdr=None, data=None):
    if not hdr:
        req = Request(url, data, headers)
    else:
        req = Request(url, data, hdr)
    if referer:
        req.add_header('Referer', referer)
    if data:
        req.add_header('Content-Length', len(data))
    response = urlopen(req)
    if response.info().get('Content-Encoding') == 'gzip':
    buf = StringIO( response.read())
    f = gzip.GzipFile(fileobj=buf)
    data = f.read()
    f.close()
else:
    data = response.read()    
response.close()
return data

def parsem3u(html, sitechk=True):
    match = re.compile('#.+,(.+?)\n(.+?)\n').findall(html)
    txtfilter = txtfilter = GETFILTER()
    txtfilter = txtfilter.split(',') if txtfilter else []
    txtfilter = [f.lower().strip() for f in txtfilter]
    i = 0
    count = 0
    for name, url in match:
        status = ""
        url = url.replace('\r','')
        if not txtfilter or any(f in name.lower() for f in txtfilter):
            if sitechk:
                if i < 5:
                    try:
                        siteup = urllib.urlopen(url).getcode()
                        status = " [COLOR red]offline[/COLOR]" if siteup != 200 else " [COLOR green]online[/COLOR]"
                    except: status = " [COLOR red]offline[/COLOR]"
                    i += 1
            addPlayLink(name+status, url, 3, uiptvicon)
            count += 1
    return count

我以為足以走本地道路

def INDEX():
TVLIST(r'c:\Desktop\IPTVLIST\M3U\playlist\test.m3u')

誰能解釋為什么它不起作用,我該怎么辦? 謝謝

正如@languitar在評論中所建議的那樣,您將擁有file://當然應該適用於Windows,但是移動到android之類的平台時,您那里的文件系統不同,您沒有C驅動器。 因此,請確保您在android上有其他位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM