-Remove useless api_client interface
This commit is contained in:
parent
7ce4934cdc
commit
62287a2313
9 changed files with 28 additions and 156 deletions
|
@ -13,27 +13,14 @@ import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
import base64
|
import base64
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
import string
|
import string
|
||||||
import hashlib
|
import traceback
|
||||||
|
|
||||||
AIRTIME_VERSION = "2.1.3"
|
AIRTIME_VERSION = "2.1.3"
|
||||||
|
|
||||||
def api_client_factory(config, logger=None):
|
|
||||||
if logger != None:
|
|
||||||
temp_logger = logger
|
|
||||||
else:
|
|
||||||
temp_logger = logging.getLogger()
|
|
||||||
|
|
||||||
if config["api_client"] == "airtime":
|
|
||||||
return AirTimeApiClient(temp_logger)
|
|
||||||
else:
|
|
||||||
temp_logger.info('API Client "'+config["api_client"]+'" not supported. Please check your config file.\n')
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
def to_unicode(obj, encoding='utf-8'):
|
def to_unicode(obj, encoding='utf-8'):
|
||||||
if isinstance(obj, basestring):
|
if isinstance(obj, basestring):
|
||||||
if not isinstance(obj, unicode):
|
if not isinstance(obj, unicode):
|
||||||
|
@ -44,120 +31,23 @@ def encode_to(obj, encoding='utf-8'):
|
||||||
if isinstance(obj, unicode):
|
if isinstance(obj, unicode):
|
||||||
obj = obj.encode(encoding)
|
obj = obj.encode(encoding)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def convert_dict_value_to_utf8(md):
|
def convert_dict_value_to_utf8(md):
|
||||||
#list comprehension to convert all values of md to utf-8
|
#list comprehension to convert all values of md to utf-8
|
||||||
return dict([(item[0], encode_to(item[1], "utf-8")) for item in md.items()])
|
return dict([(item[0], encode_to(item[1], "utf-8")) for item in md.items()])
|
||||||
|
|
||||||
class ApiClientInterface:
|
|
||||||
|
|
||||||
# Implementation: optional
|
|
||||||
#
|
|
||||||
# Called from: beginning of all scripts
|
|
||||||
#
|
|
||||||
# Should exit the program if this version of pypo is not compatible with
|
|
||||||
# 3rd party software.
|
|
||||||
def is_server_compatible(self, verbose = True):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Implementation: Required
|
|
||||||
#
|
|
||||||
# Called from: fetch loop
|
|
||||||
#
|
|
||||||
# This is the main method you need to implement when creating a new API client.
|
|
||||||
# start and end are for testing purposes.
|
|
||||||
# start and end are strings in the format YYYY-DD-MM-hh-mm-ss
|
|
||||||
def get_schedule(self, start=None, end=None):
|
|
||||||
return 0, []
|
|
||||||
|
|
||||||
# Implementation: Required
|
|
||||||
#
|
|
||||||
# Called from: fetch loop
|
|
||||||
#
|
|
||||||
# This downloads the media from the server.
|
|
||||||
def get_media(self, src, dst):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Implementation: optional
|
|
||||||
# You dont actually have to implement this function for the liquidsoap playout to work.
|
|
||||||
#
|
|
||||||
# Called from: pypo_notify.py
|
|
||||||
#
|
|
||||||
# This is a callback from liquidsoap, we use this to notify about the
|
|
||||||
# currently playing *song*. We get passed a JSON string which we handed to
|
|
||||||
# liquidsoap in get_liquidsoap_data().
|
|
||||||
def notify_media_item_start_playing(self, data, media_id):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Implementation: optional
|
|
||||||
# You dont actually have to implement this function for the liquidsoap playout to work.
|
|
||||||
def generate_range_dp(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Implementation: optional
|
|
||||||
#
|
|
||||||
# Called from: push loop
|
|
||||||
#
|
|
||||||
# Return a dict of extra info you want to pass to liquidsoap
|
|
||||||
# You will be able to use this data in update_start_playing
|
|
||||||
def get_liquidsoap_data(self, pkey, schedule):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_shows_to_record(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def upload_recorded_show(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def check_media_status(self, md5):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def update_media_metadata(self, md):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def list_all_db_files(self, dir_id):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def list_all_watched_dirs(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def add_watched_dir(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def remove_watched_dir(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def set_storage_dir(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def register_component(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def notify_liquidsoap_error(self, error_msg, stream_id):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def notify_liquidsoap_connection(self, stream_id):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Put here whatever tests you want to run to make sure your API is working
|
|
||||||
def test(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
#def get_media_type(self, playlist):
|
|
||||||
# nil
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Airtime API Client
|
# Airtime API Client
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
class AirTimeApiClient(ApiClientInterface):
|
class AirTimeApiClient():
|
||||||
|
|
||||||
def __init__(self, logger=None):
|
def __init__(self, logger=None):
|
||||||
if logger != None:
|
if logger is None:
|
||||||
self.logger = logger
|
self.logger = logging
|
||||||
else:
|
else:
|
||||||
self.logger = logging.getLogger()
|
self.logger = logger
|
||||||
|
|
||||||
# loading config file
|
# loading config file
|
||||||
try:
|
try:
|
||||||
self.config = ConfigObj('/etc/airtime/api_client.cfg')
|
self.config = ConfigObj('/etc/airtime/api_client.cfg')
|
||||||
|
|
|
@ -80,7 +80,7 @@ try:
|
||||||
configure_locale()
|
configure_locale()
|
||||||
|
|
||||||
config = AirtimeMediaConfig(logger)
|
config = AirtimeMediaConfig(logger)
|
||||||
api_client = apc.api_client_factory(config.cfg)
|
api_client = apc.AirTimeApiClient()
|
||||||
api_client.register_component("media-monitor")
|
api_client.register_component("media-monitor")
|
||||||
|
|
||||||
logger.info("Setting up monitor")
|
logger.info("Setting up monitor")
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from api_clients import api_client
|
from api_clients import api_client
|
||||||
from configobj import ConfigObj
|
|
||||||
|
|
||||||
def generate_liquidsoap_config(ss):
|
def generate_liquidsoap_config(ss):
|
||||||
data = ss['msg']
|
data = ss['msg']
|
||||||
|
@ -10,30 +9,22 @@ def generate_liquidsoap_config(ss):
|
||||||
fh.write("# THIS FILE IS AUTO GENERATED. DO NOT CHANGE!! #\n")
|
fh.write("# THIS FILE IS AUTO GENERATED. DO NOT CHANGE!! #\n")
|
||||||
fh.write("################################################\n")
|
fh.write("################################################\n")
|
||||||
for d in data:
|
for d in data:
|
||||||
buffer = d[u'keyname'] + " = "
|
str_buffer = d[u'keyname'] + " = "
|
||||||
if(d[u'type'] == 'string'):
|
if(d[u'type'] == 'string'):
|
||||||
temp = d[u'value']
|
temp = d[u'value']
|
||||||
buffer += '"%s"' % temp
|
str_buffer += '"%s"' % temp
|
||||||
else:
|
else:
|
||||||
temp = d[u'value']
|
temp = d[u'value']
|
||||||
if(temp == ""):
|
if(temp == ""):
|
||||||
temp = "0"
|
temp = "0"
|
||||||
buffer += temp
|
str_buffer += temp
|
||||||
buffer += "\n"
|
str_buffer += "\n"
|
||||||
fh.write(api_client.encode_to(buffer))
|
fh.write(api_client.encode_to(str_buffer))
|
||||||
fh.write('log_file = "/var/log/airtime/pypo-liquidsoap/<script>.log"\n')
|
fh.write('log_file = "/var/log/airtime/pypo-liquidsoap/<script>.log"\n')
|
||||||
fh.close()
|
fh.close()
|
||||||
|
|
||||||
PATH_INI_FILE = '/etc/airtime/pypo.cfg'
|
|
||||||
|
|
||||||
try:
|
|
||||||
config = ConfigObj(PATH_INI_FILE)
|
|
||||||
except Exception, e:
|
|
||||||
print 'Error loading config file: ', e
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
logging.basicConfig(format='%(message)s')
|
logging.basicConfig(format='%(message)s')
|
||||||
ac = api_client.api_client_factory(config, logging.getLogger())
|
ac = api_client(logging.getLogger())
|
||||||
ss = ac.get_stream_setting()
|
ss = ac.get_stream_setting()
|
||||||
|
|
||||||
if ss is not None:
|
if ss is not None:
|
||||||
|
|
|
@ -1,27 +1,18 @@
|
||||||
from api_clients import *
|
from api_clients import *
|
||||||
from configobj import ConfigObj
|
|
||||||
import sys
|
import sys
|
||||||
import json
|
|
||||||
|
|
||||||
try:
|
api_clients = api_client.AirTimeApiClient()
|
||||||
config = ConfigObj('/etc/airtime/pypo.cfg')
|
|
||||||
|
|
||||||
except Exception, e:
|
|
||||||
print 'error: ', e
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
api_clients = api_client.api_client_factory(config)
|
|
||||||
|
|
||||||
dj_type = sys.argv[1]
|
dj_type = sys.argv[1]
|
||||||
username = sys.argv[2]
|
username = sys.argv[2]
|
||||||
password = sys.argv[3]
|
password = sys.argv[3]
|
||||||
|
|
||||||
type = ''
|
source_type = ''
|
||||||
if dj_type == '--master':
|
if dj_type == '--master':
|
||||||
type = 'master'
|
source_type = 'master'
|
||||||
elif dj_type == '--dj':
|
elif dj_type == '--dj':
|
||||||
type = 'dj'
|
source_type = 'dj'
|
||||||
|
|
||||||
response = api_clients.check_live_stream_auth(username, password, type)
|
response = api_clients.check_live_stream_auth(username, password, type)
|
||||||
|
|
||||||
print response['msg']
|
print response['msg']
|
||||||
|
|
|
@ -107,10 +107,10 @@ except Exception, e:
|
||||||
|
|
||||||
class Global:
|
class Global:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.api_client = api_client.api_client_factory(config)
|
self.api_client = api_client.AirTimeApiClient()
|
||||||
|
|
||||||
def selfcheck(self):
|
def selfcheck(self):
|
||||||
self.api_client = api_client.api_client_factory(config)
|
self.api_client = api_client.AirTimeApiClient()
|
||||||
return self.api_client.is_server_compatible()
|
return self.api_client.is_server_compatible()
|
||||||
|
|
||||||
def test_api(self):
|
def test_api(self):
|
||||||
|
@ -172,7 +172,7 @@ if __name__ == '__main__':
|
||||||
g.test_api()
|
g.test_api()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
api_client = api_client.api_client_factory(config)
|
api_client = api_client.AirTimeApiClient()
|
||||||
api_client.register_component("pypo")
|
api_client.register_component("pypo")
|
||||||
|
|
||||||
pypoFetch_q = Queue()
|
pypoFetch_q = Queue()
|
||||||
|
|
|
@ -40,7 +40,7 @@ except Exception, e:
|
||||||
class PypoFetch(Thread):
|
class PypoFetch(Thread):
|
||||||
def __init__(self, pypoFetch_q, pypoPush_q, media_q, telnet_lock):
|
def __init__(self, pypoFetch_q, pypoPush_q, media_q, telnet_lock):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.api_client = api_client.api_client_factory(config)
|
self.api_client = api_client.AirTimeApiClient()
|
||||||
self.fetch_queue = pypoFetch_q
|
self.fetch_queue = pypoFetch_q
|
||||||
self.push_queue = pypoPush_q
|
self.push_queue = pypoPush_q
|
||||||
self.media_prepare_queue = media_q
|
self.media_prepare_queue = media_q
|
||||||
|
|
|
@ -64,7 +64,7 @@ except Exception, e:
|
||||||
|
|
||||||
class Notify:
|
class Notify:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.api_client = api_client.api_client_factory(config)
|
self.api_client = api_client.AirTimeApiClient()
|
||||||
|
|
||||||
def notify_media_start_playing(self, data, media_id):
|
def notify_media_start_playing(self, data, media_id):
|
||||||
logger = logging.getLogger("notify")
|
logger = logging.getLogger("notify")
|
||||||
|
|
|
@ -42,7 +42,7 @@ except Exception, e:
|
||||||
class PypoPush(Thread):
|
class PypoPush(Thread):
|
||||||
def __init__(self, q, telnet_lock):
|
def __init__(self, q, telnet_lock):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.api_client = api_client.api_client_factory(config)
|
self.api_client = api_client.AirTimeApiClient()
|
||||||
self.queue = q
|
self.queue = q
|
||||||
|
|
||||||
self.telnet_lock = telnet_lock
|
self.telnet_lock = telnet_lock
|
||||||
|
|
|
@ -46,7 +46,7 @@ class ShowRecorder(Thread):
|
||||||
def __init__ (self, show_instance, show_name, filelength, start_time):
|
def __init__ (self, show_instance, show_name, filelength, start_time):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.logger = logging.getLogger('recorder')
|
self.logger = logging.getLogger('recorder')
|
||||||
self.api_client = api_client.api_client_factory(config, self.logger)
|
self.api_client = api_client(self.logger)
|
||||||
self.filelength = filelength
|
self.filelength = filelength
|
||||||
self.start_time = start_time
|
self.start_time = start_time
|
||||||
self.show_instance = show_instance
|
self.show_instance = show_instance
|
||||||
|
@ -168,7 +168,7 @@ class Recorder(Thread):
|
||||||
def __init__(self, q):
|
def __init__(self, q):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.logger = logging.getLogger('recorder')
|
self.logger = logging.getLogger('recorder')
|
||||||
self.api_client = api_client.api_client_factory(config, self.logger)
|
self.api_client = api_client(self.logger)
|
||||||
self.api_client.register_component("show-recorder")
|
self.api_client.register_component("show-recorder")
|
||||||
self.sr = None
|
self.sr = None
|
||||||
self.shows_to_record = {}
|
self.shows_to_record = {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue