Я написал приложение для загрузки с помощью puqt5, когда я хочу загрузить список воспроизведения youtube, я получаю ошибку

#python #pyqt5

Вопрос:

это мой код

 from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUiType

from os import path
import sys
import urllib.request
import pafy
import humanize
import os
import requests

ui,_ = loadUiType('main.ui')

class MainApp(QMainWindow , ui):
    def __init__(self , parent=None):
        super(MainApp , self).__init__(parent)
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.Handel_UI()
        self.Handel_Buttons()

    def Handel_UI(self):
        self.setWindowTitle("Download APP")
        self.setFixedSize(655, 309)

    def Handel_Buttons(self):
        self.pushButton_4.clicked.connect(self.Download)
        self.pushButton.clicked.connect(self.Handel_Browse)
        self.pushButton_5.clicked.connect(self.Get_Youtube_video)
        self.pushButton_4.clicked.connect(self.Download_Youtube_video)
        self.pushButton_2.clicked.connect(self.Save_Browse)
        self.pushButton_3.clicked.connect(self.Download_Youtube_video)
        self.pushButton_13.clicked.connect(self.Playlist_Download)
        self.pushButton_19.clicked.connect(self.Save_Browse)

    def Handel_Browse(self):
        save_place = QFileDialog.getSaveFileName(self, caption="Save As", directory=".", filter="All Files(*.*")
        name = str(save_place[0])
        self.lineEdit_2.setText(name)

    def Handel_Progress(self, blocknum, blocksize, totalsize):
        read = blocknum * blocksize

        if totalsize > 0 :
            percent = read * 100 / totalsize
            self.progressBar.setValue(percent)
            QApplication.processEvents()

    def Download(self):
        url = self.lineEdit.text()
        save_location = self.lineEdit_2.text()
        try :
            urllib.request.urlretrieve(url, save_location, self.Handel_Progress)
        except Exception:
            QMessageBox.warning(self, "Download Error", "the Download faild")
            return
        
        QMessageBox.information(self, "Download compeleted", "the Download finished")
        self.progressBar.setValue(0)
        self.LineEdit.setText('')
        self.lineEdit_2.setText('')

    def Save_Browse(self):
        save_place = QFileDialog.getExistingDirectory(self, "Select Download Directory")
        self.lineEdit_4.setText(save_place)
        self.lineEdit_14.setText(save_place)

    def Get_Youtube_video(self):
        video_link = self.lineEdit_3.text()
        v = pafy.new(video_link)
        # st = v.videostreams
        st = v.streams

        for s in st :
            size = humanize.naturalsize(s.get_filesize())
            data = '{} {} {} {}' .format(s.mediatype , s.extension , s.quality , size)
            # data = f'{s.mediatype} {s.extension} {s.quality} {size}'
            self.comboBox.addItem(data)

    def Download_Youtube_video(self):
        video_link = self.lineEdit_3.text()
        save_location = self.lineEdit_4.text()
        v = pafy.new(video_link)
        # st = v.videostreams
        st = v.streams
        quality = self.comboBox.currentIndex()    #self.comboBox.currentIndex()
        # print(quality)
        down = st[quality].download(filepath = save_location)
        QMessageBox.information(self, "Download compeleted", "the Download finished")

    def Playlist_Download(self):
        playlist_url = self.lineEdit_13.text()
        
        save_location = self.lineEdit_14.text()
        playlist = pafy.get_playlist(playlist_url)
        videos = playlist['items']
    
        os.chdir(save_location)
        if os.path.exists(str(playlist['title'])) :
            os.chdir(str(playlist['title']))
        else :
            os.mkdir(str(playlist['title']))
            os.chdir(str(playlist['title']))
    
        for video in videos :
            p = video['pafy']
            best = p.getbest(preftype='mp4')
            best.download()

def main():
    app = QApplication(sys.argv)
    window = MainApp()
    window.show()
    app.exec_()

if __name__ == '__main__':
    main()
 

и в этом заключается ошибка

 Traceback (most recent call last):
  File "C:UsershmDesktopDownload APPindex.py", line 98, in Playlist_Download
    playlist = pafy.get_playlist(playlist_url)
  File "C:UsershmAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagespafyplaylist.py", line 58, in get_playlist
    allinfo = fetch_decode(url)  # unicode
  File "C:UsershmAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagespafypafy.py", line 67, in fetch_decode
    req = g.opener.open(url)
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.752.0_x64__qbz5n2kfra8p0liburllibrequest.py", line 523, in open
    response = meth(req, response)
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.752.0_x64__qbz5n2kfra8p0liburllibrequest.py", line 632, in http_response
    response = self.parent.error(
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.752.0_x64__qbz5n2kfra8p0liburllibrequest.py", line 555, in error
    result = self._call_chain(*args)
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.752.0_x64__qbz5n2kfra8p0liburllibrequest.py", line 494, in _call_chain
    result = func(*args)
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.752.0_x64__qbz5n2kfra8p0liburllibrequest.py", line 747, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.752.0_x64__qbz5n2kfra8p0liburllibrequest.py", line 523, in open
    response = meth(req, response)
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.752.0_x64__qbz5n2kfra8p0liburllibrequest.py", line 632, in http_response
    response = self.parent.error(
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.752.0_x64__qbz5n2kfra8p0liburllibrequest.py", line 561, in error
    return self._call_chain(*args)
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.752.0_x64__qbz5n2kfra8p0liburllibrequest.py", line 494, in _call_chain
    result = func(*args)
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.752.0_x64__qbz5n2kfra8p0liburllibrequest.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
 

Комментарии:

1. Какой адрес вы пытаетесь использовать?

2. youtube.com/…

3. @SitesSites Вы понимаете, что такое ошибка HTTP 404? Какую отладку вы провели, чтобы убедиться, что playlist_url переменная содержит допустимый URL-адрес?

4. это файл проекта drive.google.com/drive/folders/…

5. @эхуморо drive.google.com/drive/folders/…