This code consists of a python script which allows us to easily download YouTube videos/audio by passing its URL via the command line.
- youtube.py: the script's code
- aux_functions: contains multiple functions used to customize the output color and animations.
By default, the script outputs the file to: D:\YouTube
, you can simply change it by modifying the path variable.
You can download the code and easily set the path as a system environmental variable in order to be able to run the script from anywhere on your computer.
- Go to your script's directory, mine is:
cd /d d:\WebDev\Python\Scripts
- Run the following command:
- Select wether you want to download the video or audio.
python youtube.py https://www.youtube.com/watch?v=-mwpoE0x0JQ
- Simply run the following command:
youtube.py https://www.youtube.com/watch?v=-mwpoE0x0JQ
- Select wether you want to download the video or audio.
This auxiliar function writes character by character and gives the program a very nice looking.
def conti(s):
for ch in s:
sys.stdout.write(ch)
sys.stdout.flush()
time.sleep(0.02)
print("\n")
This class gives us the ability to change the output colors by calling its elements.
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'