无法解码base64 python decode

时间:2017-10-03 22:15:18

标签: python base64 kodi

我正在使用Python(在Kodi插件上)。我设法刮掉了base64中的链接。我检索了一个链接:

aHR0cHM6Ly9jd3MwMDQuZ2VhcjNyZC5uZXQvZmlsZXMvdmlkZW9zLzIwMTcvMTAvMDIvMTUwNjg4NTg2ODQwNmY5LTI0MC5tcDQ/aD1STXc3aFUyZVU1anlkRHBnNWRuelB3JnR0bD0xNTA3MDc4NjU2.mp4

存储在source[0]中,但我似乎无法将其转换为已解码的字符串?

由于某些原因,在我找到source [0]的地方,它不会解码?我认为问题出在哪一行:b64s = base64.b64decode(source[0])

def matplayer(url):
    page = get_url(url)
    source = re.findall("<iframe src='(.*?)'", page)
    if source:
        if 'youtube' in source[0]:
            return YoutubeOynat(url=source[0])
        elif 'dailymotion' in source[0]:
            return dailyoynat(url=source[0])
    else:
        source = re.compile('                file: "(.*?)"').findall(page)
        b64s = base64.b64decode(source[0])
        addLink(b64s,'','','')

def addLink(name,url,iconimage,description):
    ok=True
    liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
    liz.setInfo( type="Video", infoLabels={ "Title": name } )
    liz.setInfo( type="Video", infoLabels={"Title": name,"Plot":description,})
    ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)    
    return ok

1 个答案:

答案 0 :(得分:1)

我刚发现你的问题: 你报废的字符串是:

D = [d for d in raw_input().split(',')]

print D

我会以这种方式编写代码:

source = aHR0cHM6Ly9jd3MwMDQuZ2VhcjNyZC5uZXQvZmlsZXMvdmlkZW9zLzIwMTcvMTAvMDIvMTUwNjg4NTg2ODQwNmY5LTI0MC5tcDQ/aD1STXc3aFUyZVU1anlkRHBnNWRuelB3JnR0bD0xNTA3MDc4NjU2.mp4

在上面的代码中,我只解码了没有扩展名import base64 link = base64.b64decode(source.strip(".mp4")) print(link) 的字符 结果是:

.mp4