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 json
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
from media.monitor.exception import BadSongFile
|
||||||
|
from media.monitor.metadata import Metadata
|
||||||
from media.monitor.log import Loggable
|
from media.monitor.log import Loggable
|
||||||
|
|
||||||
# Do not confuse with media monitor 1's AirtimeNotifier class that more related
|
# 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
|
# pydispatcher or do the necessary changes on the filesystem that will fire
|
||||||
# the events
|
# the events
|
||||||
def md_update(self, msg):
|
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):
|
def new_watch(self, msg):
|
||||||
|
# TODO : add new watched directory by bootstrapping it with an empty
|
||||||
|
# database?
|
||||||
pass
|
pass
|
||||||
def remove_watch(self, msg):
|
def remove_watch(self, msg):
|
||||||
pass
|
pass
|
||||||
def rescan_watch(self, msg):
|
def rescan_watch(self, msg):
|
||||||
|
# TODO : basically a bootstrap on the directory
|
||||||
pass
|
pass
|
||||||
def change_storage(self, msg):
|
def change_storage(self, msg):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import mutagen
|
import mutagen
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
import copy
|
import copy
|
||||||
from media.monitor.exceptions import BadSongFile
|
from media.monitor.exceptions import BadSongFile
|
||||||
from media.monitor.log import Loggable
|
from media.monitor.log import Loggable
|
||||||
|
@ -93,7 +94,17 @@ def truncate_to_length(item, length):
|
||||||
class Metadata(Loggable):
|
class Metadata(Loggable):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def write_unsafe(path,md):
|
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):
|
def __init__(self, fpath):
|
||||||
# Forcing the unicode through
|
# Forcing the unicode through
|
||||||
try: fpath = fpath.decode("utf-8")
|
try: fpath = fpath.decode("utf-8")
|
||||||
|
|
Loading…
Reference in New Issue