Skip to content

Instantly share code, notes, and snippets.

@nezl
Last active October 1, 2015 05:23
Show Gist options
  • Select an option

  • Save nezl/d49114afccdbd51fe586 to your computer and use it in GitHub Desktop.

Select an option

Save nezl/d49114afccdbd51fe586 to your computer and use it in GitHub Desktop.
video:webm@854x480
Traceback (most recent call last):
File "./run.py", line 53, in <module>
techtalk(i['pafy'])
File "./run.py", line 40, in techtalk
aria(audio)
File "./run.py", line 13, in aria
subprocess.call(args)
File "/usr/lib/python3.4/subprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.4/subprocess.py", line 859, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.4/subprocess.py", line 1395, in _execute_child
restore_signals, start_new_session, preexec_fn)
UnicodeEncodeError: 'ascii' codec can't encode character '\u2014' in position 45: ordinal not in range(128)
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import pafy
import os
import subprocess
import logging
logging.getLogger().setLevel(logging.ERROR)
def aria(stream):
args = ['aria2c', '-o',stream.filename, stream.url]
subprocess.call(args)
def convaudio(file):
conv_args = ['ffmpeg', '-i', file, '-c:a', 'libfdk_aac', '-p:a',
'aac_he_v2', '-b:a', '24k', file[0:-4]+'-done.m4a']
subprocess.call(conv_args)
os.remove(file)
os.rename(file[0:-4]+'-done.m4a', file)
def getvideo(videostreams):
#print(videostreams)
l = [ "video:webm@854x480", "video:m4v@854x480", "video:webm@640x480",
"video:m4v@640x360", "video:webm@320x240"]
for i in l:
for vid in videostreams:
if vid.__str__() == i:
print(vid)
return vid
def getyt(url):
return pafy.new(url)
def techtalk(yt):
audio = yt.audiostreams.pop()
video = getvideo(yt.videostreams)
# print("====================="+video.__str__())
aria(audio)
convaudio(audio.filename)
aria(video)
conv_args = ['ffmpeg', '-i', video.filename, '-i', audio.filename, '-c:a',
'copy', '-c:v', 'copy', audio.filename[0:-4]+'.'+'mkv']
if subprocess.call(conv_args) == 0:
os.remove(video.filename)
os.remove(audio.filename)
url ="PLKprbVwttd70Euv8zJIJRBdGurLRG9-5d"
pl = pafy.get_playlist(url)
for i in pl['items']:
techtalk(i['pafy'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment