♻️ refactor code ♻️
This commit is contained in:
@@ -184,3 +184,5 @@ fabric.properties
|
||||
|
||||
# idea folder, uncomment if you don't need it
|
||||
.idea
|
||||
|
||||
*.zip
|
||||
@@ -44,7 +44,6 @@ class YaMusicCustom:
|
||||
async def init(self):
|
||||
await self.client.init()
|
||||
|
||||
@staticmethod
|
||||
def _fix_revision_bug(self, object_with_revision_param):
|
||||
object_with_revision_param.revision += 1
|
||||
return object_with_revision_param
|
||||
@@ -113,7 +112,6 @@ class YaMusicCustom:
|
||||
# return created playlist
|
||||
return playlist
|
||||
|
||||
@staticmethod
|
||||
async def clean_playlist(self, playlist: Playlist):
|
||||
playlist_tracks = await playlist.fetch_tracks_async()
|
||||
if len(playlist_tracks) != 0:
|
||||
@@ -158,13 +156,11 @@ class YaMusicCustom:
|
||||
return
|
||||
await asyncio.sleep(.1)
|
||||
|
||||
@staticmethod
|
||||
def get_controller_playlist_url(self, playlist: Playlist, turn_play=False):
|
||||
url = TARGET_CONTROL_PLAYLIST_URL_FORMAT.format(user_id=playlist.owner.login,
|
||||
playlist_id=playlist.kind)
|
||||
return url if not turn_play else f'{url}{POSTFIX_URL_PLAY}'
|
||||
|
||||
@staticmethod
|
||||
def get_track_url(self, track: Track, turn_play=False):
|
||||
track_id, album_id = track.track_id.split(':')
|
||||
url = TRACK_URL_FORMAT.format(track_id=track_id, album_id=album_id)
|
||||
@@ -234,7 +230,6 @@ class NtfyServerInterface:
|
||||
return None, Exception(
|
||||
f'Timeout, the maximum number of attempts (max time {self.MAX_TRIES_COUNT * self.REPEAT_EVERY_IN_SECONDS} in sec) was called..')
|
||||
|
||||
@staticmethod
|
||||
def download_photo_bin_and_base64_from_ntfy_message(self, message):
|
||||
# get url from message object
|
||||
url = message['attachment']['url']
|
||||
@@ -255,7 +250,7 @@ def prepare_and_return_result(request_type: str, response_data):
|
||||
}}
|
||||
|
||||
|
||||
async def main(
|
||||
async def main_asynched(
|
||||
i_YA_TOKEN_1,
|
||||
i_YA_TOKEN_2,
|
||||
i_INPUT_QUERY,
|
||||
@@ -264,7 +259,7 @@ async def main(
|
||||
i_NTFY_SEND_TOPIC,
|
||||
i_NTFY_SEND_USER,
|
||||
i_NTFY_SEND_PASS,
|
||||
) -> dict[str, dict[Any, Any]]:
|
||||
):
|
||||
i_ya_token = f'{i_YA_TOKEN_1}{i_YA_TOKEN_2}'
|
||||
global SEARCH_TAG_PREFIX
|
||||
global MESSAGE_CMD__PLAY_TRACK_RAW
|
||||
@@ -342,9 +337,11 @@ async def main(
|
||||
|
||||
result_data = None
|
||||
if i_REQUEST_TYPE == 'play_favorites':
|
||||
result_data = await play_favorites_track_main()
|
||||
await play_favorites_track_main()
|
||||
result_data = {"status": "success", "message": "Playing favorites"}
|
||||
elif i_REQUEST_TYPE == 'play_track':
|
||||
result_data = await play_single_track_main(request_text=i_INPUT_QUERY)
|
||||
await play_single_track_main(request_text=i_INPUT_QUERY)
|
||||
result_data = {"status": "success", "message": f"Playing track: {i_INPUT_QUERY}"}
|
||||
|
||||
# manual track play challenge
|
||||
elif i_REQUEST_TYPE == '':
|
||||
@@ -356,3 +353,7 @@ async def main(
|
||||
await play_single_track_main(request_text=input_query)
|
||||
|
||||
return prepare_and_return_result(request_type=i_REQUEST_TYPE, response_data=result_data)
|
||||
|
||||
|
||||
def main(**kwargs) -> dict[str, dict[Any, Any]]:
|
||||
return asyncio.run(main_asynched(**kwargs))
|
||||
|
||||
@@ -18,28 +18,37 @@ if __name__ == '__main__':
|
||||
NTFY_SEND_USER = os.getenv('NTFY_SEND_USER')
|
||||
NTFY_SEND_PASS = os.getenv('NTFY_SEND_PASS')
|
||||
|
||||
# configure
|
||||
# params
|
||||
request_type = 'play_favorites'
|
||||
input_query = ''
|
||||
print(f'[*] TEST: {request_type} {input_query}')
|
||||
|
||||
# #test example to run favorite playlist
|
||||
asyncio.run(main.main(
|
||||
main.main(
|
||||
i_YA_TOKEN_1=YA_TOKEN_1,
|
||||
i_YA_TOKEN_2=YA_TOKEN_2,
|
||||
i_REQUEST_TYPE='play_favorites',
|
||||
i_INPUT_QUERY='',
|
||||
i_REQUEST_TYPE=request_type,
|
||||
i_INPUT_QUERY=input_query,
|
||||
i_NTFY_SERVER=NTFY_SERVER,
|
||||
i_NTFY_SEND_TOPIC=NTFY_SEND_TOPIC,
|
||||
i_NTFY_SEND_USER=NTFY_SEND_USER,
|
||||
i_NTFY_SEND_PASS=NTFY_SEND_PASS
|
||||
))
|
||||
)
|
||||
|
||||
print('\n')
|
||||
# params
|
||||
request_type = 'play_track'
|
||||
input_query = 'Не дано хайфай'
|
||||
print(f'[*] TEST: {request_type} {input_query}')
|
||||
|
||||
# #test example to single run
|
||||
asyncio.run(main.main(
|
||||
main.main(
|
||||
i_YA_TOKEN_1=YA_TOKEN_1,
|
||||
i_YA_TOKEN_2=YA_TOKEN_2,
|
||||
i_REQUEST_TYPE='play_track',
|
||||
i_INPUT_QUERY='Не дано хайфай',
|
||||
i_REQUEST_TYPE=request_type,
|
||||
i_INPUT_QUERY=input_query,
|
||||
i_NTFY_SERVER=NTFY_SERVER,
|
||||
i_NTFY_SEND_TOPIC=NTFY_SEND_TOPIC,
|
||||
i_NTFY_SEND_USER=NTFY_SEND_USER,
|
||||
i_NTFY_SEND_PASS=NTFY_SEND_PASS
|
||||
))
|
||||
)
|
||||
Reference in New Issue
Block a user