From 2008f73e14bfd23f0c01f07bc06dd81a4406cb50 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 6 Apr 2024 09:09:31 +0300 Subject: [PATCH] fix --- app/api/routes/node_storage.py | 22 ++++++++++++++++++++++ app/core/background/license_service.py | 14 ++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/api/routes/node_storage.py b/app/api/routes/node_storage.py index 5af00c2..030cd26 100644 --- a/app/api/routes/node_storage.py +++ b/app/api/routes/node_storage.py @@ -151,6 +151,28 @@ async def s_api_v1_storage_get(request, file_hash=None): cover_tempfile_path = None try: + file_ext = content.filename.split('.')[-1] + if file_ext == 'mp3': + audio = AudioSegment.from_mp3(file_path) + elif file_ext == 'wav': + audio = AudioSegment.from_wav(file_path) + elif file_ext == 'ogg': + audio = AudioSegment.from_ogg(file_path) + elif file_ext == 'flv': + audio = AudioSegment.from_flv(file_path) + + if not audio: + try: + audio = AudioSegment.from_file(file_path) + except BaseException as e: + make_log("Storage", f"Error loading audio from file: {e}", level="debug") + + if not audio: + try: + audio = AudioSegment(content_file_bin) + except BaseException as e: + make_log("Storage", f"Error loading audio from binary: {e}", level="debug") + audio = AudioSegment(content_file_bin) audio = audio[:seconds_limit * 1000] if seconds_limit else audio audio.export(tempfile_path, format="mp3", cover=cover_tempfile_path) diff --git a/app/core/background/license_service.py b/app/core/background/license_service.py index b2673d6..c79d83f 100644 --- a/app/core/background/license_service.py +++ b/app/core/background/license_service.py @@ -41,19 +41,21 @@ async def license_index_loop(memory, platform_found: bool, seqno: int) -> [bool, except BaseException as e: make_log("LicenseIndex", f"Error: {e}" + '\n' + traceback.format_exc(), level="error") - for content in session.query(UserContent).filter( + process_content = session.query(UserContent).filter( and_( UserContent.type.startswith('nft/'), - UserContent.updated < (datetime.now() - timedelta(minutes=15)), + UserContent.updated < (datetime.now() - timedelta(minutes=5)), ) - ): + ).first() + if process_content: make_log("LicenseIndex", f"Syncing content with blockchain: {content.id}", level="info") try: - await content.sync_with_chain(session) - content.updated = datetime.now() - session.commit() + await process_content.sync_with_chain(session) except BaseException as e: make_log("LicenseIndex", f"Error: {e}" + '\n' + traceback.format_exc(), level="error") + finally: + process_content.updated = datetime.now() + session.commit() for action in session.query(UserAction).filter( and_(