feat(api-client): remove unused api v1 calls
This commit is contained in:
parent
ad00272168
commit
98aaa4214a
|
@ -1,12 +1,10 @@
|
|||
import json
|
||||
import logging
|
||||
import time
|
||||
import urllib.parse
|
||||
|
||||
import requests
|
||||
from libretime_shared.config import BaseConfig, GeneralConfig
|
||||
|
||||
from ._utils import ApiRequest, RequestProvider
|
||||
from ._utils import RequestProvider
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -27,20 +25,10 @@ api_endpoints[
|
|||
"register_component"
|
||||
] = "register-component/format/json/api_key/{api_key}/component/{component}"
|
||||
|
||||
# media-monitor
|
||||
api_endpoints[
|
||||
"upload_recorded"
|
||||
] = "upload-recorded/format/json/api_key/{api_key}/fileid/{fileid}/showinstanceid/{showinstanceid}"
|
||||
# show-recorder
|
||||
api_endpoints["show_schedule_url"] = "recorded-shows/format/json/api_key/{api_key}"
|
||||
api_endpoints["upload_file_url"] = "rest/media"
|
||||
# pypo
|
||||
api_endpoints[
|
||||
"update_start_playing_url"
|
||||
] = "notify-media-item-start-play/api_key/{api_key}/media_id/{media_id}/"
|
||||
api_endpoints[
|
||||
"get_stream_setting"
|
||||
] = "get-stream-setting/format/json/api_key/{api_key}/"
|
||||
api_endpoints[
|
||||
"update_liquidsoap_status"
|
||||
] = "update-liquidsoap-status/format/json/api_key/{api_key}/msg/{msg}/stream_id/{stream_id}/boot_time/{boot_time}"
|
||||
|
@ -50,16 +38,12 @@ api_endpoints[
|
|||
api_endpoints[
|
||||
"check_live_stream_auth"
|
||||
] = "check-live-stream-auth/format/json/api_key/{api_key}/username/{username}/password/{password}/djtype/{djtype}"
|
||||
api_endpoints["get_bootstrap_info"] = "get-bootstrap-info/format/json/api_key/{api_key}"
|
||||
api_endpoints[
|
||||
"notify_webstream_data"
|
||||
] = "notify-webstream-data/api_key/{api_key}/media_id/{media_id}/format/json"
|
||||
api_endpoints[
|
||||
"notify_liquidsoap_started"
|
||||
] = "rabbitmq-do-push/api_key/{api_key}/format/json"
|
||||
api_endpoints[
|
||||
"get_stream_parameters"
|
||||
] = "get-stream-parameters/api_key/{api_key}/format/json"
|
||||
api_endpoints["push_stream_stats"] = "push-stream-stats/api_key/{api_key}/format/json"
|
||||
api_endpoints[
|
||||
"update_stream_setting_table"
|
||||
|
@ -132,71 +116,6 @@ class ApiClient:
|
|||
logger.exception(exception)
|
||||
return None
|
||||
|
||||
def get_shows_to_record(self):
|
||||
try:
|
||||
return self.services.show_schedule_url()
|
||||
except Exception as exception:
|
||||
logger.exception(exception)
|
||||
return None
|
||||
|
||||
def upload_recorded_show(self, files, show_id):
|
||||
response = ""
|
||||
|
||||
retries = self.UPLOAD_RETRIES
|
||||
retries_wait = self.UPLOAD_WAIT
|
||||
|
||||
url = self.construct_rest_url("upload_file_url")
|
||||
|
||||
logger.debug(url)
|
||||
|
||||
for i in range(0, retries):
|
||||
logger.debug("Upload attempt: %s", i + 1)
|
||||
logger.debug(files)
|
||||
logger.debug(ApiRequest.API_HTTP_REQUEST_TIMEOUT)
|
||||
|
||||
try:
|
||||
request = requests.post(
|
||||
url, files=files, timeout=float(ApiRequest.API_HTTP_REQUEST_TIMEOUT)
|
||||
)
|
||||
response = request.json()
|
||||
logger.debug(response)
|
||||
|
||||
# FIXME: We need to tell LibreTime that the uploaded track was recorded
|
||||
# for a specific show
|
||||
#
|
||||
# My issue here is that response does not yet have an id. The id gets
|
||||
# generated at the point where analyzer is done with it's work. We
|
||||
# probably need to do what is below in analyzer and also make sure that
|
||||
# the show instance id is routed all the way through.
|
||||
#
|
||||
# It already gets uploaded by this but the RestController does not seem
|
||||
# to care about it. In the end analyzer doesn't have the info in it's
|
||||
# rabbitmq message and imports the show as a regular track.
|
||||
#
|
||||
# logger.info("uploaded show result as file id %s", response.id)
|
||||
#
|
||||
# url = self.construct_url("upload_recorded") url =
|
||||
# url.replace('%%fileid%%', response.id) url =
|
||||
# url.replace('%%showinstanceid%%', show_id) request.get(url)
|
||||
# logger.info("associated uploaded file %s with show instance %s",
|
||||
# response.id, show_id)
|
||||
break
|
||||
|
||||
except requests.exceptions.HTTPError as exception:
|
||||
logger.error("Http error code: %s", exception.response.status_code)
|
||||
logger.exception(exception)
|
||||
|
||||
except requests.exceptions.ConnectionError as exception:
|
||||
logger.exception("Server is down: %s", exception)
|
||||
|
||||
except Exception as exception:
|
||||
logger.exception(exception)
|
||||
|
||||
# wait some time before next retry
|
||||
time.sleep(retries_wait)
|
||||
|
||||
return response
|
||||
|
||||
def check_live_stream_auth(self, username, password, dj_type):
|
||||
try:
|
||||
return self.services.check_live_stream_auth(
|
||||
|
@ -206,17 +125,6 @@ class ApiClient:
|
|||
logger.exception(exception)
|
||||
return {}
|
||||
|
||||
def construct_rest_url(self, action_key):
|
||||
"""
|
||||
Constructs the base url for RESTful requests
|
||||
"""
|
||||
url = urllib.parse.urlsplit(self.base_url)
|
||||
url.username = self.api_key
|
||||
return f"{url.geturl()}/{api_endpoints[action_key]}"
|
||||
|
||||
def get_stream_setting(self):
|
||||
return self.services.get_stream_setting()
|
||||
|
||||
def register_component(self, component):
|
||||
"""
|
||||
Purpose of this method is to contact the server with a "Hey its
|
||||
|
@ -249,12 +157,6 @@ class ApiClient:
|
|||
except Exception as exception:
|
||||
logger.exception(exception)
|
||||
|
||||
def get_bootstrap_info(self):
|
||||
"""
|
||||
Retrieve infomations needed on bootstrap time.
|
||||
"""
|
||||
return self.services.get_bootstrap_info()
|
||||
|
||||
def notify_webstream_data(self, data, media_id):
|
||||
"""
|
||||
Update the server with the latest metadata we've received from the
|
||||
|
@ -266,11 +168,6 @@ class ApiClient:
|
|||
).retry(5)
|
||||
)
|
||||
|
||||
def get_stream_parameters(self):
|
||||
response = self.services.get_stream_parameters()
|
||||
logger.debug(response)
|
||||
return response
|
||||
|
||||
def push_stream_stats(self, data):
|
||||
# TODO : users of this method should do their own error handling
|
||||
response = self.services.push_stream_stats(
|
||||
|
@ -289,7 +186,3 @@ class ApiClient:
|
|||
|
||||
def update_metadata_on_tunein(self):
|
||||
self.services.update_metadata_on_tunein()
|
||||
|
||||
|
||||
class InvalidContentType(Exception):
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue