mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2026-03-07 01:47:32 +01:00
OCR en imágenes funciona.
This commit is contained in:
@@ -605,11 +605,72 @@ class BaseBuffer(base.Buffer):
|
||||
output.speak(_("Could not delete."), True)
|
||||
|
||||
|
||||
def audio(self, *args, **kwargs):
|
||||
output.speak(_("Audio playback not supported for Bluesky yet."))
|
||||
|
||||
# Helper to map standard keys if they don't invoke the methods above via get_event
|
||||
# But usually get_event is enough.
|
||||
def audio(self, event=None, item=None, *args, **kwargs):
|
||||
"""Play audio/video from the current post."""
|
||||
if sound.URLPlayer.player.is_playing():
|
||||
return sound.URLPlayer.stop_audio()
|
||||
if item is None:
|
||||
item = self.get_item()
|
||||
if not item:
|
||||
return
|
||||
urls = utils.get_media_urls(item)
|
||||
if not urls:
|
||||
output.speak(_("This post has no playable media."), True)
|
||||
return
|
||||
url = ""
|
||||
if len(urls) == 1:
|
||||
url = urls[0]
|
||||
elif len(urls) > 1:
|
||||
from wxUI.dialogs import urlList
|
||||
urls_list = urlList.urlList()
|
||||
urls_list.populate_list(urls)
|
||||
if urls_list.get_response() == widgetUtils.OK:
|
||||
url = urls_list.get_string()
|
||||
if hasattr(urls_list, "destroy"):
|
||||
urls_list.destroy()
|
||||
if url:
|
||||
sound.URLPlayer.play(url, self.session.settings["sound"]["volume"])
|
||||
|
||||
def ocr_image(self, *args, **kwargs):
|
||||
"""Perform OCR on images in the current post."""
|
||||
post = self.get_item()
|
||||
if not post:
|
||||
return
|
||||
|
||||
image_list = utils.get_image_urls(post)
|
||||
if not image_list:
|
||||
return
|
||||
|
||||
if len(image_list) > 1:
|
||||
from wxUI.dialogs import urlList
|
||||
labels = [_("Picture {0}").format(i + 1) for i in range(len(image_list))]
|
||||
dialog = urlList.urlList(title=_("Select the picture"))
|
||||
dialog.populate_list(labels)
|
||||
if dialog.get_response() != widgetUtils.OK:
|
||||
return
|
||||
img = image_list[dialog.get_item()]
|
||||
else:
|
||||
img = image_list[0]
|
||||
|
||||
url = img.get("url")
|
||||
if not url:
|
||||
return
|
||||
|
||||
from extra import ocr as ocr_module
|
||||
api = ocr_module.OCRSpace.OCRSpaceAPI()
|
||||
try:
|
||||
text = api.OCR_URL(url)
|
||||
except ocr_module.OCRSpace.APIError:
|
||||
output.speak(_("Unable to extract text"), True)
|
||||
return
|
||||
except Exception as e:
|
||||
log.error("OCR error: %s", e)
|
||||
output.speak(_("Unable to extract text"), True)
|
||||
return
|
||||
|
||||
viewer = blueski_messages.text(title=_("OCR Result"), text=text["ParsedText"])
|
||||
viewer.message.ShowModal()
|
||||
viewer.message.Destroy()
|
||||
|
||||
# Also implement "view_item" if standard keymap uses it
|
||||
def get_formatted_message(self):
|
||||
|
||||
@@ -215,11 +215,40 @@ class Conversation(BaseBuffer):
|
||||
traverse(thread)
|
||||
self.session.db[self.name] = []
|
||||
self.buffer.list.clear()
|
||||
return self.process_items(final_items, play_sound)
|
||||
# Don't use process_items() because it applies reverse logic.
|
||||
# Conversations should always be chronological (oldest first).
|
||||
return self._add_items_chronological(final_items, play_sound)
|
||||
except Exception as e:
|
||||
log.error("Error fetching thread: %s", e)
|
||||
return 0
|
||||
|
||||
def _add_items_chronological(self, items, play_sound=True):
|
||||
"""Add items in chronological order (oldest first) without reverse logic."""
|
||||
if not items:
|
||||
return 0
|
||||
|
||||
safe = True
|
||||
relative_times = self.session.settings["general"].get("relative_times", False)
|
||||
show_screen_names = self.session.settings["general"].get("show_screen_names", False)
|
||||
|
||||
for item in items:
|
||||
self.session.db[self.name].append(item)
|
||||
post = self.compose_function(item, self.session.db, self.session.settings,
|
||||
relative_times=relative_times,
|
||||
show_screen_names=show_screen_names,
|
||||
safe=safe)
|
||||
self.buffer.list.insert_item(False, *post)
|
||||
|
||||
# Select the root post (first item after ancestors, or just the first)
|
||||
total = self.buffer.list.get_count()
|
||||
if total > 0:
|
||||
self.buffer.list.select_item(0)
|
||||
|
||||
if play_sound and self.sound and not self.session.settings["sound"]["session_mute"]:
|
||||
self.session.sound.play(self.sound)
|
||||
|
||||
return len(items)
|
||||
|
||||
|
||||
class LikesBuffer(BaseBuffer):
|
||||
"""User's liked posts."""
|
||||
|
||||
Reference in New Issue
Block a user