2022-08-10 01:10:25 +00:00
|
|
|
# Python imports
|
2022-11-29 04:34:13 +00:00
|
|
|
import os
|
|
|
|
import threading
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
import hashlib
|
2022-08-10 01:10:25 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
# Gtk imports
|
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
gi.require_version('GdkPixbuf', '2.0')
|
2022-11-29 04:34:13 +00:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import GLib
|
|
|
|
from gi.repository import Gio
|
|
|
|
from gi.repository import GdkPixbuf
|
2022-08-10 01:10:25 +00:00
|
|
|
|
|
|
|
# Application imports
|
2022-09-06 02:21:04 +00:00
|
|
|
from plugins.plugin_base import PluginBase
|
2022-08-10 01:10:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
# NOTE: Threads WILL NOT die with parent's destruction.
|
|
|
|
def threaded(fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-09-06 02:21:04 +00:00
|
|
|
class Plugin(PluginBase):
|
2022-08-10 01:10:25 +00:00
|
|
|
def __init__(self):
|
2022-09-06 02:21:04 +00:00
|
|
|
super().__init__()
|
|
|
|
|
2022-08-13 03:54:16 +00:00
|
|
|
self.path = os.path.dirname(os.path.realpath(__file__))
|
2022-09-06 02:21:04 +00:00
|
|
|
self._GLADE_FILE = f"{self.path}/re_thumbnailer.glade"
|
2022-08-13 03:54:16 +00:00
|
|
|
self.name = "VOD Thumbnailer" # NOTE: Need to remove after establishing private bidirectional 1-1 message bus
|
|
|
|
# where self.name should not be needed for message comms
|
2022-09-06 02:21:04 +00:00
|
|
|
|
2022-08-10 01:10:25 +00:00
|
|
|
self._thumbnailer_dialog = None
|
|
|
|
self._thumbnail_preview_img = None
|
2022-09-03 22:01:41 +00:00
|
|
|
self._scrub_step = None
|
2022-08-10 01:10:25 +00:00
|
|
|
self._file_name = None
|
|
|
|
self._file_location = None
|
|
|
|
self._file_hash = None
|
|
|
|
|
|
|
|
|
2022-09-06 02:21:04 +00:00
|
|
|
def run(self):
|
2023-02-21 01:18:45 +00:00
|
|
|
self._builder = Gtk.Builder()
|
2022-08-10 01:10:25 +00:00
|
|
|
self._builder.add_from_file(self._GLADE_FILE)
|
2023-02-21 01:18:45 +00:00
|
|
|
self._connect_builder_signals(self, self._builder)
|
2022-08-10 01:10:25 +00:00
|
|
|
|
|
|
|
self._thumbnailer_dialog = self._builder.get_object("thumbnailer_dialog")
|
2022-09-03 22:01:41 +00:00
|
|
|
self._scrub_step = self._builder.get_object("scrub_step")
|
2022-08-10 01:10:25 +00:00
|
|
|
self._file_name = self._builder.get_object("file_name")
|
|
|
|
self._file_location = self._builder.get_object("file_location")
|
|
|
|
self._thumbnail_preview_img = self._builder.get_object("thumbnail_preview_img")
|
|
|
|
self._file_hash = self._builder.get_object("file_hash")
|
|
|
|
|
2022-10-10 01:59:44 +00:00
|
|
|
def generate_reference_ui_element(self):
|
2022-10-21 03:23:14 +00:00
|
|
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(f"{self.path}/../../icons/video.png", 16, 16, True)
|
|
|
|
icon = Gtk.Image.new_from_pixbuf(pixbuf)
|
2022-10-27 00:47:54 +00:00
|
|
|
item = Gtk.ImageMenuItem(self.name)
|
|
|
|
|
2022-10-26 04:27:21 +00:00
|
|
|
item.set_image( icon )
|
|
|
|
item.connect("activate", self._show_thumbnailer_page)
|
|
|
|
item.set_always_show_image(True)
|
|
|
|
return item
|
2022-10-10 01:59:44 +00:00
|
|
|
|
2022-08-10 01:10:25 +00:00
|
|
|
|
|
|
|
@threaded
|
|
|
|
def _show_thumbnailer_page(self, widget=None, eve=None):
|
2022-10-10 01:59:44 +00:00
|
|
|
self._event_system.emit("get_current_state")
|
2022-08-10 01:10:25 +00:00
|
|
|
|
2022-09-29 22:22:33 +00:00
|
|
|
state = self._fm_state
|
2022-08-10 01:10:25 +00:00
|
|
|
self._event_message = None
|
|
|
|
|
|
|
|
GLib.idle_add(self._process_changes, (state))
|
|
|
|
|
|
|
|
def _process_changes(self, state):
|
2022-09-29 22:22:33 +00:00
|
|
|
self._fm_state = None
|
2022-08-10 01:10:25 +00:00
|
|
|
|
2022-12-07 05:36:10 +00:00
|
|
|
if len(state.uris) == 1:
|
|
|
|
if state.uris[0].lower().endswith(state.tab.fvideos):
|
2022-09-29 22:22:33 +00:00
|
|
|
self._fm_state = state
|
2022-08-10 01:10:25 +00:00
|
|
|
self._set_ui_data()
|
|
|
|
response = self._thumbnailer_dialog.run()
|
2022-09-03 22:01:41 +00:00
|
|
|
if response in [Gtk.ResponseType.CLOSE, Gtk.ResponseType.DELETE_EVENT]:
|
2022-08-10 01:10:25 +00:00
|
|
|
self._thumbnailer_dialog.hide()
|
|
|
|
|
|
|
|
|
|
|
|
def _regenerate_thumbnail(self, widget=None, eve=None):
|
2022-09-03 22:01:41 +00:00
|
|
|
scrub_percent = int(self._scrub_step.get_value())
|
|
|
|
file = self._file_name.get_text()
|
|
|
|
dir = self._file_location.get_text()
|
|
|
|
file_hash = self._file_hash.get_text()
|
2022-09-29 22:22:33 +00:00
|
|
|
hash_img_pth = f"{self._fm_state.tab.ABS_THUMBS_PTH}/{file_hash}.jpg"
|
2022-08-10 01:10:25 +00:00
|
|
|
|
|
|
|
try:
|
2023-02-04 22:32:00 +00:00
|
|
|
self._fm_state.tab.create_video_thumbnail(f"{dir}/{file}", f"{scrub_percent}%", True)
|
2022-09-03 22:01:41 +00:00
|
|
|
preview_pixbuf = GdkPixbuf.Pixbuf.new_from_file(hash_img_pth)
|
|
|
|
self._thumbnail_preview_img.set_from_pixbuf(preview_pixbuf)
|
|
|
|
|
2022-09-29 22:22:33 +00:00
|
|
|
img_pixbuf = self._fm_state.tab.create_scaled_image(hash_img_pth)
|
|
|
|
tree_pth = self._fm_state.icon_grid.get_selected_items()[0]
|
|
|
|
itr = self._fm_state.store.get_iter(tree_pth)
|
|
|
|
pixbuff = self._fm_state.store.get(itr, 0)[0]
|
|
|
|
self._fm_state.store.set(itr, 0, img_pixbuf)
|
2022-08-10 01:10:25 +00:00
|
|
|
except Exception as e:
|
2022-09-03 22:01:41 +00:00
|
|
|
print(repr(e))
|
2022-08-10 01:10:25 +00:00
|
|
|
print("Couldn't regenerate thumbnail!")
|
|
|
|
|
|
|
|
|
|
|
|
def _set_ui_data(self):
|
2022-12-07 05:36:10 +00:00
|
|
|
uri = self._fm_state.uris[0]
|
2022-09-29 22:22:33 +00:00
|
|
|
path = self._fm_state.tab.get_current_directory()
|
2022-09-03 22:01:41 +00:00
|
|
|
parts = uri.split("/")
|
2023-02-04 22:32:00 +00:00
|
|
|
file_hash = self._fm_state.tab.fast_hash(uri)
|
2022-09-29 22:22:33 +00:00
|
|
|
hash_img_pth = f"{self._fm_state.tab.ABS_THUMBS_PTH}/{file_hash}.jpg"
|
2022-09-03 22:01:41 +00:00
|
|
|
preview_pixbuf = GdkPixbuf.Pixbuf.new_from_file(hash_img_pth)
|
2022-08-10 01:10:25 +00:00
|
|
|
|
2022-09-03 22:01:41 +00:00
|
|
|
self._thumbnail_preview_img.set_from_pixbuf(preview_pixbuf)
|
2022-08-10 01:10:25 +00:00
|
|
|
self._file_name.set_text(parts[ len(parts) - 1 ])
|
|
|
|
self._file_location.set_text(path)
|
|
|
|
self._file_hash.set_text(file_hash)
|