Skip to content

Commit

Permalink
Fix Pytube 403 error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Sep 25, 2024
1 parent cb0828a commit c2e736c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 0 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def download_button_click(self):
# assert self.videos_dict exists
if not self._assert_videos_dict(self.download_status, "No video to download."):
return

playlist_properties = self._get_playlist_properties()
self.download_button.setEnabled(False)
self.download_status.setText("Downloading...")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ itunespy==1.5.5
moviepy
mutagen
PyQt5
pytube
pytubefix
QDarkStyle
requests
youtube-dl==2020.12.14
18 changes: 15 additions & 3 deletions utils/download_youtube.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from shutil import copy2

import pytube
from pytubefix import YouTube
import requests
from mutagen.mp3 import MP3
from mutagen.mp4 import MP4, MP4Cover
Expand All @@ -20,11 +20,23 @@ def thread_query_youtube(args):
save_as_mp4 = args[3]
full_link = yt_link_starter + videos_dict["id"]


def new_get_youtube_mp3():
try:
yt = YouTube(full_link)
print(yt.title)

ys = yt.streams.get_audio_only()
ys.download(mp3=True)
except Exception as error: # not a good Exceptions catch...
print(f"Error: {str(error)}") # poor man's logging
raise RuntimeError from error

def get_youtube_mp4():
"""Write MP4 audio file from YouTube video."""
try:
video = pytube.YouTube(full_link)
stream = video.streams.filter(audio_codec="mp4a.40.2").first()
video = YouTube(full_link)
stream = video.streams.get_highest_resolution()
mp4_filename = f'{song_properties.get("song")}'
illegal_char = (
"?",
Expand Down

0 comments on commit c2e736c

Please sign in to comment.