繁体   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