I am trying to embed a Youtube video in a PyQt5 application. However, for specific videos it consistently displays an error ("An error occurred. Please try again later. (Playback id: XXXX)"), while for others it consistently works.

I cannot explain the behavior, and so far the only hypothesis I formed that I cannot completely dismiss, is that videos with many views (>3k) tend to work, while videos with few views (<3k) tend to not work.

I did check whether it can be a problem of the videos not allowing embedding, but face the same issue in videos I uploaded myself, that specifically allow embedding.

Here the a code example where I face this issue. First showing the non-working video, then showing the working video:

from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView

class YouTubePlayer(QWidget):
    def __init__(self, video_url):
        super().__init__()
        self.setWindowTitle("YouTube Player")
        self.setGeometry(100, 100, 800, 600)
        layout = QVBoxLayout(self)
        self.web_view = QWebEngineView()
        layout.addWidget(self.web_view)
        self.web_view.setUrl(QUrl(video_url))


if __name__ == "__main__":
    app = QApplication([])
    video_url = "https://www.youtube.com/embed/Ug0Gh42RlXs"
    youtube_player = YouTubePlayer(video_url)
    youtube_player.show()
    app.exec_()
    video_url = "https://www.youtube.com/embed/raTMa8MneTY"
    youtube_player = YouTubePlayer(video_url)
    youtube_player.show()
    app.exec_()

Any information explaining or resolving the issue would be greatly appreciated!

0

There are 0 answers