Convert all of your media files into mp3

Last days, I was trying to convert a lot of videos into audio, so that I can use them in another devices.  Firstly I was trying to write it into shell script, but that was just a head-ache! as my experience in shell scripting is zero!

So I wrote it in 3 minutes in python🙂

That’s the code

#! usr/bin/python
# -*- coding: utf-8 -*-
#
# conver_to_mp3.py
#
# Copyright 2011 moemen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

import os
import glob
import sys

def convert_to_mp3(path):
'''
Convert the media files in the given directory into mp3
'''
print 'Go to the files ...'
os.chdir(path)
print
print 'Creating a new directory for store the output ...'
os.system('mkdir mp3')
print
print 'Scanning ...'
files = glob.glob("*")
print
for f in files:
name = "./mp3/"+f[:-3]+'mp3'
print 'converting', f, 'to > ', name
os.system("ffmpeg -i '{0}' '{1}'".format(f, name))
print 'Finished!'

if __name__ == '__main__':
convert_to_mp3(sys.argv[1])

Have fun with it .. and I ‘m waiting for your opinion :)

أضف تعليقاً

إملأ الحقول أدناه بالمعلومات المناسبة أو إضغط على إحدى الأيقونات لتسجيل الدخول:

WordPress.com Logo

أنت تعلق بإستخدام حساب WordPress.com. تسجيل خروج   / تغيير )

صورة تويتر

أنت تعلق بإستخدام حساب Twitter. تسجيل خروج   / تغيير )

Facebook photo

أنت تعلق بإستخدام حساب Facebook. تسجيل خروج   / تغيير )

Google+ photo

أنت تعلق بإستخدام حساب Google+. تسجيل خروج   / تغيير )

Connecting to %s

%d مدونون معجبون بهذه: