-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0d767d
commit 99aab33
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import PySimpleGUI as sg | ||
import os | ||
import subprocess | ||
|
||
sg.theme('BluePurple') | ||
layout = [[sg.Text('YouTube Downloader')], | ||
[sg.Text('Playlist or Video URL'), sg.InputText()], | ||
[sg.Text('Path'), sg.In(), sg.FolderBrowse(target=(2, 1))], | ||
[sg.Submit(), sg.Exit()]] | ||
|
||
window = sg.Window('YouTube Downloader', layout, size=(250, 130), default_element_size=(12,1), resizable=True) | ||
|
||
while True: | ||
event, values = window.read() | ||
purl = values[0] | ||
path = values[1] | ||
if event in (sg.WIN_CLOSED, 'Submit'): | ||
if "watch" in purl: | ||
import pytube | ||
link = purl | ||
yt = pytube.YouTube(link) | ||
yt.streams.get_highest_resolution().download(path) | ||
sg.popup('Done!') | ||
elif "playlist" in purl: | ||
import re | ||
from pytube import Playlist | ||
|
||
YOUTUBE_STREAM_AUDIO = '140' | ||
DOWNLOAD_DIR = path | ||
|
||
playlist = Playlist(purl) | ||
|
||
playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)") | ||
|
||
print("Downloading", len(playlist.video_urls), "video(s)...") | ||
|
||
for url in playlist.video_urls: | ||
print(url) | ||
|
||
for video in playlist.videos: | ||
audioStream = video.streams.get_by_itag(YOUTUBE_STREAM_AUDIO) | ||
audioStream.download(output_path=DOWNLOAD_DIR) | ||
os.chdir(path) | ||
os.system('for %i in (*.mp4) do ffmpeg -i "%i" "%~ni.mp3') | ||
|
||
test = os.listdir(path) | ||
|
||
for item in test: | ||
if item.endswith(".mp4"): | ||
os.remove(os.path.join(path, item)) | ||
|
||
sg.popup('Done!') | ||
else: | ||
sg.popup('Link Not Compatable') | ||
elif event in (sg.WIN_CLOSED, 'Exit'): | ||
break |