Skip to content

Instantly share code, notes, and snippets.

@lolobosse
Created December 24, 2015 17:11
Show Gist options
  • Save lolobosse/6ce504ff3b53427defe0 to your computer and use it in GitHub Desktop.
Save lolobosse/6ce504ff3b53427defe0 to your computer and use it in GitHub Desktop.
To regroup x avis files which have been splitted
import re
from subprocess import call
import sys
import os
rootdir = '.'
dictOfFilms = {}
for subdir, dirs, files in os.walk(rootdir):
for file in files:
if file.endswith(".avi") and re.search("_[0-9].avi", file) is None:
prefix = file.replace('.avi', '')
regex = re.compile(prefix + "_[0-9].avi")
for subfile in files:
if regex.match(subfile):
if prefix not in dictOfFilms:
dictOfFilms[prefix] = [file]
dictOfFilms[prefix].append(subfile)
for key, value in dictOfFilms.iteritems():
toGroupProperly = ["'" + a + "'" for a in value]
command = "cat " + " ".join(
toGroupProperly) + " > tmp.avi && mencoder -forceidx -oac copy -ovc copy tmp.avi -o 'Converted/" + key + ".avi' && rm -f tmp.avi"
if 'go' in sys.argv:
call(command, shell=True)
print command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment