From 065311d0d800a94a7f96e2ec3ee34e8e463b1e74 Mon Sep 17 00:00:00 2001 From: Schimon Jehudah Date: Sat, 10 Feb 2024 23:25:05 +0000 Subject: [PATCH] Add switch for media --- slixfeed/assets/settings.ini | 3 +++ slixfeed/task.py | 10 ++++++---- slixfeed/xmpp/process.py | 20 ++++++++++++++++++++ slixfeed/xmpp/utility.py | 8 ++++---- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/slixfeed/assets/settings.ini b/slixfeed/assets/settings.ini index 9b50867..74313ca 100644 --- a/slixfeed/assets/settings.ini +++ b/slixfeed/assets/settings.ini @@ -24,6 +24,9 @@ interval = 300 # Maximum length of summary (Value 0 to disable) length = 300 +# Display media (audio, image, video) when available +media = 0 + # Mark entries of newly added entries as unread old = 0 diff --git a/slixfeed/task.py b/slixfeed/task.py index fd1b042..3f1ba13 100644 --- a/slixfeed/task.py +++ b/slixfeed/task.py @@ -198,6 +198,7 @@ async def xmpp_send_update(self, jid, num=None): db_file = config.get_pathname_to_database(jid_file) enabled = await config.get_setting_value(db_file, 'enabled') if enabled: + show_media = await config.get_setting_value(db_file, 'media') if not num: num = await config.get_setting_value(db_file, 'quantum') else: @@ -227,10 +228,11 @@ async def xmpp_send_update(self, jid, num=None): # elif enclosure.startswith("magnet:"): # media = action.get_magnet(enclosure) # elif enclosure: - if enclosure: - media = enclosure - else: - media = await action.extract_image_from_html(url) + if show_media: + if enclosure: + media = enclosure + else: + media = await action.extract_image_from_html(url) if media and news_digest: # Send textual message diff --git a/slixfeed/xmpp/process.py b/slixfeed/xmpp/process.py index af8a9e5..dae73c3 100644 --- a/slixfeed/xmpp/process.py +++ b/slixfeed/xmpp/process.py @@ -615,6 +615,26 @@ async def message(self, message): # else: # response = 'Missing value.' XmppMessage.send_reply(self, message, response) + case 'media off': + db_file = config.get_pathname_to_database(jid_file) + key = 'media' + val = 0 + if await sqlite.get_settings_value(db_file, key): + await sqlite.update_settings_value(db_file, [key, val]) + else: + await sqlite.set_settings_value(db_file, [key, val]) + response = 'Media is disabled.' + XmppMessage.send_reply(self, message, response) + case 'media on': + db_file = config.get_pathname_to_database(jid_file) + key = 'media' + val = 1 + if await sqlite.get_settings_value(db_file, key): + await sqlite.update_settings_value(db_file, [key, val]) + else: + await sqlite.set_settings_value(db_file, [key, val]) + response = 'Media is enabled.' + XmppMessage.send_reply(self, message, response) case 'new': db_file = config.get_pathname_to_database(jid_file) key = 'old' diff --git a/slixfeed/xmpp/utility.py b/slixfeed/xmpp/utility.py index 55d65c5..24754a1 100644 --- a/slixfeed/xmpp/utility.py +++ b/slixfeed/xmpp/utility.py @@ -57,7 +57,7 @@ async def get_chat_type(self, jid): 'Jabber ID: {}' .format(e, jid)) logging.error(message) - except BaseException as e: - logging.error('BaseException', str(e)) - finally: - logging.info('Chat type is:', chat_type) + # except BaseException as e: + # logging.error('BaseException', str(e)) + # finally: + # logging.info('Chat type is:', chat_type)