Last active
July 28, 2016 15:52
-
-
Save najmam/d829d8d8a0b87994c0c1 to your computer and use it in GitHub Desktop.
A script for extracting audio streams in bulk. Relies on ffmpeg
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/env python3 | |
import os, sys | |
# This script expects the following folder structure: | |
# / the folder you run this script from | |
# /in store the videos which you want to rip here | |
# /out the extracted audio will be written here | |
# as Ogg files, using the same name as the input | |
# /done and the videos that were in in/ will be moved here. | |
# | |
# This script depends on ffmpeg. | |
extensions_to_convert = ['mp4_', 'mp4', 'flv', 'mkv', 'wav', 'ogv', 'avi', '3gp', 'wmv'] | |
should_convert = lambda f: any([f.endswith(e) for e in extensions_to_convert]) | |
pending_files = os.scandir(os.path.join(os.curdir, 'in')) | |
files = [d.name for d in pending_files if os.path.isfile(os.path.join(os.curdir, 'in', d.name)) and should_convert(d.name)] | |
def rename(f): | |
cf = f | |
for ext in extensions_to_convert: | |
cf = cf.replace('.'+ext, '.ogg') | |
return cf | |
src_dst = [(f, rename(f)) for f in files] | |
for (source, destination) in src_dst: | |
os.system('ffmpeg -i "in/%s" -vn -acodec libvorbis "out/%s"' % (source, destination)) | |
os.system('mv "in/%s" "done/%s"' % (source, source)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment