Skip to content

Commit 12267c7

Browse files
authored
Merge pull request #39 from Lich-Corals/dev
Various fixes and changes
2 parents 5ca43c5 + bdaf1d4 commit 12267c7

7 files changed

+60
-54
lines changed

markdown/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ nohup nautilus & disown
1414
Automatic updates are only working in the home dictionary. If you've installed the script at the system-wide location, you may turn off automatic updates.
1515
<br/><br/>To <b>turn off automatic updates</b>, open the config file with a text editor and set the `automaticUpdates` variable to 'false'.
1616
To <b>manually trigger a self-update</b>, just open the .py file with a text editor and change the value of the `converterVersion` variable.
17+
To turn off the <b>update pop-up</b>, open the config file with a text editor and set the `showPatchNotes` variable to 'false'.
1718

1819
## 3.2 Shown menu items
1920
To turn off the <b>patch note button</b> in the context menu, open the config file with a text editor and set the `showPatchNoteButton` variable to 'false'.
@@ -23,7 +24,6 @@ Note: This option is not available in Nemo so far.
2324
<br/><br/>To turn off the '<b>convert to wallpaper</b>' function, open the config file with a text editor and set the `convertToWallpapers` variable to 'false'.
2425

2526
## 3.3 Other options
26-
To turn off the <b>patch note pop-up</b>, open the config file with a text editor and set the `showPatchNotes` variable to 'false'.
2727
<br/>To turn off the <b>Double script installation Warning</b>, open the config file with a text editor and set the `checkForDoubleInstallation` variable to 'false'.
2828
Note: This option may be a bit buggy in Nemo, I'll fix it in the future if it appears to be annoying to some users.
2929
<br/>To turn off the __addition of timestamps__ to filenames, open the config file with a text editor and set the `timeInNames` variable to ‘false’.
@@ -34,4 +34,4 @@ Note: This option may be a bit buggy in Nemo, I'll fix it in the future if it ap
3434
- [Errorrs and warnings](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md)
3535
- [Install dependencies](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-dependencies.md)
3636
- [Installation for Nautilus](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nautilus.md)
37-
- [Installation for Nemo](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nemo.md)
37+
- [Installation for Nemo](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nemo.md)

markdown/errors-and-warnings.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Errors and warnings
22
This section will hopefully be helpful, if you experience problems with the plugin.
33
## WARNING(Nautilus-file-converter)(XXX):
4-
### (000): "pyheif" not found
4+
### (000): "pillow_heif" not found
55
<b>Causes:</b><br/>
6-
This warning is caused, because the script is not able to find your pyheif installation.
6+
This warning is caused, because the script is not able to find your pillow_heif installation.
77
<br/><br/><b>Possible Effects:</b><br/>
88
Without pyheif, the converter won't be able to convert from heif file format.
99
<br/><br/><b>How to solve?</b><br/>
10-
To solve this warning, you need to install pyheif using pip.
10+
To solve this warning, you need to install pillow_heif using pip.
1111
<br/>View the [Optional dependencies](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-dependencies.md#optional-dependencies) section to get installation instructions.
1212

1313
### (001): "jxlpy" not found

markdown/install-dependencies.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ pacman -S python-pip
2020
pip install Pillow
2121
```
2222

23+
[python-magic](https://pypi.org/project/python-magic/) will be used to detect the mimetypes of files:
24+
```bash
25+
pip install python-magic
26+
```
27+
2328
[ffmpeg](https://ffmpeg.org/download.html#build-linux) is needed to convert audio and video.
2429

2530
```bash
@@ -34,16 +39,13 @@ sudo pacman -S ffmpeg
3439
```
3540

3641
## Optional dependencies
37-
### pyheif (HEIC, AVIF)
38-
[pyheif](https://pypi.org/project/pyheif/) is needed if you want to convert from **heif** or **avif** format.
42+
### pillow_heif (from HEIF, AVIF)
43+
[pillow_heif](https://pypi.org/project/pillow-heif/) is needed if you want to convert from **heif** or **avif** format.
3944
<br/> Install it using this command:
4045
```bash
41-
pip install pyheif
42-
```
43-
You may need to install some dependencies before installing pyheif. Otherwise you could get an error installing it.
44-
```bash
45-
yum install libffi libheif-devel libde265-devel
46+
pip install pillow-heif
4647
```
48+
4749
### pillow-avif-plugin (to AVIF)
4850
In addition, to convert *to* **avif** format you will need this [plugin for Pillow](https://pypi.org/project/pillow-avif-plugin/).
4951
```bash

markdown/install-nautilus.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ sudo pacman -Sy python-nautilus
2525

2626
cd ./linux-file-converter-addon
2727
```
28-
- For a system-wide installation move the file to '/usr/share/nautilus-python/extensions/' using this command in the dictionary with the file:
29-
```bash
30-
sudo mv nautilus-fileconverter.py /usr/share/nautilus-python/extensions/nautilus-fileconverter.py
31-
```
32-
- For a user specific installation move the file to '~/.local/share/nautilus-python/extensions/' using this command in the dictionary with the file:
28+
- Move the script to the right location:
29+
<br><b>Important: Only use <i>one</i> of the following commands, otherwise you will get the menu-option twice!</b>
30+
- For a user specific installation move the file to '~/.local/share/nautilus-python/extensions/' using this command in the dictionary with the file:
3331
```bash
3432
mv nautilus-fileconverter.py ~/.local/share/nautilus-python/extensions/nautilus-fileconverter.py
3533
```
34+
- For a system-wide installation move the file to '/usr/share/nautilus-python/extensions/' using this command in the dictionary with the file:
35+
```bash
36+
sudo mv nautilus-fileconverter.py /usr/share/nautilus-python/extensions/nautilus-fileconverter.py
37+
```
3638
- Now you only have to restart Nautilus using the following commands:
3739
```bash
3840
#Quit Nautilus
@@ -48,4 +50,4 @@ sudo pacman -Sy python-nautilus
4850
- [Errorrs and warnings](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md)
4951
- [Install dependencies](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-dependencies.md)
5052
- __[Installation for Nautilus](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nautilus.md)__
51-
- [Installation for Nemo](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nemo.md)
53+
- [Installation for Nemo](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nemo.md)

markdown/update-notification.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Your file converter just updated itself!
2+
Visit [the release page](https://github.com/Lich-Corals/linux-file-converter-addon/releases) to see what's changed.
3+
<br>If you want to see every commit, you can also look at the [commit history](https://github.com/Lich-Corals/linux-file-converter-addon/commits/main).
4+
5+
If you don't want to see this popup, you can disable it; look at [this section](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/configuration.md#31-automatic-updates) to do so.

nautilus-fileconverter.nemo_action

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Name=Convert to...
33
Comment=Convert file using nautilus-fileconverter
44
Exec=<nautilus-fileconverter.py %F>
55
Selection=NotNone
6-
Mimetypes=image/jpeg;image/png;image/bmp;application/postscript;image/gif;image/x-icon;image/x-pcx;image/x-portable-pixmap;image/tiff;image/x-xbm;image/x-xbitmap;video/fli;image/vnd.fpx;image/vnd.net-fpx;windows/metafile;image/x-xpixmap;image/webp;image/avif;image/heif;image/jxl;audio/mpeg;audio/mpeg3;video/x-mpeg;audio/x-mpeg-3;audio/x-wav;audio/wav;audio/wave;audio/x-pn-wave;audio/vnd.wave;audio/x-mpegurl;audio/mp4;audio/mp4a-latm;audio/mpeg4-generic;audio/x-matroska;audio/aac;audio/aacp;audio/3gpp;audio/3gpp2;audio/ogg;audio/opus;audio/flac;audio/x-vorbis+ogg;video/mp4;video/webm;video/x-matroska;video/avi;video/msvideo;video/x-msvideo;video/quicktime;
6+
Mimetypes=image/jpeg;image/png;image/bmp;application/postscript;image/gif;image/x-icon;image/x-pcx;image/x-portable-pixmap;image/tiff;image/x-xbm;image/x-xbitmap;video/fli;image/vnd.fpx;image/vnd.net-fpx;windows/metafile;image/x-xpixmap;image/webp;image/avif;image/heif;image/heic;image/jxl;audio/mpeg;audio/mpeg3;video/x-mpeg;audio/x-mpeg-3;audio/x-wav;audio/wav;audio/wave;audio/x-pn-wave;audio/vnd.wave;audio/x-mpegurl;audio/mp4;audio/mp4a-latm;audio/mpeg4-generic;audio/x-matroska;audio/aac;audio/aacp;audio/3gpp;audio/3gpp2;audio/ogg;audio/opus;audio/flac;audio/x-vorbis+ogg;video/mp4;video/webm;video/x-matroska;video/avi;video/msvideo;video/x-msvideo;video/quicktime;

nautilus-fileconverter.py

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/python3 -OOt
22

33
# --- Version number ---
4-
converterVersion = "001002008" # Change the number if you want to trigger an update.
4+
converterVersion = "001002009" # Change the number if you want to trigger an update.
55

66
# --- Imports ---
77
import gi
@@ -23,7 +23,7 @@
2323
from urllib.parse import urlparse, unquote
2424
from pathlib import Path
2525
from datetime import datetime
26-
import mimetypes
26+
import magic
2727
import pathlib
2828
import os, shlex
2929
import urllib.request
@@ -32,35 +32,39 @@
3232
import ast
3333
import re
3434

35+
# --- Create magic object ---
36+
mime = magic.Magic(mime=True)
37+
3538
# --- Get the path to the script and if it's writeable ---
3639
currentPath = str(pathlib.Path(__file__).parent.resolve()) # used for config file and self-update!
3740
scriptUpdateable = os.access(f"{currentPath}/{os.path.basename(__file__)}", os.W_OK)
3841

3942
# --- Check if dependencies are installed and imported ---
40-
pyheifInstalled = False
43+
pillow_heifInstalled = False
4144
jxlpyInstalled = False
4245
pillow_avif_pluginInstalled = False
4346

4447
try:
45-
import pyheif
46-
pyheifInstalled = True
48+
from pillow_heif import register_heif_opener
49+
register_heif_opener()
50+
pillow_heifInstalled = True
4751
except ImportError:
48-
pyheifInstalled = False
49-
print(f"WARNING(Nautilus-file-converter)(000): \"pyheif\" not found, if you want to convert from heif format. View https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md for more information." )
52+
pillow_heifInstalled = False
53+
print(f"WARNING(Nautilus-file-converter)(000): \"pillow_heif\" not found. View https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md for more information." )
5054

5155
try:
5256
import jxlpy
5357
from jxlpy import JXLImagePlugin
5458
jxlpyInstalled = True
5559
except ImportError:
5660
jxlpyInstalled = False
57-
print(f"WARNING(Nautilus-file-converter)(001): \"jxlpy\" not found, if you want to convert from- or to jxl format. View https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md for more information.")
61+
print(f"WARNING(Nautilus-file-converter)(001): \"jxlpy\" not found. View https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md for more information.")
5862

5963
try:
6064
import pillow_avif
6165
pillow_avif_pluginInstalled = True
6266
except ImportError:
63-
print(f"WARNING(Nautilus-file-converter)(002) \"pillow-avif-plugin\" not found, if you want to convert to avif format. View https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md for more information.")
67+
print(f"WARNING(Nautilus-file-converter)(002) \"pillow-avif-plugin\" not found. View https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md for more information.")
6468

6569
if not scriptUpdateable:
6670
print(f"WARNING(Nautilus-file-converter)(003): No permission to self-update; script at \"{currentPath}/{os.path.basename(__file__)}\" is not writeable. View https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md for more information.")
@@ -110,7 +114,7 @@
110114
print("Updating...")
111115
fileUpdatePath = f"{currentPath}/{os.path.basename(__file__)}"
112116
if _config["showPatchNotes"]:
113-
os.system(f"nohup xdg-open \"https://github.com/Lich-Corals/linux-file-converter-addon/releases\" &")
117+
os.system(f"nohup xdg-open \"https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/update-notification.md\" &")
114118
with open(fileUpdatePath, 'w') as file:
115119
file.write(onlineFile)
116120

@@ -120,7 +124,9 @@
120124

121125
# --- Disable debug printing ---
122126
# comment it out (using '#' in front of the line) if you wish debug printing
123-
#print = lambda *wish, **verbosity: None
127+
print = lambda *wish, **verbosity: None
128+
129+
print(f"pyheif: {pillow_heifInstalled}\njxlpy: {jxlpyInstalled}\npillow_avif: {pillow_avif_pluginInstalled}")
124130

125131
# --- Create file format tuples and write format dict-lists? ---
126132
READ_FORMATS_IMAGE = ('image/jpeg',
@@ -143,7 +149,8 @@
143149
'image/webp')
144150

145151
pyheifReadFormats = ('image/avif',
146-
'image/heif')
152+
'image/heif',
153+
'image/heic')
147154

148155
jxlpyReadFormats = ('image/jxl')
149156

@@ -236,7 +243,7 @@
236243
{'name': 'MP3'},
237244
{'name': 'WAV'}]
238245

239-
if pyheifInstalled:
246+
if pillow_heifInstalled:
240247
READ_FORMATS_IMAGE = READ_FORMATS_IMAGE + pyheifReadFormats
241248

242249
if jxlpyInstalled:
@@ -273,25 +280,14 @@ def convert_image(menu, format, files):
273280
from_file_path = file
274281
print(__removeTimestamp(from_file_path.stem) + from_file_path.stem)
275282
to_file_path = from_file_path.with_name(f"{__removeTimestamp(from_file_path.stem)}{_addToName}.{format['extension'].lower()}")
276-
try:
277-
image = Image.open(from_file_path)
278-
if (format['name']) == 'JPEG':
279-
image = image.convert('RGB')
280-
if 'square' in format:
281-
image = image.resize((int(format['square']), int(format['square'])))
282-
if 'w' in format:
283-
image = image.resize((int(format['w']), int(format['h'])))
284-
image.save(to_file_path, format=(format['extension']))
285-
except UnidentifiedImageError:
286-
try:
287-
heif_file = pyheif.read(from_file_path)
288-
heif_image = Image.frombytes(heif_file.mode, heif_file.size, heif_file.data, "raw", heif_file.mode, heif_file.stride,)
289-
if (format['extension']) == 'JPEG':
290-
heif_image = heif_image.convert("RGB")
291-
heif_image.save(to_file_path, format['extension'])
292-
except UnidentifiedImageError:
293-
pass
294-
pass
283+
image = Image.open(from_file_path)
284+
if (format['name']) == 'JPEG':
285+
image = image.convert('RGB')
286+
if 'square' in format:
287+
image = image.resize((int(format['square']), int(format['square'])))
288+
if 'w' in format:
289+
image = image.resize((int(format['w']), int(format['h'])))
290+
image.save(to_file_path, format=(format['extension']))
295291

296292

297293
# --- Function to convert using FFMPEG (video and audio) ---
@@ -323,15 +319,16 @@ def __init__(self):
323319
_allAudios = True
324320
_allVideos = True
325321
for _arg in _nemoArgs:
326-
if not mimetypes.guess_type(str(_arg))[0] in READ_FORMATS_IMAGE:
322+
if not mime.from_file(_arg) in READ_FORMATS_IMAGE:
327323
_allImages = False
328-
if not mimetypes.guess_type(str(_arg))[0] in READ_FORMATS_AUDIO:
324+
if not mime.from_file(_arg) in READ_FORMATS_AUDIO:
329325
_allAudios = False
330-
if not mimetypes.guess_type(str(_arg))[0] in READ_FORMATS_VIDEO:
326+
if not mime.from_file(_arg) in READ_FORMATS_VIDEO:
331327
_allVideos = False
332328

333329
if _allImages:
334330
for writeFormat in WRITE_FORMATS_IMAGE:
331+
print(writeFormat)
335332
extensions.append([writeFormat['name'], str(writeFormat), 0])
336333
if _config["convertToSquares"]:
337334
for writeFormat in WRITE_FORMATS_SQUARE:

0 commit comments

Comments
 (0)