mirror of
https://github.com/metafy-social/python-scripts.git
synced 2025-01-18 07:17:03 +00:00
download-youtube- audio-or-video
added YouTube audio or video downloader
This commit is contained in:
parent
3108d05d03
commit
d6bff79604
12
scripts/youtube_audio_or_video_download/README.md
Normal file
12
scripts/youtube_audio_or_video_download/README.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Download YouTube Audio or Video
|
||||
|
||||
with one script, you can download a YouTube video as either video or audio only
|
||||
|
||||
#### Installation
|
||||
pip install pytube
|
||||
|
||||
### Usage
|
||||
* Clone the repo
|
||||
* install requirement
|
||||
* run python script.py
|
||||
* enter YouTube video url
|
|
@ -0,0 +1,65 @@
|
|||
from pytube import YouTube
|
||||
import os
|
||||
|
||||
def audio_only():
|
||||
print('------------------------------')
|
||||
print('Hey, you are about to download the audio of the YouTube video of your choice')
|
||||
print("Don't know why you need that though, but enjoyyyy.")
|
||||
print('------------------------------\n')
|
||||
|
||||
video_url = str(input("Enter the YouTube video URL: "))
|
||||
yt = YouTube(video_url)
|
||||
|
||||
#path to save to
|
||||
path = os.getcwd() + '\\'
|
||||
|
||||
#video title
|
||||
title = yt.title
|
||||
|
||||
#download audio
|
||||
audio = yt.streams.filter(only_audio=True).first()
|
||||
audio_file = audio.download(output_path=path)
|
||||
|
||||
#save file
|
||||
base, extension = os.path.splitext(audio_file)
|
||||
new_audio_file = base + '.mp3'
|
||||
os.rename(audio_file, new_audio_file)
|
||||
|
||||
print(title + " has been successfully downloaded.")
|
||||
|
||||
def video():
|
||||
print('------------------------------')
|
||||
print('Hey, you are about to download the YouTube video of your choice')
|
||||
print("Enjoyyyy.")
|
||||
print('------------------------------\n')
|
||||
|
||||
video_url = str(input("Enter the YouTube video URL: "))
|
||||
yt = YouTube(video_url)
|
||||
|
||||
#path to save to
|
||||
path = os.getcwd() + '\\'
|
||||
|
||||
#video title
|
||||
title = yt.title
|
||||
|
||||
#download video
|
||||
video = yt.streams.filter(res='1080p').first()
|
||||
video_file = video.download(output_path=path)
|
||||
|
||||
#save file
|
||||
base, extension = os.path.splitext(video_file)
|
||||
new_audio_file = base + '.mp4'
|
||||
os.rename(video_file, new_audio_file)
|
||||
|
||||
print(title + " has been successfully downloaded.")
|
||||
|
||||
def main():
|
||||
download = str(input('Video or Audio_only? (V|A): '))
|
||||
|
||||
if download == "V":
|
||||
video()
|
||||
else:
|
||||
audio_only()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user