Commit 6e5d4677 authored by Colomban Wendling's avatar Colomban Wendling

Initial import

parents
#!/usr/bin/make -f
# License: Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
prefix ?= $(HOME)/.local
bindir ?= $(prefix)/bin
actionsdir ?= $(prefix)/share/file-manager/actions
MKDIR_P ?= mkdir -p
INSTALL ?= install
RM ?= rm -f
SED ?= sed
PROG = nautilus-mp3-converter
ACTION = $(PROG).desktop
all: $(PROG) $(ACTION)
install: all
test -d $(bindir) || $(MKDIR_P) $(bindir)
test -d $(actionsdir) || $(MKDIR_P) $(actionsdir)
$(INSTALL) -m 755 -t $(bindir) $(PROG)
$(INSTALL) -m 644 -t $(actionsdir) $(ACTION)
$(SED) -i $(actionsdir)/$(ACTION) -e 's%^Exec=%\0$(bindir)/%'
uninstall:
$(RM) $(bindir)/$(PROG)
$(RM) $(actionsdir)/$(ACTION)
#!/bin/bash
#
# nautilus-mp3-converter - Nautilus Action for converting audio files
#
# Copyright 2017 Colomban Wendling <ban@herbesfolles.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
FFMPEG=avconv
QUALITY=5
TITLE="Convertir en MP3"
progress() {
local count=$1
zenity --progress \
--title="$TITLE" \
--text="Conversion en MP3..." \
--percentage=0 \
--auto-close \
--auto-kill \
$([ "$count" = 1 ] && echo --pulsate)
}
format() {
echo "<b>$1</b>\n\n$2"
}
error() {
zenity --error \
--title="$TITLE" \
--text="$(format "$1" "$2")"
}
process_file() {
local f="$1"
local dest="${f%.*}.mp3"
local replace_option=-n
# check if the file exists, and whether to replace it
if [ -e "$dest" ]; then
if zenity --question \
--title="Écraser – $TITLE" \
--text="$(format "Voulez-vous écraser le fichier « <i>${dest##*/}</i> » ?" \
"Le fichier « <i>${dest##*/}</i> » existe déjà, voulez-vous le remplacer ?")" \
--ok-label="Écraser"
then
replace_option=-y
else
return 0
fi
fi
# same file, abort
if [ "$(realpath "$f")" = "$(realpath "$dest")" ]; then
error "Le fichier de destination est le même que le fichier source" \
"Les chemins « <i>$f</i> » et « <i>$dest</i> » identifient le même fichier.
Essayez-vous de convertir un fichier qui est déjà au format MP3 ?"
return 1
fi
$FFMPEG "$replace_option" -v error -i "$f" -codec:a libmp3lame -q:a $QUALITY "$dest"
}
count=$#
n=0
for f in "$@"; do
echo "# Conversion de « ${f##*/} » ($((n+1)) de $count)…"
process_file "$f" || {
error "Échec de la conversion" \
"La conversion du fichier « <i>${f##*/}</i> » a échouée"
break
}
((n++))
echo $((n * 100 / count))
done | progress "$count"
[Desktop Entry]
Type=Action
Icon=audio-x-generic
Name=Convert to MP3
Name[fr]=Convertir en MP3
ToolbarLabel=Convert to MP3
ToolbarLabel[fr]=Convertir en MP3
Tooltip=Converts various audio formats to MP3
Tooltip[fr]=Convertis divers formats audio en MP3
Profiles=profile-zero;
[X-Action-Profile profile-zero]
Name=Default profile
Name[fr]=Profil par défaut
Exec=nautilus-mp3-converter %F
Basenames=*;!*.mp3;
MimeTypes=audio/*;
Schemes=file;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment