| 16 | |
| 17 | |
| 18 | class TranscodeAction(GObject.GObject, Nautilus.MenuProvider): |
| 19 | def _launch_transcode(self, paths): |
| 20 | wrapper = shutil.which("omarchy-launch-floating-terminal-with-presentation") |
| 21 | binary = shutil.which("omarchy-transcode") |
| 22 | if not wrapper or not binary: |
| 23 | return |
| 24 | |
| 25 | if len(paths) == 1: |
| 26 | cmd = shlex.join([binary, paths[0]]) |
| 27 | else: |
| 28 | cmd = "; ".join( |
| 29 | f"echo {shlex.quote(f'Transcoding {path}')} && " |
| 30 | f"{shlex.join([binary, path])} || true" |
| 31 | for path in paths |
| 32 | ) |
| 33 | |
| 34 | Gio.Subprocess.new([wrapper, cmd], Gio.SubprocessFlags.NONE) |
| 35 | |
| 36 | def _is_supported(self, file): |
| 37 | mime = file.get_mime_type() or "" |
| 38 | if mime.startswith(SUPPORTED_MIME_PREFIXES): |
| 39 | return True |
| 40 | |
| 41 | location = file.get_location() |
| 42 | if not location: |
| 43 | return False |
| 44 | path = location.get_path() or "" |
| 45 | lower = path.lower() |
| 46 | return any(lower.endswith(ext) for ext in SUPPORTED_EXTENSIONS) |
| 47 | |
| 48 | def _selected_paths(self, files): |
| 49 | paths = [] |
| 50 | seen = set() |
| 51 | |
| 52 | for file in files: |
| 53 | if file.is_directory(): |
| 54 | continue |
| 55 | if not self._is_supported(file): |
| 56 | continue |
| 57 | location = file.get_location() |
| 58 | if not location: |
| 59 | continue |
| 60 | path = location.get_path() |
| 61 | if path and path not in seen: |
| 62 | seen.add(path) |
| 63 | paths.append(path) |
| 64 | return paths |
| 65 | |
| 66 | def _make_item(self, paths): |
| 67 | label = "Transcode" if len(paths) == 1 else f"Transcode {len(paths)} items" |
| 68 | item = Nautilus.MenuItem( |
| 69 | name="OmarchyTranscodeNautilus::transcode", |
| 70 | label=label, |
| 71 | icon="media-playback-start", |
| 72 | ) |
| 73 | item.connect("activate", self._on_activate, paths) |
| 74 | return item |
| 75 |
nothing calls this directly
no outgoing calls
no test coverage detected