Advertisement
Typhoon

Audio File Encoder

Oct 29th, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import time
  5. import subprocess
  6. from datetime import datetime, timedelta
  7.  
  8.  
  9. path = '/opt/data/'
  10. rem_date = datetime.now() - timedelta(days=1)
  11.  
  12. for subdir, dirs, files in os.walk(path):
  13.     files.sort()
  14.     for file in files :
  15.         filetime = datetime.fromtimestamp(os.path.getctime(subdir + '/' + file))
  16.         if filetime > rem_date and ( str(file).endswith('.wav') or str(file).endswith('.ogg')):
  17.             file_name = os.path.splitext(file)[0]
  18.  
  19.             if str(file).endswith('.ogg') :
  20.                 outfile_name_audio = subdir + '/' + file_name
  21.             else:
  22.                 outfile_name_audio = subdir + '/' + file_name + ".mp3"
  23.  
  24.             fullpath = subdir + '/' + file
  25.             print "#####################"
  26.             print "Start Time: " + datetime.now().strftime("%Y-%m-%d %H:%M")
  27.             print "Original File : " + file
  28.             print "New File : " +file_name
  29.             cmd_audio = 'ffmpeg -i %s -ab 64k -y %s' % (fullpath, outfile_name_audio)
  30.             subprocess.call([cmd_audio, "-y"], shell=True)
  31.             print "Removing file: " + file
  32.             os.remove(fullpath)
  33.  
  34.             print "Stop Time: " + datetime.now().strftime("%Y-%m-%d %H:%M")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement