CC-2633: added new encode_to()
- added encode_to() to api_client - replaced .encode() with new encode_to()
This commit is contained in:
parent
a199585cb9
commit
8995e828ff
10 changed files with 54 additions and 33 deletions
|
@ -6,7 +6,7 @@ import sys
|
|||
import os
|
||||
import signal
|
||||
|
||||
from api_clients import api_client
|
||||
from api_clients import api_client as apc
|
||||
|
||||
from multiprocessing import Process, Queue as mpQueue
|
||||
|
||||
|
@ -34,7 +34,7 @@ logger.info("\n\n*** Media Monitor bootup ***\n\n")
|
|||
|
||||
try:
|
||||
config = AirtimeMediaConfig(logger)
|
||||
api_client = api_client.api_client_factory(config.cfg)
|
||||
api_client = apc.api_client_factory(config.cfg)
|
||||
|
||||
logger.info("Setting up monitor")
|
||||
response = None
|
||||
|
@ -42,7 +42,7 @@ try:
|
|||
response = api_client.setup_media_monitor()
|
||||
time.sleep(5)
|
||||
|
||||
storage_directory = response["stor"].encode('utf-8')
|
||||
storage_directory = apc.encode_to(response["stor"], 'utf-8')
|
||||
logger.info("Storage Directory is: %s", storage_directory)
|
||||
config.storage_directory = os.path.normpath(storage_directory)
|
||||
config.imported_directory = os.path.normpath(storage_directory + '/imported')
|
||||
|
|
|
@ -2,6 +2,7 @@ import os
|
|||
import time
|
||||
|
||||
from subprocess import Popen, PIPE
|
||||
from api_clients import api_client
|
||||
|
||||
class AirtimeMediaMonitorBootstrap():
|
||||
|
||||
|
@ -29,7 +30,7 @@ class AirtimeMediaMonitorBootstrap():
|
|||
|
||||
for id, dir in directories.iteritems():
|
||||
self.logger.debug("%s, %s", id, dir)
|
||||
self.sync_database_to_filesystem(id, dir.encode("utf-8"))
|
||||
self.sync_database_to_filesystem(id, api_client.encode_to(dir, "utf-8"))
|
||||
|
||||
"""Gets a list of files that the Airtime database knows for a specific directory.
|
||||
You need to provide the directory's row ID, which is obtained when calling
|
||||
|
@ -69,7 +70,7 @@ class AirtimeMediaMonitorBootstrap():
|
|||
db_known_files_set = set()
|
||||
files = self.list_db_files(dir_id)
|
||||
for file in files['files']:
|
||||
db_known_files_set.add(file.encode('utf-8'))
|
||||
db_known_files_set.add(api_client.encode_to(file, 'utf-8'))
|
||||
|
||||
new_files = self.mmc.scan_dir_for_new_files(dir)
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ class AirtimeMetadata:
|
|||
if (isinstance(md[key], basestring)):
|
||||
#self.logger.info("Converting md[%s] = '%s' ", key, md[key])
|
||||
md[key] = api_client.to_unicode(md[key])
|
||||
md[key] = md[key].encode('utf-8')
|
||||
md[key] = api_client.encode_to(md[key], 'utf-8')
|
||||
#self.logger.info("Converting complete: md[%s] = '%s' ", key, md[key])
|
||||
|
||||
return md
|
||||
|
|
|
@ -11,6 +11,7 @@ import pyinotify
|
|||
from pyinotify import Notifier
|
||||
|
||||
#from api_clients import api_client
|
||||
from api_clients import api_client
|
||||
from airtimemetadata import AirtimeMetadata
|
||||
|
||||
class AirtimeNotifier(Notifier):
|
||||
|
@ -74,7 +75,7 @@ class AirtimeNotifier(Notifier):
|
|||
self.watch_directory(m['directory'])
|
||||
|
||||
elif m['event_type'] == "remove_watch":
|
||||
watched_directory = m['directory'].encode('utf-8')
|
||||
watched_directory = api_client.encode_to(m['directory'], 'utf-8')
|
||||
|
||||
mm = self.proc_fun()
|
||||
wd = mm.wm.get_wd(watched_directory)
|
||||
|
@ -83,8 +84,8 @@ class AirtimeNotifier(Notifier):
|
|||
|
||||
elif m['event_type'] == "change_stor":
|
||||
storage_directory = self.config.storage_directory
|
||||
new_storage_directory = m['directory'].encode('utf-8')
|
||||
new_storage_directory_id = str(m['dir_id']).encode('utf-8')
|
||||
new_storage_directory = api_client.encode_to(m['directory'], 'utf-8')
|
||||
new_storage_directory_id = api_client.encode_to(str(m['dir_id']), 'utf-8')
|
||||
|
||||
mm = self.proc_fun()
|
||||
|
||||
|
@ -108,7 +109,7 @@ class AirtimeNotifier(Notifier):
|
|||
|
||||
self.watch_directory(new_storage_directory)
|
||||
elif m['event_type'] == "file_delete":
|
||||
filepath = m['filepath'].encode('utf-8')
|
||||
filepath = api_client.encode_to(m['filepath'], 'utf-8')
|
||||
|
||||
mm = self.proc_fun()
|
||||
self.logger.info("Adding file to ignore: %s ", filepath)
|
||||
|
|
|
@ -5,6 +5,7 @@ import logging
|
|||
|
||||
from subprocess import Popen, PIPE
|
||||
from airtimemetadata import AirtimeMetadata
|
||||
from api_clients import api_client
|
||||
|
||||
class MediaMonitorCommon:
|
||||
|
||||
|
@ -164,14 +165,14 @@ class MediaMonitorCommon:
|
|||
try:
|
||||
#will be in the format .ext
|
||||
file_ext = os.path.splitext(original_path)[1]
|
||||
file_ext = file_ext.encode('utf-8')
|
||||
file_ext = api_client.encode_to(file_ext, 'utf-8')
|
||||
|
||||
path_md = ['MDATA_KEY_TITLE', 'MDATA_KEY_CREATOR', 'MDATA_KEY_SOURCE', 'MDATA_KEY_TRACKNUMBER', 'MDATA_KEY_BITRATE']
|
||||
|
||||
md = {}
|
||||
for m in path_md:
|
||||
if m not in orig_md:
|
||||
md[m] = u'unknown'.encode('utf-8')
|
||||
md[m] = api_client.encode_to(u'unknown', 'utf-8')
|
||||
else:
|
||||
#get rid of any "/" which will interfere with the filepath.
|
||||
if isinstance(orig_md[m], basestring):
|
||||
|
@ -189,10 +190,10 @@ class MediaMonitorCommon:
|
|||
filepath = None
|
||||
#file is recorded by Airtime
|
||||
#/srv/airtime/stor/recorded/year/month/year-month-day-time-showname-bitrate.ext
|
||||
if(md['MDATA_KEY_CREATOR'] == "Airtime Show Recorder".encode('utf-8')):
|
||||
if(md['MDATA_KEY_CREATOR'] == api_client.encode_to("Airtime Show Recorder", 'utf-8')):
|
||||
#yyyy-mm-dd-hh-MM-ss
|
||||
y = orig_md['MDATA_KEY_YEAR'].split("-")
|
||||
filepath = '%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "recorded".encode('utf-8'), y[0], y[1], orig_md['MDATA_KEY_YEAR'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
|
||||
filepath = '%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)
|
||||
|
||||
#"Show-Title-2011-03-28-17:15:00"
|
||||
title = md['MDATA_KEY_TITLE'].split("-")
|
||||
|
@ -206,10 +207,10 @@ class MediaMonitorCommon:
|
|||
new_md['MDATA_KEY_TITLE'] = '%s-%s-%s:%s:%s' % (show_name, orig_md['MDATA_KEY_YEAR'], show_hour, show_min, show_sec)
|
||||
self.md_manager.save_md_to_file(new_md)
|
||||
|
||||
elif(md['MDATA_KEY_TRACKNUMBER'] == u'unknown'.encode('utf-8')):
|
||||
filepath = '%s/%s/%s/%s/%s-%s%s' % (storage_directory, "imported".encode('utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
|
||||
elif(md['MDATA_KEY_TRACKNUMBER'] == api_client.encode_to(u'unknown', 'utf-8')):
|
||||
filepath = '%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)
|
||||
else:
|
||||
filepath = '%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "imported".encode('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 = '%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 = self.create_unique_filename(filepath, original_path)
|
||||
self.logger.info('Unique filepath: %s', filepath)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue