Skip to content

Commit

Permalink
Merge pull request #39 from Lich-Corals/dev
Browse files Browse the repository at this point in the history
Various fixes and changes
  • Loading branch information
Lich-Corals authored Apr 6, 2024
2 parents 5ca43c5 + bdaf1d4 commit 12267c7
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 54 deletions.
4 changes: 2 additions & 2 deletions markdown/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ nohup nautilus & disown
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.
<br/><br/>To <b>turn off automatic updates</b>, open the config file with a text editor and set the `automaticUpdates` variable to 'false'.
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.
To turn off the <b>update pop-up</b>, open the config file with a text editor and set the `showPatchNotes` variable to 'false'.

## 3.2 Shown menu items
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'.
Expand All @@ -23,7 +24,6 @@ Note: This option is not available in Nemo so far.
<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'.

## 3.3 Other options
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'.
<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'.
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.
<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’.
Expand All @@ -34,4 +34,4 @@ Note: This option may be a bit buggy in Nemo, I'll fix it in the future if it ap
- [Errorrs and warnings](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md)
- [Install dependencies](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-dependencies.md)
- [Installation for Nautilus](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nautilus.md)
- [Installation for Nemo](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nemo.md)
- [Installation for Nemo](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nemo.md)
6 changes: 3 additions & 3 deletions markdown/errors-and-warnings.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Errors and warnings
This section will hopefully be helpful, if you experience problems with the plugin.
## WARNING(Nautilus-file-converter)(XXX):
### (000): "pyheif" not found
### (000): "pillow_heif" not found
<b>Causes:</b><br/>
This warning is caused, because the script is not able to find your pyheif installation.
This warning is caused, because the script is not able to find your pillow_heif installation.
<br/><br/><b>Possible Effects:</b><br/>
Without pyheif, the converter won't be able to convert from heif file format.
<br/><br/><b>How to solve?</b><br/>
To solve this warning, you need to install pyheif using pip.
To solve this warning, you need to install pillow_heif using pip.
<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.

### (001): "jxlpy" not found
Expand Down
16 changes: 9 additions & 7 deletions markdown/install-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ pacman -S python-pip
pip install Pillow
```

[python-magic](https://pypi.org/project/python-magic/) will be used to detect the mimetypes of files:
```bash
pip install python-magic
```

[ffmpeg](https://ffmpeg.org/download.html#build-linux) is needed to convert audio and video.

```bash
Expand All @@ -34,16 +39,13 @@ sudo pacman -S ffmpeg
```

## Optional dependencies
### pyheif (HEIC, AVIF)
[pyheif](https://pypi.org/project/pyheif/) is needed if you want to convert from **heif** or **avif** format.
### pillow_heif (from HEIF, AVIF)
[pillow_heif](https://pypi.org/project/pillow-heif/) is needed if you want to convert from **heif** or **avif** format.
<br/> Install it using this command:
```bash
pip install pyheif
```
You may need to install some dependencies before installing pyheif. Otherwise you could get an error installing it.
```bash
yum install libffi libheif-devel libde265-devel
pip install pillow-heif
```

### pillow-avif-plugin (to AVIF)
In addition, to convert *to* **avif** format you will need this [plugin for Pillow](https://pypi.org/project/pillow-avif-plugin/).
```bash
Expand Down
14 changes: 8 additions & 6 deletions markdown/install-nautilus.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ sudo pacman -Sy python-nautilus

cd ./linux-file-converter-addon
```
- For a system-wide installation move the file to '/usr/share/nautilus-python/extensions/' using this command in the dictionary with the file:
```bash
sudo mv nautilus-fileconverter.py /usr/share/nautilus-python/extensions/nautilus-fileconverter.py
```
- For a user specific installation move the file to '~/.local/share/nautilus-python/extensions/' using this command in the dictionary with the file:
- Move the script to the right location:
<br><b>Important: Only use <i>one</i> of the following commands, otherwise you will get the menu-option twice!</b>
- For a user specific installation move the file to '~/.local/share/nautilus-python/extensions/' using this command in the dictionary with the file:
```bash
mv nautilus-fileconverter.py ~/.local/share/nautilus-python/extensions/nautilus-fileconverter.py
```
- For a system-wide installation move the file to '/usr/share/nautilus-python/extensions/' using this command in the dictionary with the file:
```bash
sudo mv nautilus-fileconverter.py /usr/share/nautilus-python/extensions/nautilus-fileconverter.py
```
- Now you only have to restart Nautilus using the following commands:
```bash
#Quit Nautilus
Expand All @@ -48,4 +50,4 @@ sudo pacman -Sy python-nautilus
- [Errorrs and warnings](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md)
- [Install dependencies](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-dependencies.md)
- __[Installation for Nautilus](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nautilus.md)__
- [Installation for Nemo](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nemo.md)
- [Installation for Nemo](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/install-nemo.md)
5 changes: 5 additions & 0 deletions markdown/update-notification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Your file converter just updated itself!
Visit [the release page](https://github.com/Lich-Corals/linux-file-converter-addon/releases) to see what's changed.
<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).

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.
2 changes: 1 addition & 1 deletion nautilus-fileconverter.nemo_action
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Name=Convert to...
Comment=Convert file using nautilus-fileconverter
Exec=<nautilus-fileconverter.py %F>
Selection=NotNone
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;
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;
67 changes: 32 additions & 35 deletions nautilus-fileconverter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/python3 -OOt

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

# --- Imports ---
import gi
Expand All @@ -23,7 +23,7 @@
from urllib.parse import urlparse, unquote
from pathlib import Path
from datetime import datetime
import mimetypes
import magic
import pathlib
import os, shlex
import urllib.request
Expand All @@ -32,35 +32,39 @@
import ast
import re

# --- Create magic object ---
mime = magic.Magic(mime=True)

# --- Get the path to the script and if it's writeable ---
currentPath = str(pathlib.Path(__file__).parent.resolve()) # used for config file and self-update!
scriptUpdateable = os.access(f"{currentPath}/{os.path.basename(__file__)}", os.W_OK)

# --- Check if dependencies are installed and imported ---
pyheifInstalled = False
pillow_heifInstalled = False
jxlpyInstalled = False
pillow_avif_pluginInstalled = False

try:
import pyheif
pyheifInstalled = True
from pillow_heif import register_heif_opener
register_heif_opener()
pillow_heifInstalled = True
except ImportError:
pyheifInstalled = False
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." )
pillow_heifInstalled = False
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." )

try:
import jxlpy
from jxlpy import JXLImagePlugin
jxlpyInstalled = True
except ImportError:
jxlpyInstalled = False
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.")
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.")

try:
import pillow_avif
pillow_avif_pluginInstalled = True
except ImportError:
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.")
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.")

if not scriptUpdateable:
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.")
Expand Down Expand Up @@ -110,7 +114,7 @@
print("Updating...")
fileUpdatePath = f"{currentPath}/{os.path.basename(__file__)}"
if _config["showPatchNotes"]:
os.system(f"nohup xdg-open \"https://github.com/Lich-Corals/linux-file-converter-addon/releases\" &")
os.system(f"nohup xdg-open \"https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/update-notification.md\" &")
with open(fileUpdatePath, 'w') as file:
file.write(onlineFile)

Expand All @@ -120,7 +124,9 @@

# --- Disable debug printing ---
# comment it out (using '#' in front of the line) if you wish debug printing
#print = lambda *wish, **verbosity: None
print = lambda *wish, **verbosity: None

print(f"pyheif: {pillow_heifInstalled}\njxlpy: {jxlpyInstalled}\npillow_avif: {pillow_avif_pluginInstalled}")

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

pyheifReadFormats = ('image/avif',
'image/heif')
'image/heif',
'image/heic')

jxlpyReadFormats = ('image/jxl')

Expand Down Expand Up @@ -236,7 +243,7 @@
{'name': 'MP3'},
{'name': 'WAV'}]

if pyheifInstalled:
if pillow_heifInstalled:
READ_FORMATS_IMAGE = READ_FORMATS_IMAGE + pyheifReadFormats

if jxlpyInstalled:
Expand Down Expand Up @@ -273,25 +280,14 @@ def convert_image(menu, format, files):
from_file_path = file
print(__removeTimestamp(from_file_path.stem) + from_file_path.stem)
to_file_path = from_file_path.with_name(f"{__removeTimestamp(from_file_path.stem)}{_addToName}.{format['extension'].lower()}")
try:
image = Image.open(from_file_path)
if (format['name']) == 'JPEG':
image = image.convert('RGB')
if 'square' in format:
image = image.resize((int(format['square']), int(format['square'])))
if 'w' in format:
image = image.resize((int(format['w']), int(format['h'])))
image.save(to_file_path, format=(format['extension']))
except UnidentifiedImageError:
try:
heif_file = pyheif.read(from_file_path)
heif_image = Image.frombytes(heif_file.mode, heif_file.size, heif_file.data, "raw", heif_file.mode, heif_file.stride,)
if (format['extension']) == 'JPEG':
heif_image = heif_image.convert("RGB")
heif_image.save(to_file_path, format['extension'])
except UnidentifiedImageError:
pass
pass
image = Image.open(from_file_path)
if (format['name']) == 'JPEG':
image = image.convert('RGB')
if 'square' in format:
image = image.resize((int(format['square']), int(format['square'])))
if 'w' in format:
image = image.resize((int(format['w']), int(format['h'])))
image.save(to_file_path, format=(format['extension']))


# --- Function to convert using FFMPEG (video and audio) ---
Expand Down Expand Up @@ -323,15 +319,16 @@ def __init__(self):
_allAudios = True
_allVideos = True
for _arg in _nemoArgs:
if not mimetypes.guess_type(str(_arg))[0] in READ_FORMATS_IMAGE:
if not mime.from_file(_arg) in READ_FORMATS_IMAGE:
_allImages = False
if not mimetypes.guess_type(str(_arg))[0] in READ_FORMATS_AUDIO:
if not mime.from_file(_arg) in READ_FORMATS_AUDIO:
_allAudios = False
if not mimetypes.guess_type(str(_arg))[0] in READ_FORMATS_VIDEO:
if not mime.from_file(_arg) in READ_FORMATS_VIDEO:
_allVideos = False

if _allImages:
for writeFormat in WRITE_FORMATS_IMAGE:
print(writeFormat)
extensions.append([writeFormat['name'], str(writeFormat), 0])
if _config["convertToSquares"]:
for writeFormat in WRITE_FORMATS_SQUARE:
Expand Down

0 comments on commit 12267c7

Please sign in to comment.