This commit is contained in:
user 2024-04-05 15:09:03 +03:00
parent 410cfe320b
commit 0d781c06ec
2 changed files with 11 additions and 5 deletions

View File

@ -26,11 +26,8 @@ async def t_callback_owned_content(query: types.CallbackQuery, memory=None, user
).all(): ).all():
try: try:
metadata_content = StoredContent.from_cid(db_session, content.json_format()['metadata_cid']) metadata_content = StoredContent.from_cid(db_session, content.json_format()['metadata_cid'])
make_log("OwnedContent", f"Metadata content: {metadata_content.filepath}")
with open(metadata_content.filepath, 'r') as f: with open(metadata_content.filepath, 'r') as f:
metadata_content_json = json.loads(f.read()) metadata_content_json = json.loads(f.read())
make_log("OwnedContent", f"Metadata content: {metadata_content_json}")
except BaseException as e: except BaseException as e:
make_log("OwnedContent", f"Can't get metadata content: {e}", level='warning') make_log("OwnedContent", f"Can't get metadata content: {e}", level='warning')
continue continue

View File

@ -5,6 +5,7 @@ from app.core._utils.tg_process_template import tg_process_template
from app.core._config import PROJECT_HOST from app.core._config import PROJECT_HOST
from app.core._keyboards import get_inline_keyboard from app.core._keyboards import get_inline_keyboard
from aiogram.types import URLInputFile from aiogram.types import URLInputFile
import json
class PlayerTemplates: class PlayerTemplates:
@ -39,6 +40,10 @@ class PlayerTemplates:
except: except:
content_type, content_encoding = 'application', 'x-binary' content_type, content_encoding = 'application', 'x-binary'
content_metadata = StoredContent.from_cid(db_session, content_meta.get('metadata_cid') or None)
with open(content_metadata.filepath, 'r') as f:
content_metadata_json = json.loads(f.read())
try: try:
cover_content = StoredContent.from_cid(self.db_session, content_meta.get('cover_cid') or None) cover_content = StoredContent.from_cid(self.db_session, content_meta.get('cover_cid') or None)
except BaseException as e: except BaseException as e:
@ -49,8 +54,12 @@ class PlayerTemplates:
local_content_cid.content_type = 'audio/mpeg' local_content_cid.content_type = 'audio/mpeg'
local_content_url = f"{PROJECT_HOST}/api/v1/storage/{local_content_cid.serialize_v2(include_accept_type=True)}" local_content_url = f"{PROJECT_HOST}/api/v1/storage/{local_content_cid.serialize_v2(include_accept_type=True)}"
if content_type == 'audio': if content_type == 'audio':
template_kwargs['title'] = 'title' audio_title = content_metadata_json.get('name', "").split(' - ')
template_kwargs['performer'] = 'performer' if len(audio_title) > 1:
template_kwargs['performer'] = audio_title[0].strip()
audio_title = audio_title[1:]
template_kwargs['title'] = audio_title[0].strip()
template_kwargs['protect_content'] = True template_kwargs['protect_content'] = True
template_kwargs['audio'] = URLInputFile(local_content_url) template_kwargs['audio'] = URLInputFile(local_content_url)
if cover_content: if cover_content: