python - KeyError : 'url_encoded_fmt_stream_map'

标签 python python-3.x beautifulsoup youtube pytube

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

`

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)

`

enter image description here

最佳答案

您的问题似乎与giacaglia今天修复的错误有关。根据Github Commit,可以通过修改mixins.py来修复该错误的解决方案,如链接中所述。您的播放列表应该可以正常运行,而不会遇到上面遇到的KeyError:'url_encoded_fmt_stream_map'问题。

关于python - KeyError : 'url_encoded_fmt_stream_map' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59135180/

相关文章:

python - 并非所有组都在 Telethon 中可见

python - 极差的预测 : LSTM time-series

python - 在Python中创建具有列键和行键的二维数组

python - 网页抓取谷歌财经

python - 我如何暗示一个类型与打字具有可比性

c++ - QWidgetAction 在 trigger() 之后保持可见

python - 每个服务器前缀

python - 预期 Python 中的预期 block

html - 使用 BeautifulSoup 通过标签类迭代 html

python - 如果没有图片,如何在同一位置抓取多个图像的链接空白该位置