Skip to content

Instantly share code, notes, and snippets.

@Mebus
Forked from anonymous/-
Last active April 22, 2017 21:07
Show Gist options
  • Save Mebus/e43e09a594a7f83892f31436d473e526 to your computer and use it in GitHub Desktop.
Save Mebus/e43e09a594a7f83892f31436d473e526 to your computer and use it in GitHub Desktop.
youtube2tv.py
#!/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