-
-
Save Mebus/e43e09a594a7f83892f31436d473e526 to your computer and use it in GitHub Desktop.
youtube2tv.py
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
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Author: Mebus | |
License: MIT | |
Purpose: Convert files for crappy PHILIPS **SMART**TV | |
Requirments-Installation: | |
pip3 install validators | |
apt-get install youtube-dl ffmpeg | |
""" | |
import os | |
import sys | |
import validators | |
if len(sys.argv) <= 1: | |
print("Please provide a URL.") | |
sys.exit() | |
url = sys.argv[1] | |
tmpdir = 'youtube2tv-tmp' | |
permdir = 'youtube2tv-transcoded' | |
if validators.url(url): | |
# tmp directory | |
if not os.path.isdir(tmpdir): | |
os.makedirs(tmpdir) | |
# permanent directory | |
if not os.path.isdir(permdir): | |
os.makedirs(permdir) | |
cmd = "youtube-dl --restrict-filenames -o '" + tmpdir + "/%(title)s.%(ext)s' " + url | |
print(cmd) | |
# run download | |
os.system(cmd) | |
i = 0 | |
myfile = None | |
for afile in os.listdir(tmpdir): | |
print(afile) | |
myfile = afile | |
i = i+1 | |
if i == 1: | |
fpath = os.path.join(tmpdir,myfile) # path of inputfile | |
opath = os.path.join(permdir,myfile) # path of outputfile | |
print(fpath) | |
cmd2 = "ffmpeg -i " + fpath + " -acodec mp3 -vcodec copy " + opath | |
print(cmd2) | |
# run conversion | |
os.system(cmd2) | |
# delete the old file | |
os.remove(fpath) | |
else: | |
print("Could not identify my file...") | |
else: | |
print("URL invalid!") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment