From 6ebb1fd5558eb6388cee243ed1ef312754f8f1fb Mon Sep 17 00:00:00 2001 From: Kyle Robbertze Date: Thu, 23 Jan 2020 12:37:49 +0200 Subject: [PATCH] more pypo fixes --- installer/lib/requirements-debian-buster.apt | 2 + installer/lib/requirements-debian-stretch.apt | 2 + installer/lib/requirements-ubuntu-bionic.apt | 2 + installer/lib/requirements-ubuntu-xenial.apt | 2 + ...uirements-ubuntu-xenial_docker_minimal.apt | 2 + .../api_clients/api_clients/api_client.py | 43 +++++----- python_apps/pypo/liquidsoap/__main__.py | 11 ++- .../liquidsoap/generate_liquidsoap_cfg.py | 8 +- python_apps/pypo/pypo/__main__.py | 8 +- python_apps/pypo/pypo/pure.py | 12 ++- python_apps/pypo/pypo/pypofetch.py | 45 ++++------ python_apps/pypo/pypo/pypoliquidsoap.py | 41 +++++----- python_apps/pypo/pypo/telnetliquidsoap.py | 82 +++++++++---------- python_apps/pypo/setup.py | 3 +- 14 files changed, 132 insertions(+), 131 deletions(-) diff --git a/installer/lib/requirements-debian-buster.apt b/installer/lib/requirements-debian-buster.apt index 3dc1121c3..7438d1e0f 100644 --- a/installer/lib/requirements-debian-buster.apt +++ b/installer/lib/requirements-debian-buster.apt @@ -4,6 +4,8 @@ curl ecasound flac git +gstreamer1.0-plugins-bad +gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly icecast2 lame diff --git a/installer/lib/requirements-debian-stretch.apt b/installer/lib/requirements-debian-stretch.apt index ace712897..5dcf1e199 100644 --- a/installer/lib/requirements-debian-stretch.apt +++ b/installer/lib/requirements-debian-stretch.apt @@ -4,6 +4,8 @@ curl ecasound flac git +gstreamer1.0-plugins-bad +gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly icecast2 lame diff --git a/installer/lib/requirements-ubuntu-bionic.apt b/installer/lib/requirements-ubuntu-bionic.apt index d45f05564..0254b3d3c 100644 --- a/installer/lib/requirements-ubuntu-bionic.apt +++ b/installer/lib/requirements-ubuntu-bionic.apt @@ -4,6 +4,8 @@ coreutils curl ecasound flac +gstreamer1.0-plugins-bad +gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly icecast2 lame diff --git a/installer/lib/requirements-ubuntu-xenial.apt b/installer/lib/requirements-ubuntu-xenial.apt index 275cc0200..df64d2fd2 100644 --- a/installer/lib/requirements-ubuntu-xenial.apt +++ b/installer/lib/requirements-ubuntu-xenial.apt @@ -4,6 +4,8 @@ coreutils curl ecasound flac +gstreamer1.0-plugins-bad +gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly icecast2 lame diff --git a/installer/lib/requirements-ubuntu-xenial_docker_minimal.apt b/installer/lib/requirements-ubuntu-xenial_docker_minimal.apt index 41257a70e..549db5c9d 100644 --- a/installer/lib/requirements-ubuntu-xenial_docker_minimal.apt +++ b/installer/lib/requirements-ubuntu-xenial_docker_minimal.apt @@ -4,6 +4,8 @@ coreutils curl ecasound flac +gstreamer1.0-plugins-bad +gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly lame libao-ocaml diff --git a/python_apps/api_clients/api_clients/api_client.py b/python_apps/api_clients/api_clients/api_client.py index 911fa6179..fb9cad33e 100644 --- a/python_apps/api_clients/api_clients/api_client.py +++ b/python_apps/api_clients/api_clients/api_client.py @@ -117,7 +117,8 @@ class ApiRequest(object): def __call__(self,_post_data=None, **kwargs): final_url = self.url.params(**kwargs).url() - if _post_data is not None: _post_data = urllib.parse.urlencode(_post_data) + if _post_data is not None: + _post_data = urllib.parse.urlencode(_post_data).encode('utf-8') self.logger.debug(final_url) try: req = urllib.request.Request(final_url, _post_data) @@ -131,8 +132,7 @@ class ApiRequest(object): self.logger.error('HTTP request to %s timed out', final_url) raise except Exception as e: - #self.logger.error('Exception: %s', e) - #self.logger.error("traceback: %s", traceback.format_exc()) + #self.logger.exception(e) raise try: @@ -142,8 +142,7 @@ class ApiRequest(object): else: raise InvalidContentType() except Exception: - #self.logger.error(response) - #self.logger.error("traceback: %s", traceback.format_exc()) + #self.logger.exception(e) raise def req(self, *args, **kwargs): @@ -182,8 +181,10 @@ class RequestProvider(object): def __contains__(self, request) : return request in self.requests def __getattr__(self, attr): - if attr in self: return self.requests[attr] - else: return super(RequestProvider, self).__getattribute__(attr) + if attr in self: + return self.requests[attr] + else: + return super(RequestProvider, self).__getattribute__(attr) class AirtimeApiClient(object): @@ -197,8 +198,7 @@ class AirtimeApiClient(object): self.config.update(api_config) self.services = RequestProvider(self.config) except Exception as e: - self.logger.error('Error loading config file: %s', config_path) - self.logger.error("traceback: %s", traceback.format_exc()) + self.logger.exception('Error loading config file: %s', config_path) sys.exit(1) def __get_airtime_version(self): @@ -239,7 +239,7 @@ class AirtimeApiClient(object): try: self.services.notify_liquidsoap_started() except Exception as e: - self.logger.error(str(e)) + self.logger.exception(e) def notify_media_item_start_playing(self, media_id): """ This is a callback from liquidsoap, we use this to notify @@ -248,14 +248,14 @@ class AirtimeApiClient(object): try: return self.services.update_start_playing_url(media_id=media_id) except Exception as e: - self.logger.error(str(e)) + self.logger.exception(e) return None def get_shows_to_record(self): try: return self.services.show_schedule_url() except Exception as e: - self.logger.error(str(e)) + self.logger.exception(e) return None def upload_recorded_show(self, files, show_id): @@ -307,8 +307,7 @@ class AirtimeApiClient(object): logger.error("Server is down: %s", e.args) logger.error("traceback: %s", traceback.format_exc()) except Exception as e: - logger.error("Exception: %s", e) - logger.error("traceback: %s", traceback.format_exc()) + self.logger.exception(e) #wait some time before next retry time.sleep(retries_wait) @@ -320,7 +319,7 @@ class AirtimeApiClient(object): return self.services.check_live_stream_auth( username=username, password=password, djtype=dj_type) except Exception as e: - self.logger.error(str(e)) + self.logger.exception(e) return {} def construct_url(self,config_action_key): @@ -468,17 +467,14 @@ class AirtimeApiClient(object): stream_id=stream_id, boot_time=time).retry(5) except Exception as e: - #TODO - logger.error("Exception: %s", e) + self.logger.exception(e) def notify_source_status(self, sourcename, status): try: - logger = self.logger return self.services.update_source_status.req(sourcename=sourcename, status=status).retry(5) except Exception as e: - #TODO - logger.error("Exception: %s", e) + self.logger.exception(e) def get_bootstrap_info(self): """ Retrieve infomations needed on bootstrap time """ @@ -494,7 +490,7 @@ class AirtimeApiClient(object): try: return self.services.get_files_without_replay_gain(dir_id=dir_id) except Exception as e: - self.logger.error(str(e)) + self.logger.exception(e) return [] def get_files_without_silan_value(self): @@ -506,7 +502,7 @@ class AirtimeApiClient(object): try: return self.services.get_files_without_silan_value() except Exception as e: - self.logger.error(str(e)) + self.logger.exception(e) return [] def update_replay_gain_values(self, pairs): @@ -549,8 +545,7 @@ class AirtimeApiClient(object): response = self.services.update_stream_setting_table(_post_data={'data': json.dumps(data)}) return response except Exception as e: - #TODO - self.logger.error(str(e)) + self.logger.exception(e) def update_metadata_on_tunein(self): self.services.update_metadata_on_tunein() diff --git a/python_apps/pypo/liquidsoap/__main__.py b/python_apps/pypo/liquidsoap/__main__.py index d7ac1bbb6..4be598d1c 100644 --- a/python_apps/pypo/liquidsoap/__main__.py +++ b/python_apps/pypo/liquidsoap/__main__.py @@ -1,12 +1,11 @@ """ Runs Airtime liquidsoap """ - - import argparse import os from . import generate_liquidsoap_cfg import logging import subprocess +from pypo import pure PYPO_HOME = '/var/tmp/airtime/pypo/' @@ -16,16 +15,16 @@ def run(): parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", help="run in debug mode", action="store_true") args = parser.parse_args() - + os.environ["HOME"] = PYPO_HOME if args.debug: logging.basicConfig(level=getattr(logging, 'DEBUG', None)) - + generate_liquidsoap_cfg.run() ''' check liquidsoap version if less than 1.3 use legacy liquidsoap script ''' - liquidsoap_version=subprocess.check_output("liquidsoap --version", shell=True) - if "1.1.1" not in liquidsoap_version: + liquidsoap_version = subprocess.check_output("liquidsoap --version", shell=True, text=True) + if pure.version_cmp(liquidsoap_version, "1.3") < 0: script_path = os.path.join(os.path.dirname(__file__), 'ls_script.liq') else: script_path = os.path.join(os.path.dirname(__file__), 'ls_script_legacy.liq') diff --git a/python_apps/pypo/liquidsoap/generate_liquidsoap_cfg.py b/python_apps/pypo/liquidsoap/generate_liquidsoap_cfg.py index d35e2333f..27bc927f2 100644 --- a/python_apps/pypo/liquidsoap/generate_liquidsoap_cfg.py +++ b/python_apps/pypo/liquidsoap/generate_liquidsoap_cfg.py @@ -28,21 +28,21 @@ def generate_liquidsoap_config(ss): except: #Everything else is a string str_buffer = "%s = \"%s\"\n" % (key, value) - fh.write(str_buffer.encode('utf-8')) + fh.write(str_buffer) # ignore squashes unused variable errors from Liquidsoap - fh.write(("ignore(%s)\n" % key).encode('utf-8')) + fh.write("ignore(%s)\n" % key) auth_path = os.path.dirname(os.path.realpath(__file__)) fh.write('log_file = "/var/log/airtime/pypo-liquidsoap/