本文介绍了KeyError:"url_encoded_fmt_stream_map"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个可以从YouTube下载整个播放列表的代码.它适用于某些播放列表,但不适用于少数播放列表.我在下面的代码中显示的播放列表之一.也可以随时在此代码上添加更多功能.如果已有下载该播放列表的代码,请与我分享链接

I am trying to make a code which can download the entire playlist from YouTube. It worked for some playlist but not working for few playlists. One of the playlist I have shown in my code below. Also feel free to add more features on this code.If there is already a code to download the playlist so please share the link with me

`

from bs4 import BeautifulSoup
from pytube import YouTube
import urllib.request
import time
import os


## list of link parsed by bs4
s = []


## to name and save the playlist folder and download path respectively
directory = 'Hacker101'
savePath = "G:/Download/video/"
path = os.path.join(savePath, directory)


## link parser
past_link_here = "https://www.youtube.com/playlist?list=PLxhvVyxYRviZd1oEA9nmnilY3PhVrt4nj"
html_page = urllib.request.urlopen(past_link_here)
x = html_page.read()
soup = BeautifulSoup(x, 'html.parser')
for link in soup.findAll('a'):
    k = link.get('href')
    if 'watch' in k:
        s.append(k)
    else:
        pass


## to create playlist folder
def create_project_dir(x):
    if not os.path.exists(x):
        print('Creating directory ' + x)
        os.makedirs(x)
create_project_dir(path)


## downloading videos by using links from list s = []
for x in set(s):
    link="https://www.youtube.com" + x
    yt = YouTube(link)
    k = yt.title
    file_path = path + '\\' + k + '.mp4'
    try:
        if os.path.exists(file_path):
            print(k + ' is \n' + "already downloaded")
        else:
            j = yt.streams.filter(progressive=True).all()
            l = yt.streams.first()
            print(k + ' is downloading....')
            l.download(path)
            time.sleep(1)
            print('downloading compleat')

##    except Exception:
##        print('error')

    except KeyError as e:
        print('KeyError') % str(e)

`

推荐答案

您的问题似乎与 giacaglia .根据 Github提交,可以通过修改解决该bug的方法您的mixins.py(如链接中所述).您的播放列表应该可以正常工作,而不会遇到上面遇到的KeyError:'url_encoded_fmt_stream_map'问题.

Your issue appears to be related to a bug that was fixed today by giacaglia . Based on the Github Commit the solution to the bug can be fixed by modifying your mixins.py as detailed in the link. Your playlists should work without running into the KeyError: 'url_encoded_fmt_stream_map' issue you had above.

这篇关于KeyError:"url_encoded_fmt_stream_map"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:09