parent
a56755ed47
commit
ee52d2e36e
|
@ -3,6 +3,7 @@ import hashlib
|
||||||
import mutagen
|
import mutagen
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
|
import datetime
|
||||||
import re
|
import re
|
||||||
from api_clients import api_client
|
from api_clients import api_client
|
||||||
|
|
||||||
|
@ -26,7 +27,8 @@ class AirtimeMetadata:
|
||||||
"MDATA_KEY_COMPOSER": "composer",\
|
"MDATA_KEY_COMPOSER": "composer",\
|
||||||
"MDATA_KEY_ENCODER": "encodedby",\
|
"MDATA_KEY_ENCODER": "encodedby",\
|
||||||
"MDATA_KEY_CONDUCTOR": "conductor",\
|
"MDATA_KEY_CONDUCTOR": "conductor",\
|
||||||
"MDATA_KEY_YEAR": "date",\
|
"MDATA_KEY_YEAR": "year",\
|
||||||
|
"MDATA_KEY_DATE": "date",\
|
||||||
"MDATA_KEY_URL": "website",\
|
"MDATA_KEY_URL": "website",\
|
||||||
"MDATA_KEY_ISRC": "isrc",\
|
"MDATA_KEY_ISRC": "isrc",\
|
||||||
"MDATA_KEY_COPYRIGHT": "copyright",\
|
"MDATA_KEY_COPYRIGHT": "copyright",\
|
||||||
|
@ -44,7 +46,8 @@ class AirtimeMetadata:
|
||||||
"composer": "MDATA_KEY_COMPOSER",\
|
"composer": "MDATA_KEY_COMPOSER",\
|
||||||
"encodedby": "MDATA_KEY_ENCODER",\
|
"encodedby": "MDATA_KEY_ENCODER",\
|
||||||
"conductor": "MDATA_KEY_CONDUCTOR",\
|
"conductor": "MDATA_KEY_CONDUCTOR",\
|
||||||
"date": "MDATA_KEY_YEAR",\
|
"year": "MDATA_KEY_YEAR",\
|
||||||
|
"date": "MDATA_KEY_DATE",\
|
||||||
"website": "MDATA_KEY_URL",\
|
"website": "MDATA_KEY_URL",\
|
||||||
"isrc": "MDATA_KEY_ISRC",\
|
"isrc": "MDATA_KEY_ISRC",\
|
||||||
"copyright": "MDATA_KEY_COPYRIGHT",\
|
"copyright": "MDATA_KEY_COPYRIGHT",\
|
||||||
|
@ -200,6 +203,9 @@ class AirtimeMetadata:
|
||||||
if 'MDATA_KEY_YEAR' in md:
|
if 'MDATA_KEY_YEAR' in md:
|
||||||
md['MDATA_KEY_YEAR'] = self.truncate_to_length(md['MDATA_KEY_YEAR'], 4)
|
md['MDATA_KEY_YEAR'] = self.truncate_to_length(md['MDATA_KEY_YEAR'], 4)
|
||||||
|
|
||||||
|
if 'MDATA_KEY_DATE' in md:
|
||||||
|
md['MDATA_KEY_DATE'] = self.truncate_to_length(md['MDATA_KEY_DATE'], 16)
|
||||||
|
|
||||||
if 'MDATA_KEY_URL' in md:
|
if 'MDATA_KEY_URL' in md:
|
||||||
md['MDATA_KEY_URL'] = self.truncate_to_length(md['MDATA_KEY_URL'], 512)
|
md['MDATA_KEY_URL'] = self.truncate_to_length(md['MDATA_KEY_URL'], 512)
|
||||||
|
|
||||||
|
|
|
@ -296,10 +296,7 @@ class AirtimeProcessEvent(ProcessEvent):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
#show moved from unwatched folder into a watched folder. Do not "organize".
|
#show moved from unwatched folder into a watched folder. Do not "organize".
|
||||||
if self.mmc.is_parent_directory(event.pathname, self.config.recorded_directory):
|
is_recorded = self.mmc.is_parent_directory(event.pathname, self.config.recorded_directory)
|
||||||
is_recorded = True
|
|
||||||
else:
|
|
||||||
is_recorded = False
|
|
||||||
self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': event.pathname, 'is_recorded_show': is_recorded})
|
self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': event.pathname, 'is_recorded_show': is_recorded})
|
||||||
else:
|
else:
|
||||||
#When we move a directory into a watched_dir, we only get a notification that the dir was created,
|
#When we move a directory into a watched_dir, we only get a notification that the dir was created,
|
||||||
|
|
|
@ -208,8 +208,6 @@ class MediaMonitorCommon:
|
||||||
|
|
||||||
storage_directory = self.config.storage_directory
|
storage_directory = self.config.storage_directory
|
||||||
|
|
||||||
is_recorded_show = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#will be in the format .ext
|
#will be in the format .ext
|
||||||
file_ext = os.path.splitext(original_path)[1]
|
file_ext = os.path.splitext(original_path)[1]
|
||||||
|
@ -238,8 +236,8 @@ class MediaMonitorCommon:
|
||||||
#/srv/airtime/stor/recorded/year/month/year-month-day-time-showname-bitrate.ext
|
#/srv/airtime/stor/recorded/year/month/year-month-day-time-showname-bitrate.ext
|
||||||
if(md['MDATA_KEY_CREATOR'] == u"Airtime Show Recorder"):
|
if(md['MDATA_KEY_CREATOR'] == u"Airtime Show Recorder"):
|
||||||
#yyyy-mm-dd-hh-MM-ss
|
#yyyy-mm-dd-hh-MM-ss
|
||||||
y = orig_md['MDATA_KEY_YEAR'].split("-")
|
y = orig_md['MDATA_KEY_DATE'].split("-")
|
||||||
filepath = u'%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, api_client.encode_to("recorded", 'utf-8'), y[0], y[1], orig_md['MDATA_KEY_YEAR'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
|
filepath = u'%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "recorded", y[0], y[1], orig_md['MDATA_KEY_DATE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
|
||||||
|
|
||||||
#"Show-Title-2011-03-28-17:15:00"
|
#"Show-Title-2011-03-28-17:15:00"
|
||||||
title = md['MDATA_KEY_TITLE'].split("-")
|
title = md['MDATA_KEY_TITLE'].split("-")
|
||||||
|
@ -250,13 +248,13 @@ class MediaMonitorCommon:
|
||||||
|
|
||||||
new_md = {}
|
new_md = {}
|
||||||
new_md["MDATA_KEY_FILEPATH"] = original_path
|
new_md["MDATA_KEY_FILEPATH"] = original_path
|
||||||
new_md['MDATA_KEY_TITLE'] = '%s-%s-%s:%s:%s' % (show_name, orig_md['MDATA_KEY_YEAR'], show_hour, show_min, show_sec)
|
new_md['MDATA_KEY_TITLE'] = '%s-%s-%s:%s:%s' % (show_name, orig_md['MDATA_KEY_DATE'], show_hour, show_min, show_sec)
|
||||||
self.md_manager.save_md_to_file(new_md)
|
self.md_manager.save_md_to_file(new_md)
|
||||||
|
|
||||||
elif(md['MDATA_KEY_TRACKNUMBER'] == u'unknown'):
|
elif(md['MDATA_KEY_TRACKNUMBER'] == u'unknown'):
|
||||||
filepath = u'%s/%s/%s/%s/%s-%s%s' % (storage_directory, api_client.encode_to("imported", 'utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
|
filepath = u'%s/%s/%s/%s/%s-%s%s' % (storage_directory, "imported", md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
|
||||||
else:
|
else:
|
||||||
filepath = u'%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, api_client.encode_to("imported", 'utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TRACKNUMBER'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
|
filepath = u'%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "imported", md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TRACKNUMBER'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
|
||||||
|
|
||||||
filepath = self.create_unique_filename(filepath, original_path)
|
filepath = self.create_unique_filename(filepath, original_path)
|
||||||
self.logger.info('Unique filepath: %s', filepath)
|
self.logger.info('Unique filepath: %s', filepath)
|
||||||
|
@ -264,6 +262,7 @@ class MediaMonitorCommon:
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error('Exception: %s', e)
|
self.logger.error('Exception: %s', e)
|
||||||
|
self.logger.error("traceback: %s", traceback.format_exc())
|
||||||
|
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
|
|
|
@ -127,13 +127,14 @@ class ShowRecorder(Thread):
|
||||||
self.logger.info("time: %s" % time)
|
self.logger.info("time: %s" % time)
|
||||||
|
|
||||||
name = time+"-"+self.show_name
|
name = time+"-"+self.show_name
|
||||||
artist = api_client.encode_to("Airtime Show Recorder",'utf-8')
|
artist = "Airtime Show Recorder"
|
||||||
|
|
||||||
#set some metadata for our file daemon
|
#set some metadata for our file daemon
|
||||||
recorded_file = mutagen.File(filepath, easy=True)
|
recorded_file = mutagen.File(filepath, easy=True)
|
||||||
recorded_file['title'] = name
|
recorded_file['title'] = name
|
||||||
recorded_file['artist'] = artist
|
recorded_file['artist'] = artist
|
||||||
recorded_file['date'] = md[0]
|
recorded_file['date'] = md[0]
|
||||||
|
recorded_file['year'] = md[0].split("-")[0]
|
||||||
#You cannot pass ints into the metadata of a file. Even tracknumber needs to be a string
|
#You cannot pass ints into the metadata of a file. Even tracknumber needs to be a string
|
||||||
recorded_file['tracknumber'] = unicode(self.show_instance)
|
recorded_file['tracknumber'] = unicode(self.show_instance)
|
||||||
recorded_file.save()
|
recorded_file.save()
|
||||||
|
|
Loading…
Reference in New Issue