Removed code duplication

This commit is contained in:
Rudi Grinberg 2012-09-14 11:48:34 -04:00
parent 7a46bdc4a2
commit 53ec408249
2 changed files with 8 additions and 25 deletions

View file

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import mutagen
import math
import os
import copy
from collections import namedtuple
@ -8,6 +7,7 @@ from mutagen.easymp4 import EasyMP4KeyError
from media.monitor.exceptions import BadSongFile
from media.monitor.log import Loggable
from media.monitor.pure import format_length
import media.monitor.pure as mmp
"""
@ -94,24 +94,6 @@ truncate_table = {
'MDATA_KEY_COPYRIGHT' : 512,
}
def format_length(mutagen_length):
"""
Convert mutagen length to airtime length
"""
t = float(mutagen_length)
h = int(math.floor(t / 3600))
t = t % 3600
m = int(math.floor(t / 60))
s = t % 60
# will be ss.uuu
s = str(s)
seconds = s.split(".")
s = seconds[0]
# have a maximum of 6 subseconds.
if len(seconds[1]) >= 6: ss = seconds[1][0:6]
else: ss = seconds[1][0:]
return "%s:%s:%s.%s" % (h, m, s, ss)
def truncate_to_length(item, length):
if isinstance(item, int): item = str(item)
if isinstance(item, basestring):

View file

@ -308,6 +308,7 @@ def organized_path(old_path, root_path, orig_md):
# MDATA_KEY_BITRATE is in bytes/second i.e. (256000) we want to turn this
# into 254kbps
# Some metadata elements cannot be empty, hence we default them to some
# value just so that we can create a correct path
normal_md = default_to_f(orig_md, path_md, unicode_unknown, default_f)
@ -477,12 +478,12 @@ def file_playable(pathname):
"""
Returns True if 'pathname' is playable by liquidsoap. False otherwise.
"""
#when there is an single apostrophe inside of a string quoted by
#apostrophes, we can only escape it by replace that apostrophe with '\''.
#This breaks the string into two, and inserts an escaped single quote in
#between them. We run the command as pypo because otherwise the target file
#is opened with write permissions, and this causes an inotify ON_CLOSE_WRITE
#event to be fired :/
# when there is an single apostrophe inside of a string quoted by
# apostrophes, we can only escape it by replace that apostrophe with
# '\''. This breaks the string into two, and inserts an escaped
# single quote in between them. We run the command as pypo because
# otherwise the target file is opened with write permissions, and
# this causes an inotify ON_CLOSE_WRITE event to be fired :/
command = ("airtime-liquidsoap -c 'output.dummy" + \
"(audio_to_stereo(single(\"%s\")))' > /dev/null 2>&1") % \
pathname.replace("'", "'\\''")