Extracted read_wave_duration out of code

This commit is contained in:
Rudi Grinberg 2012-09-13 17:03:05 -04:00
parent 7586aa37f3
commit 12e27e659a
2 changed files with 10 additions and 7 deletions

View File

@ -3,8 +3,6 @@ import mutagen
import math import math
import os import os
import copy import copy
import wave
import contextlib
from collections import namedtuple from collections import namedtuple
from mutagen.easymp4 import EasyMP4KeyError from mutagen.easymp4 import EasyMP4KeyError
@ -214,11 +212,7 @@ class Metadata(Loggable):
# Hickity Hackity for .wav files. Properly do this later # Hickity Hackity for .wav files. Properly do this later
if mmp.extension(fpath) == 'wav': if mmp.extension(fpath) == 'wav':
with contextlib.closing(wave.open(fpath,'r')) as f: full_mutagen.set_length(mmp.read_wave_duration(fpath))
frames = f.getnframes()
rate = f.getframerate()
duration = frames/float(rate)
full_mutagen.set_length(duration)
# Finally, we "normalize" all the metadata here: # Finally, we "normalize" all the metadata here:
self.__metadata = mmp.normalized_metadata(self.__metadata, fpath) self.__metadata = mmp.normalized_metadata(self.__metadata, fpath)

View File

@ -3,6 +3,8 @@ import copy
import subprocess import subprocess
import os import os
import math import math
import wave
import contextlib
import shutil import shutil
import re import re
import sys import sys
@ -97,6 +99,13 @@ def is_airtime_recorded(md):
if not 'MDATA_KEY_CREATOR' in md: return False if not 'MDATA_KEY_CREATOR' in md: return False
return md['MDATA_KEY_CREATOR'] == u'Airtime Show Recorder' return md['MDATA_KEY_CREATOR'] == u'Airtime Show Recorder'
def read_wave_duration(path):
with contextlib.closing(wave.open(path,'r')) as f:
frames = f.getnframes()
rate = f.getframerate()
duration = frames/float(rate)
return duration
def clean_empty_dirs(path): def clean_empty_dirs(path):
""" """
walks path and deletes every empty directory it finds walks path and deletes every empty directory it finds