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

问题描述 投票:0回答:1

我想修改这个脚本以使用脱机文件,如果我从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')

谁解释了为什么它不起作用,我该怎么办?谢谢

python python-2.7 python-3.x
1个回答
0
投票

正如@languitar在评论中所建议的,你会有file://当然它应该适用于Windows,但是转移到像android这样的平台,你有不同的文件系统,你没有C驱动器。因此,请确保您在Android上有另一个位置。

© www.soinside.com 2019 - 2024. All rights reserved.