replacing media monitor code in upgrade with latest.
This commit is contained in:
parent
1660899096
commit
fb5c0803ce
|
@ -3,6 +3,7 @@ import hashlib
|
|||
import mutagen
|
||||
import logging
|
||||
import math
|
||||
import re
|
||||
|
||||
"""
|
||||
list of supported easy tags in mutagen version 1.20
|
||||
|
@ -102,6 +103,7 @@ class AirtimeMetadata:
|
|||
|
||||
def get_md_from_file(self, filepath):
|
||||
|
||||
self.logger.debug("testing upgrade")
|
||||
self.logger.info("getting info from filepath %s", filepath)
|
||||
|
||||
try:
|
||||
|
@ -133,9 +135,28 @@ class AirtimeMetadata:
|
|||
md['MDATA_KEY_TITLE'] = original_name
|
||||
|
||||
#incase track number is in format u'4/11'
|
||||
#need to also check that the tracknumber is even a tracknumber (cc-2582)
|
||||
if 'MDATA_KEY_TRACKNUMBER' in md:
|
||||
try:
|
||||
md['MDATA_KEY_TRACKNUMBER'] = int(md['MDATA_KEY_TRACKNUMBER'])
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
if isinstance(md['MDATA_KEY_TRACKNUMBER'], basestring):
|
||||
md['MDATA_KEY_TRACKNUMBER'] = md['MDATA_KEY_TRACKNUMBER'].split("/")[0]
|
||||
match = re.search('^(\d*/\d*)?', md['MDATA_KEY_TRACKNUMBER'])
|
||||
|
||||
if match.group(0) is not u'':
|
||||
md['MDATA_KEY_TRACKNUMBER'] = int(md['MDATA_KEY_TRACKNUMBER'].split("/")[0])
|
||||
else:
|
||||
del md['MDATA_KEY_TRACKNUMBER']
|
||||
|
||||
#make sure bpm is valid, need to check more types of formats for this tag to assure correct parsing.
|
||||
if 'MDATA_KEY_BPM' in md:
|
||||
if isinstance(md['MDATA_KEY_BPM'], basestring):
|
||||
try:
|
||||
md['MDATA_KEY_BPM'] = int(md['MDATA_KEY_BPM'])
|
||||
except Exception, e:
|
||||
del md['MDATA_KEY_BPM']
|
||||
|
||||
md['MDATA_KEY_BITRATE'] = file_info.info.bitrate
|
||||
md['MDATA_KEY_SAMPLERATE'] = file_info.info.sample_rate
|
||||
|
@ -152,4 +173,7 @@ class AirtimeMetadata:
|
|||
if(isinstance(md[key], basestring)):
|
||||
md[key] = md[key].encode('utf-8')
|
||||
|
||||
self.logger.info("MD after parsing.")
|
||||
self.logger.debug(md)
|
||||
|
||||
return md
|
||||
|
|
|
@ -207,18 +207,18 @@ class MediaMonitorCommon:
|
|||
|
||||
return filepath
|
||||
|
||||
def execCommandAndReturnStdOut(self, command):
|
||||
p = Popen(command, shell=True, stdout=PIPE)
|
||||
stdout = p.communicate()[0]
|
||||
def exec_command(self, command):
|
||||
p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
if p.returncode != 0:
|
||||
self.logger.warn("command \n%s\n return with a non-zero return value", command)
|
||||
self.logger.error(stderr)
|
||||
return stdout
|
||||
|
||||
def scan_dir_for_new_files(self, dir):
|
||||
command = 'find "%s" -type f -iname "*.ogg" -o -iname "*.mp3" -readable' % dir.replace('"', '\\"')
|
||||
self.logger.debug(command)
|
||||
stdout = self.execCommandAndReturnStdOut(command)
|
||||
stdout = unicode(stdout, "utf_8")
|
||||
stdout = self.exec_command(command)
|
||||
|
||||
return stdout.splitlines()
|
||||
|
||||
|
@ -230,8 +230,6 @@ class MediaMonitorCommon:
|
|||
file_md = self.md_manager.get_md_from_file(pathname)
|
||||
|
||||
if file_md is not None:
|
||||
#is_recorded_show = 'MDATA_KEY_CREATOR' in file_md and \
|
||||
# file_md['MDATA_KEY_CREATOR'] == "AIRTIMERECORDERSOURCEFABRIC".encode('utf-8')
|
||||
filepath = self.create_file_path(pathname, file_md)
|
||||
|
||||
self.logger.debug("Moving from %s to %s", pathname, filepath)
|
||||
|
|
Loading…
Reference in New Issue