cc-4105: added metadata write function
This commit is contained in:
parent
53e9b02b26
commit
493f93c425
|
@ -4,6 +4,8 @@ from kombu.connection import BrokerConnection
|
|||
import json
|
||||
import copy
|
||||
|
||||
from media.monitor.exception import BadSongFile
|
||||
from media.monitor.metadata import Metadata
|
||||
from media.monitor.log import Loggable
|
||||
|
||||
# Do not confuse with media monitor 1's AirtimeNotifier class that more related
|
||||
|
@ -88,12 +90,22 @@ class AirtimeMessageReceiver(Loggable):
|
|||
# pydispatcher or do the necessary changes on the filesystem that will fire
|
||||
# the events
|
||||
def md_update(self, msg):
|
||||
pass
|
||||
md_path = msg['MDATA_KEY_FILEPATH']
|
||||
try:
|
||||
Metadata.write_unsafe(path=md_path, md=msg)
|
||||
except BadSongFile as e:
|
||||
self.logger.info("Cannot find metadata file: '%s'" % e.path)
|
||||
except Exception as e:
|
||||
# TODO : add md_path to problem path or something?
|
||||
self.logger.info("Unknown error when writing metadata to: '%s'" % md_path)
|
||||
def new_watch(self, msg):
|
||||
# TODO : add new watched directory by bootstrapping it with an empty
|
||||
# database?
|
||||
pass
|
||||
def remove_watch(self, msg):
|
||||
pass
|
||||
def rescan_watch(self, msg):
|
||||
# TODO : basically a bootstrap on the directory
|
||||
pass
|
||||
def change_storage(self, msg):
|
||||
pass
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import mutagen
|
||||
import math
|
||||
import os
|
||||
import copy
|
||||
from media.monitor.exceptions import BadSongFile
|
||||
from media.monitor.log import Loggable
|
||||
|
@ -93,7 +94,17 @@ def truncate_to_length(item, length):
|
|||
class Metadata(Loggable):
|
||||
@staticmethod
|
||||
def write_unsafe(path,md):
|
||||
pass
|
||||
if not os.path.exists(path):
|
||||
raise BadSongFile(path)
|
||||
song_file = mutagen.File(path, easy=True)
|
||||
for airtime_k, airtime_v in md.iteritems():
|
||||
if airtime_k in airtime2mutagen:
|
||||
song_file[ airtime2mutagen[airtime_k] ] = airtime_v
|
||||
else:
|
||||
song_file[ airtime2mutagen[airtime_k] ] = u""
|
||||
song_file.save()
|
||||
|
||||
|
||||
def __init__(self, fpath):
|
||||
# Forcing the unicode through
|
||||
try: fpath = fpath.decode("utf-8")
|
||||
|
|
Loading…
Reference in New Issue