Skip to content

Instantly share code, notes, and snippets.

@pyriand3r
Last active October 9, 2016 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyriand3r/850156745a6c0a5edd4d to your computer and use it in GitHub Desktop.
Save pyriand3r/850156745a6c0a5edd4d to your computer and use it in GitHub Desktop.
Concatinates all mp3-files of a folder in right order and repairs the header of the new file afterwords. Usage: -src <folderpath> = Folder with mp3s to concatinate / -dest <filepath> = Destination for concatinated new file ATTENTION: This script is written for use under linux.
#!/usr/bin/env python2.7
# -*- coding: iso-8859-1 -*-
''' Concatinate all mp3-files of a folder in right order
and repair header afterwords.
Usage: -s / --source <folderpath> = Folder with mp3s to concatinate.
-d / --destination <filepath> = Destination for concatinated files
ATTENTION: This script is written for use under linux (Ubuntu)
'''
import os
import argparse
from glob import glob
def mp3join(src, dest):
#list all mp3-files and sort them magically
filelist = glob(src + "/*.mp3")
filelist = sorted(filelist)
#Copy first file into tmp
start = filelist[0]
print "Kopiere %s nach /tmp/tmp1.mp3" % start
os.system("cp '%s' /tmp/tmp1.mp3" % start)
filelist.pop(0)
#concatinate all file to tmp-file
for mp3 in filelist:
print "füge %s hinzu" % mp3
os.system("cat /tmp/tmp1.mp3 '%s' > /tmp/tmp2.mp3" % mp3)
os.system("mv /tmp/tmp2.mp3 /tmp/tmp1.mp3")
#repair the header
os.system("ffmpeg -i /tmp/tmp1.mp3 -c copy '%s.mp3'" % dest)
#Clean temp
os.system("rm /tmp/tmp1.mp3")
argp = argparse.ArgumentParser(description=__doc__)
argp.add_argument(
"-s", "--source", default=None,
help="Folder with mp3-files to concatinate")
argp.add_argument(
"-d", "--destination", default=None,
help="Target-file")
args = argp.parse_args()
if args.source is None:
print "Please provide an folder with mp3-files to concatinate. [-s <folderpath> (absoulte)]"
elif args.destination is None:
print "Please specify a destination file to concatinate to. [-d <filepath> (absolute)]"
else:
mp3join(args.source, args.destination)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment