-
Notifications
You must be signed in to change notification settings - Fork 0
/
nautilus-open-in-mediainfo-gui.py
45 lines (35 loc) · 1.47 KB
/
nautilus-open-in-mediainfo-gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from gi.repository import Nautilus, GObject
import subprocess
import gi
gi_version_major = 3 if 30 <= gi.version_info[1] < 40 else 4
gi.require_versions({
'Nautilus': '3.0' if gi_version_major == 3 else '4.0',
'Gdk': '3.0' if gi_version_major == 3 else '4.0',
'Gtk': '3.0' if gi_version_major == 3 else '4.0'
})
class MediaInfoExtension(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
GObject.GObject.__init__(self)
def get_file_items(self, *args, **kwargs):
files = args[0] if gi_version_major == 4 else args[1]
item_label = 'Open in MediaInfo'
item_mediainfo = Nautilus.MenuItem(
name='MediaInfoExtension::OpenWithMediaInfo',
label=item_label,
tip='View media information with MediaInfo')
item_mediainfo.connect('activate', self.open_with_mediainfo, files)
return item_mediainfo,
def open_with_mediainfo(self, menu, files):
if not self.check_mediainfo_installed():
return
file_paths = [file.get_location().get_path() for file in files]
for file_path in file_paths:
subprocess.Popen(['mediainfo-gui', file_path],
start_new_session=True)
print(f"INFO: Opened {file_path.split('/')[-1]}")
def check_mediainfo_installed(self):
try:
subprocess.check_output(['mediainfo', '--version'])
return True
except FileNotFoundError:
return False