Last active
December 19, 2015 17:38
-
-
Save schettino72/5992335 to your computer and use it in GitHub Desktop.
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 python | |
"""cut begin and end from mp3, to get rid of annoying intro from podcast | |
""" | |
import os | |
import sys | |
from subprocess import check_output as cmd | |
CUT_START = '01:22' | |
CUT_END = 23 # seconds | |
def cut_mp3(mp3_in, mp3_out): | |
duration = cmd(['mp3info', '-p', '%m:%s', mp3_in]) | |
minutes, seconds = (int(x) for x in duration.split(':')) | |
cut_start = '00:{}+000-'.format(CUT_START) | |
seconds -= CUT_END | |
if seconds < 0: | |
seconds += 60 | |
minutes -= 1 | |
cut_end = '00:{:02d}:{:02d}+000'.format(minutes, seconds) | |
cmd(['mp3cut', '-o', mp3_out, '-t', cut_start + cut_end, mp3_in]) | |
if __name__ == '__main__': | |
import glob | |
for mp3_in in glob.glob('LearningIndonesian-*.mp3'): | |
number = mp3_in.rsplit('-', 1)[1].split('.')[0] | |
mp3_out = '{:02d}-indonesian.mp3'.format(int(number)) | |
if not os.path.exists(mp3_out): | |
cut_mp3(mp3_in, mp3_out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment