Compare commits
52 Commits
Author | SHA1 | Date | |
---|---|---|---|
1650372857
|
|||
be219b7522 | |||
e2bc45d4c6
|
|||
6701d0b642
|
|||
5a3718d2bb | |||
d39ba38574 | |||
1fe2898fe3 | |||
dc63e8d6b7
|
|||
ccb4b5d39b
|
|||
d4b932266b | |||
bca0d76a9c | |||
a98e92ab51 | |||
75eab0cc26 | |||
a2ed4f2c3b | |||
e09b5e986e | |||
|
c72e03e902 | ||
|
d62a260b71 | ||
|
044608be0d | ||
|
4d6c0ec88b | ||
|
bff082e078 | ||
|
ce8f0c5e3a | ||
|
239413dd5a | ||
|
01d58331d0 | ||
|
7d23f80b2a | ||
|
6414efac19 | ||
|
b4e4282623 | ||
|
13da0372ff | ||
|
3a624f7657 | ||
|
34b8c740f5 | ||
|
0badeb5752 | ||
|
e2b881823b | ||
|
13ae47a82c | ||
|
c1adc5c95c | ||
|
33eed57195 | ||
|
0c525af8fe | ||
|
dc63c13d6b | ||
|
db7f7a0f66 | ||
|
308e320427 | ||
|
fc0b6174d0 | ||
|
8fb1538f8f | ||
|
777ebf4514 | ||
|
de24c41e67 | ||
|
8227ff3f66 | ||
|
db51a6a46c | ||
|
8a9d0eafde | ||
|
e562ead9ca | ||
|
a77ab44a4f | ||
|
0c08359082 | ||
|
f8a85ab1a6 | ||
|
325918d7da | ||
|
a71b3bed94 | ||
|
ad2c0ba9fc |
34
Changelog.md
Normal file
34
Changelog.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Changelog
|
||||
|
||||
## v2.1
|
||||
|
||||
* Migrate from egrep to grep (#31)
|
||||
* Add rmTrailingZero func (#30)
|
||||
|
||||
## v2.0
|
||||
|
||||
* Progress indicator (#14)
|
||||
* Undo with Overides (#15)
|
||||
* Array fix (#21)
|
||||
* Convert counter to season function (#22)
|
||||
* Additional string operators (#23)
|
||||
|
||||
## v1.1
|
||||
|
||||
* Add bugfix
|
||||
|
||||
## v1.0
|
||||
|
||||
* Default configuration changeable for each user (#1)
|
||||
* Undo function (#3)
|
||||
* Advanced pattern recognition (#5)
|
||||
* Counter and serial case detection
|
||||
* Help menu (#8)
|
||||
* Version info (#20)
|
||||
* Init user config if not there (#13)
|
||||
|
||||
## before
|
||||
|
||||
* Handle different formats (#4)
|
||||
* Basic functions Functioning
|
||||
* Replaces the old shorter
|
@@ -1,6 +1,6 @@
|
||||
Package: shorter
|
||||
Source: shorter
|
||||
Version: 0.4
|
||||
Version: 2.1
|
||||
Architecture: all
|
||||
Maintainer: markus <markus@obermui.de>, 6543 <6543@obermui.de>
|
||||
Installed-Size: <SIZE>
|
||||
|
@@ -1,3 +1,9 @@
|
||||
# shorter
|
||||
|
||||
Bennent Serien in einheitliches Format um
|
||||
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||
[](https://code.obermui.de/markus/shorter/releases)
|
||||
|
||||
rename series to unified format
|
||||
|
||||
how to install:
|
||||
- archlinux [aur](https://aur.archlinux.org/packages/shorter)
|
BIN
doc/found.jpg
Normal file
BIN
doc/found.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
@@ -21,3 +21,7 @@ date="$2"
|
||||
[ -f "DEBIAN/control" ] && {
|
||||
sed -i "/Version:\ /c\Version:\ $version_sed" "DEBIAN/control"
|
||||
}
|
||||
|
||||
[ -f README.md ] && {
|
||||
sed -i "s/\[\!\[Release\].*/\[\!\[Release\]\(https:\/\/img\.shields\.io\/badge\/Release-$version_sed-brightgreen\)\]\(https:\/\/code\.obermui\.de\/markus\/shorter\/releases\)/g" README.md
|
||||
}
|
||||
|
346
src/shorter
346
src/shorter
@@ -1,12 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
#@date 2019-03-09
|
||||
#@version 0.4
|
||||
#@date 2022-09-14
|
||||
#@version 2.1
|
||||
#@author markus@obermui.de, 6543@obermui.de
|
||||
|
||||
arg1="$1"
|
||||
[ "$arg1" == "--help" ] &&
|
||||
{
|
||||
[ "$arg1" == "--help" ] && {
|
||||
#help menue ...
|
||||
echo 'Aufruf: shorter'
|
||||
echo ' oder: shorter -u'
|
||||
@@ -43,7 +42,7 @@ arg1="$1"
|
||||
exit 0
|
||||
}
|
||||
[ "$arg1" == "--version" ] && {
|
||||
echo "shorter, Version 0.4"
|
||||
echo "shorter, Version 2.1"
|
||||
exit 0
|
||||
}
|
||||
|
||||
@@ -56,6 +55,10 @@ mod_silence="false"
|
||||
ep4se="" # "Anzahl Ep S1","Anzahl Ep S2","Anzahl Ep S3", ...
|
||||
formats="mp4" # "all, mp4, ..."
|
||||
DEBUG="false"
|
||||
JobCounter="0"
|
||||
AllJobs="0"
|
||||
Start_String=""
|
||||
End_String_bevore_Ext=""
|
||||
|
||||
#load user default config
|
||||
[ -f "$HOME/.config/shorter/defaults.conf" ] && source "$HOME/.config/shorter/defaults.conf"
|
||||
@@ -63,11 +66,11 @@ DEBUG="false"
|
||||
#Define Global Const
|
||||
readonly NL=$'\n'
|
||||
|
||||
while getopts "d:e:sup:ft:Vv" arg; do
|
||||
while getopts "d:e:sup:ft:Vvh" arg; do
|
||||
case $arg in
|
||||
d)
|
||||
#ceck if is number
|
||||
if [ -n "$(echo "$file_name" | egrep ^[[:digit:]]+$)" ]; then
|
||||
if [ -n "$(echo "$OPTARG" | grep -E ^[[:digit:]]+$)" ]; then
|
||||
search_depth="$OPTARG"
|
||||
else
|
||||
echo "[-d]: Ungültige Suchtiefe: \"$OPTARG\": Ganzzahliger Ausdruck erwartet"
|
||||
@@ -76,8 +79,7 @@ while getopts "d:e:sup:ft:Vv" arg; do
|
||||
;;
|
||||
e)
|
||||
tmp="${OPTARG//,/}"
|
||||
echo $tmp
|
||||
if [ -n "$(echo "$tmp" | egrep ^[[:digit:]]+$)" ]; then
|
||||
if [ -n "$(echo "$tmp" | grep -E ^[[:digit:]]+$)" ]; then
|
||||
echo "mit komma getrennte episoden pro staffel: $OPTARG"
|
||||
ep4se="$OPTARG"
|
||||
else
|
||||
@@ -110,20 +112,22 @@ while getopts "d:e:sup:ft:Vv" arg; do
|
||||
[ -n "$OPTARG" ] && formats="$OPTARG"
|
||||
;;
|
||||
V)
|
||||
echo "shorter, Version 0.4"
|
||||
echo "shorter, Version 2.1"
|
||||
exit 0
|
||||
;;
|
||||
v)
|
||||
echo "Verbose Mode: ENABLED"
|
||||
DEBUG="true"
|
||||
;;
|
||||
h)
|
||||
hide="true"
|
||||
;;
|
||||
*)
|
||||
echo "--help for more information"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
#select_files [path] [deph] -> pathliste
|
||||
function select_files() {
|
||||
local Path="$1"
|
||||
@@ -140,6 +144,12 @@ function select_files() {
|
||||
fi
|
||||
}
|
||||
|
||||
#rmTrailingZero [string] -> stdout
|
||||
# löscht alle forangehenden 0
|
||||
function rmTrailingZero() {
|
||||
echo $1 | sed -e 's/^[0]*//'
|
||||
}
|
||||
|
||||
#search_int_nextto_string [full_string_string_string] [search_pattern] -> stdout (each nl)
|
||||
# finde alle zusammenhängenden zahlen hinter string
|
||||
function search_int_nextto_string() {
|
||||
@@ -170,11 +180,11 @@ function search_int_nextto_string() {
|
||||
|
||||
for i in $char; do
|
||||
|
||||
[[ "$i" = [0-9] ]] && return_int=""$return_int""$i""
|
||||
[[ "$i" = [0-9] ]] && return_int="$return_int$i"
|
||||
[[ "$i" = [0-9] ]] || break
|
||||
|
||||
done
|
||||
echo "$return_int" | egrep -v '^\s*$'
|
||||
rmTrailingZero $(echo "$return_int" | grep -v -E '^\s*$')
|
||||
|
||||
done
|
||||
|
||||
@@ -190,8 +200,8 @@ function search_pattern() {
|
||||
local Episode=""
|
||||
local diff_elem="false" ## used to check arrays if there are different integers in it
|
||||
local mode="season"
|
||||
declare -a Array_S
|
||||
declare -a Array_E
|
||||
declare -a Array_S=()
|
||||
declare -a Array_E=()
|
||||
|
||||
#handle file extention
|
||||
file_name="$(echo "$file_name" | rev | cut -d "." -f 2- | rev )"
|
||||
@@ -224,37 +234,48 @@ function search_pattern() {
|
||||
}
|
||||
|
||||
file_name="${file_name// /_}" #leerzeichen ersetzen
|
||||
file_name="${file_name//-/_}" #minus ersetzen
|
||||
file_name="$(echo "$file_name" | tr "[A-Z]" "[a-z]")"
|
||||
|
||||
debug "search_pattern: file_name = $file_name"
|
||||
|
||||
#analysieren > modus -> 3modis: Staffel&Epis|Count|Other
|
||||
|
||||
#sondefall numbers only -> wechsle zu counter
|
||||
[ -n "$(echo "$file_name" | grep -E ^[[:digit:]]+$)" ] && {
|
||||
Array_E[0]="$file_name"
|
||||
debug "Name is only a Number: \"$file_name\" => Counter mode"
|
||||
}
|
||||
|
||||
#default.conf:
|
||||
debug "Add \"$Start_String\" at the Front of $file_name"
|
||||
debug "Add \"$End_String_bevore_Ext\" at the End of $file_name"
|
||||
file_name="$Start_String"$file_name"$End_String_bevore_Ext"
|
||||
debug "new filename: with end and start var: $file_name"
|
||||
|
||||
|
||||
#check if config files exist
|
||||
[ -f "$HOME/.config/shorter/pattern-season.conf" ] || { echoerr "search_pattern: Error: pattern-season.conf not exist"; exit 5; }
|
||||
[ -f "$HOME/.config/shorter/pattern-episode.conf" ] || { echoerr "search_pattern: Error: pattern-episode.conf not exist"; exit 5; }
|
||||
|
||||
#für alle staffeln-muster -> ints in array
|
||||
Array_S=($(cat "$HOME/.config/shorter/pattern-season.conf" | tr "[A-Z]" "[a-z]" | grep -v "^$" | while read line; do
|
||||
Array_S+=($(cat "$HOME/.config/shorter/pattern-season.conf" | grep -v "#" | tr "[A-Z]" "[a-z]" | grep -v "^$" | while read line; do
|
||||
debug "search_pattern: season-pattern: $line"
|
||||
search_int_nextto_string "$file_name" "$line"
|
||||
done | tr '\n' ' '))
|
||||
debug "search_pattern: Array_S(${#Array_S[@]}): ${Array_S[@]}"
|
||||
|
||||
#sondefall numbers only -> wechsle zu counter
|
||||
[ -n "$(echo "$file_name" | egrep ^[[:digit:]]+$)" ] && {
|
||||
Array_E[0]="$file_name"
|
||||
debug "Name is only a Number => Counter mode"
|
||||
}
|
||||
|
||||
|
||||
#für alle episoden-muster -> ints in array
|
||||
Array_E=($(cat "$HOME/.config/shorter/pattern-episode.conf" | tr "[A-Z]" "[a-z]" | grep -v "^$" | while read line; do
|
||||
Array_E+=($(cat "$HOME/.config/shorter/pattern-episode.conf" | grep -v "#" | tr "[A-Z]" "[a-z]" | grep -v "^$" | while read line; do
|
||||
debug "search_pattern: season-episode: $line"
|
||||
search_int_nextto_string "$file_name" "$line"
|
||||
done | tr '\n' ' '))
|
||||
debug "search_pattern: Array_E(${#Array_E[@]}): ${Array_E[@]}"
|
||||
|
||||
#lösche alle führenden "0" in arrays
|
||||
Array_E=($(for i in "${Array_E[@]}"; do echo "$i" | sed 's/^[0]*//'; done))
|
||||
Array_S=($(for i in "${Array_S[@]}"; do echo "$i" | sed 's/^[0]*//'; done))
|
||||
|
||||
#wenn keien episode gefunden -> user input
|
||||
[ "${#Array_E[@]}" -gt 0 ] && {
|
||||
|
||||
@@ -324,13 +345,17 @@ function search_pattern() {
|
||||
}
|
||||
fi
|
||||
debug "Countermode: Episode: $Episode"
|
||||
#return number only if ep4se is not set
|
||||
echo "$Episode$file_ext" | sed 's/^[0]*//'
|
||||
return
|
||||
#else
|
||||
# calc S??E??
|
||||
#
|
||||
|
||||
if [ -z "$ep4se" ]; then
|
||||
#return number only if ep4se is not set
|
||||
echo "$Episode$file_ext" | sed 's/^[0]*//'
|
||||
debug "search_pattern: No -e"
|
||||
else
|
||||
#return output od denumber function
|
||||
debug "search_pattern: use -e"
|
||||
decounter "$Episode" "$file_ext"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -340,13 +365,62 @@ function search_pattern() {
|
||||
## 2Do Ask USER
|
||||
echoerr "select_patern: USER Input needed"
|
||||
echoerr "Current Name: \"$file_name_no_smal\""
|
||||
echoerr -n "Use only Return to skip it: New Name > "
|
||||
echo -en "\033[2KUse only Return to skip it: New Name > " >&2
|
||||
local New_Name=""
|
||||
read New_Name < /dev/tty
|
||||
[ -n "$New_Name" ] && echo "$New_Name$file_ext"
|
||||
|
||||
}
|
||||
|
||||
#Normalize_SuE [season] [episode] (extention) -> S??E??.ext | S??E??
|
||||
function Normalize_SuE() {
|
||||
local S="$1"
|
||||
local E="$2"
|
||||
local F="$3"
|
||||
|
||||
[ -z "$S" ] && {
|
||||
echoerr "No Season Param!"
|
||||
return
|
||||
}
|
||||
|
||||
[ -z "$E" ] && {
|
||||
echoerr "No Episode Param!"
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
E="$(echo ${E} | sed 's/^[0]*//')"
|
||||
S="$(echo ${S} | sed 's/^[0]*//')"
|
||||
[ "${E}" -le 9 ] && E="0${E}"
|
||||
[ "${S}" -le 9 ] && S="0${S}"
|
||||
echo "S${S}E${E}${F}"
|
||||
}
|
||||
|
||||
#destaffler [Folge] [Format]
|
||||
function decounter() {
|
||||
|
||||
local Folge="$1"
|
||||
local Staffel="1"
|
||||
local Format="$2"
|
||||
local Result_found="false"
|
||||
|
||||
for i in `echo ${ep4se//,/ }`; do
|
||||
if [ "$Folge" -gt "$i" ]; then
|
||||
Folge="$(("$Folge"-"$i"))"
|
||||
Staffel="$(($Staffel+1))"
|
||||
else
|
||||
debug "destaffler: param for Normalize_SuE: (S:) $Staffel (E:) $Folge (Format:) $Format"
|
||||
Result_found="true"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$Result_found" == "true" ]; then
|
||||
Normalize_SuE "$Staffel" "$Folge" "$Format"
|
||||
else
|
||||
echoerr "Invalied Input: -e or Invalied Episode: \"$1\""
|
||||
fi
|
||||
}
|
||||
|
||||
#rename_manager [Vorher_Path_file] [new name]
|
||||
function rename_manager() {
|
||||
@@ -354,24 +428,24 @@ function rename_manager() {
|
||||
local New_Name="$2"
|
||||
|
||||
[ -f "$Vorher_File" ] || {
|
||||
echo "rename_manager: ERROR: File: \"$Vorher_File\" doesnt exist anymore!"
|
||||
echoerr "rename_manager: ERROR: File: \"$Vorher_File\" doesnt exist anymore!"
|
||||
return
|
||||
}
|
||||
|
||||
[ -z "$New_Name" ] && {
|
||||
echo "rename_manager: ERROR: New Name is Null"
|
||||
echoerr "rename_manager: ERROR: New Name is Null"
|
||||
return
|
||||
}
|
||||
|
||||
local New_File_Path=""`echo "$Vorher_File" | rev | cut -d "/" -f 2- | rev`"/$New_Name"
|
||||
|
||||
[ -z "$New_File_Path" ] && {
|
||||
echo "rename_manager: ERROR: GetPath from Oldfile and add NewFileName failed!"
|
||||
echoerr "rename_manager: ERROR: GetPath from Oldfile and add NewFileName failed!"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$New_File_Path" == "$Vorher_File" ] && {
|
||||
echo "rename_manager: INFO: Die Datei \"$New_File_Path\" muss nicht umbenannt werden!"
|
||||
[ "$hide" == "" ] && echoerr "rename_manager: INFO: Die Datei \"$New_File_Path\" muss nicht umbenannt werden!"
|
||||
return
|
||||
}
|
||||
|
||||
@@ -379,7 +453,7 @@ function rename_manager() {
|
||||
#wenn bereits eine Datei vorhanden ist:
|
||||
[ -e "$New_File_Path" ] && {
|
||||
|
||||
echo "Es exestiert bereits das File \"$New_File_Path\""
|
||||
echoerr "Es exestiert bereits das File \"$New_File_Path\""
|
||||
|
||||
#wenn nich überschrieben werden soll
|
||||
[ "$mod_force" != "true" ] && {
|
||||
@@ -387,62 +461,88 @@ function rename_manager() {
|
||||
#wenn (nicht nicht) gefragt werden soll
|
||||
if [ "$mod_silence" != "true" ]; then
|
||||
|
||||
read -p"Soll die Datei überschrieben werden? (y/N)? " yN </dev/tty # </dev/tty wegen dem while read line, weil da schon read ist
|
||||
echo -ne "\033[2KSoll die Datei überschrieben werden? (y/N)? " >&2
|
||||
read yN </dev/tty # </dev/tty wegen dem while read line, weil da schon read ist
|
||||
#wenn yN nicht y ist
|
||||
[ "$yN" != "y" ] && {
|
||||
echo "Wird übersprungen!"
|
||||
echoerr "Wird übersprungen!"
|
||||
return
|
||||
}
|
||||
|
||||
else
|
||||
echo "Wird übersprungen!"
|
||||
echoerr "Wird übersprungen!"
|
||||
return
|
||||
fi
|
||||
}
|
||||
echo "Datei wird überschrieben!: $New_File_Path"
|
||||
rm "$New_File_Path"
|
||||
echoerr "Datei wird überschrieben!: $New_File_Path"
|
||||
tocache "$New_File_Path"
|
||||
}
|
||||
|
||||
echo "Die Datei \"$Vorher_File\" wird zu \"$New_Name\" umbenannt"
|
||||
echoerr "Die Datei \"$Vorher_File\" wird zu \"$New_Name\" umbenannt"
|
||||
|
||||
echo ""$Vorher_File"^"$New_File_Path"" >> $HOME/.cache/shorter/Log.txt
|
||||
echo "$Vorher_File>$New_File_Path" >> $HOME/.cache/shorter/Log.txt
|
||||
mv "$Vorher_File" "$New_File_Path"
|
||||
|
||||
|
||||
}
|
||||
|
||||
#tocache [path_to_file]
|
||||
function tocache() {
|
||||
local Path_to_File="$1"
|
||||
local File_Name="$(echo "$Path_to_File" | rev | cut -d "/" -f 1 | rev)"
|
||||
local New_File_Path="$HOME/.cache/shorter/Log/$File_Name"
|
||||
|
||||
[ -e "$Path_to_File" ] || {
|
||||
echoerr "tocache: File doesn't exist: $Path_to_File!"
|
||||
return
|
||||
}
|
||||
|
||||
debug "tocache: filename: $File_Name"
|
||||
while [ -e "${New_File_Path}" ]; do
|
||||
New_File_Path+="_"
|
||||
done
|
||||
debug "tocache: Filepath in .cache: $New_File_Path"
|
||||
|
||||
debug "tocache: mv $Path_to_File -> $New_File_Path"
|
||||
|
||||
echo "$Path_to_File>$New_File_Path" >> $HOME/.cache/shorter/Log.txt
|
||||
mv "$Path_to_File" "$New_File_Path"
|
||||
}
|
||||
|
||||
#undo
|
||||
function undo() {
|
||||
|
||||
local File="`tac $HOME/.cache/shorter/Log.txt | sed "/^$/d"`"
|
||||
|
||||
[ -z "$File" ] && {
|
||||
echo "Nichts zu tun!"
|
||||
echoerr "Nichts zu tun!"
|
||||
return
|
||||
}
|
||||
AllJobs="$(echo -n "$File" | grep -c '^')"
|
||||
|
||||
echo "$File" | while read line; do
|
||||
JobCounter="$(($JobCounter+1))"
|
||||
|
||||
#Vorher == Name befor das File umbenannt wurde (1 Teil im Log)
|
||||
#Jetzt == Name der exestiert (2 Teil im Log)
|
||||
local Vorher="`echo "$line" | cut -d "^" -f 1`"
|
||||
local Jetzt="`echo "$line" | cut -d "^" -f 2`"
|
||||
local Vorher="`echo "$line" | cut -d ">" -f 1`"
|
||||
local Jetzt="`echo "$line" | cut -d ">" -f 2`"
|
||||
|
||||
[ "$Vorher" == "$Jetzt" ] && {
|
||||
echo "undo: [Error] Die Datei wurde nicht umbenannt: $Vorher"
|
||||
echoerr "undo: [Error] Die Datei wurde nicht umbenannt: $Vorher"
|
||||
continue
|
||||
}
|
||||
|
||||
[ -f "$Jetzt" ] || {
|
||||
echo "undo: [Error] Datei existiert nicht mehr: $Jetzt"
|
||||
echo "undo: [Error] Fehlgeschlagene Dateien können mit einem erneuten Vorgang umbenannt werden!"
|
||||
echoerr "undo: [Error] Datei existiert nicht mehr: $Jetzt"
|
||||
echoerr " ==> Fehlgeschlagene Dateien können mit einem erneuten Vorgang umbenannt werden!"
|
||||
continue
|
||||
}
|
||||
|
||||
#wenn bereits eine Datei mit dem Namen vorhanden ist:
|
||||
[ -e "$Vorher" ] && {
|
||||
|
||||
echo "[info] Es exestiert bereits das File \"$Vorher\""
|
||||
echoerr "[info] Es exestiert bereits das File \"$Vorher\""
|
||||
|
||||
#wenn nich überschrieben werden soll
|
||||
[ "$mod_force" != "true" ] && {
|
||||
@@ -450,28 +550,29 @@ function undo() {
|
||||
#wenn (nicht nicht) gefragt werden soll
|
||||
if [ "$mod_silence" != "true" ]; then
|
||||
|
||||
read -p "Soll die Datei überschrieben werden? (y/N)? " yN </dev/tty # </dev/tty wegen dem while read line, weil da schon read ist
|
||||
echo -ne "\033[2KSoll die Datei überschrieben werden? (y/N)? " >&2
|
||||
read yN </dev/tty # </dev/tty wegen dem while read line, weil da schon read ist
|
||||
#wenn yN nicht y ist
|
||||
[ "$yN" != "y" ] && {
|
||||
echo "Überspringe Datei"
|
||||
echo "[info] Fehlgeschlagene Dateien können mit einem erneuten Vorgang umbenannt werden!"
|
||||
echoerr "Überspringe Datei"
|
||||
echoerr "[info] Fehlgeschlagene Dateien können mit einem erneuten Vorgang umbenannt werden!"
|
||||
continue
|
||||
}
|
||||
|
||||
else
|
||||
echo "mod_silence=true ==> Überpringe Datei"
|
||||
echo "[info] Fehlgeschlagene Dateien können mit einem erneuten Vorgang umbenannt werden!"
|
||||
echoerr "mod_silence=true ==> Überpringe Datei"
|
||||
echoerr "[info] Fehlgeschlagene Dateien können mit einem erneuten Vorgang umbenannt werden!"
|
||||
continue
|
||||
fi
|
||||
}
|
||||
echo "Datei wird überschrieben!: $Vorher"
|
||||
echoerr "Datei wird überschrieben!: $Vorher"
|
||||
|
||||
}
|
||||
|
||||
echo "undo: [main] Verschiebe: \"$Jetzt\" nach \"$Vorher\""
|
||||
echoerr "undo: [main] Verschiebe: \"$Jetzt\" nach \"$Vorher\""
|
||||
|
||||
#entferne erfolgreicge vorgänge aus log
|
||||
echo "`cat $HOME/.cache/shorter/Log.txt | grep -v "$Vorher^$Jetzt" | grep -v "^$"`" > $HOME/.cache/shorter/Log.txt
|
||||
echo "`cat $HOME/.cache/shorter/Log.txt |grep -v "$Vorher>$Jetzt" | grep -v "^$"`" > $HOME/.cache/shorter/Log.txt
|
||||
|
||||
mv "$Jetzt" "$Vorher"
|
||||
|
||||
@@ -480,6 +581,41 @@ function undo() {
|
||||
}
|
||||
|
||||
|
||||
function echo_Fortschritt() {
|
||||
|
||||
[ "$AllJobs" == "0" ] || [ -z "$AllJobs" ] && {
|
||||
return
|
||||
}
|
||||
local Prozent="$((($JobCounter*100)/$AllJobs))"
|
||||
local Hashtek=""
|
||||
|
||||
[ -z "$Prozent" ] && Prozent="0"
|
||||
Hashtek="--------------------"
|
||||
[ "$Prozent" -gt "4" ] && Hashtek="#-------------------"
|
||||
[ "$Prozent" -gt "9" ] && Hashtek="##------------------"
|
||||
[ "$Prozent" -gt "14" ] && Hashtek="###-----------------"
|
||||
[ "$Prozent" -gt "19" ] && Hashtek="####----------------"
|
||||
[ "$Prozent" -gt "24" ] && Hashtek="#####---------------"
|
||||
[ "$Prozent" -gt "29" ] && Hashtek="######--------------"
|
||||
[ "$Prozent" -gt "34" ] && Hashtek="#######-------------"
|
||||
[ "$Prozent" -gt "39" ] && Hashtek="########------------"
|
||||
[ "$Prozent" -gt "44" ] && Hashtek="#########-----------"
|
||||
[ "$Prozent" -gt "49" ] && Hashtek="##########----------"
|
||||
[ "$Prozent" -gt "54" ] && Hashtek="###########---------"
|
||||
[ "$Prozent" -gt "59" ] && Hashtek="############--------"
|
||||
[ "$Prozent" -gt "64" ] && Hashtek="#############-------"
|
||||
[ "$Prozent" -gt "69" ] && Hashtek="##############------"
|
||||
[ "$Prozent" -gt "74" ] && Hashtek="###############-----"
|
||||
[ "$Prozent" -gt "79" ] && Hashtek="################----"
|
||||
[ "$Prozent" -gt "84" ] && Hashtek="#################---"
|
||||
[ "$Prozent" -gt "89" ] && Hashtek="##################--"
|
||||
[ "$Prozent" -gt "94" ] && Hashtek="###################-"
|
||||
[ "$Prozent" -gt "99" ] && Hashtek="####################"
|
||||
############################################################################
|
||||
echo -ne "${Hashtek}(${Prozent}%) \r" >&2
|
||||
}
|
||||
|
||||
|
||||
function main() {
|
||||
local Files="`select_files "$path" "$search_depth"`"
|
||||
[ -z "$Files" ] && {
|
||||
@@ -487,7 +623,12 @@ function main() {
|
||||
return
|
||||
}
|
||||
|
||||
AllJobs="$(echo -n "$Files" | grep -c '^')"
|
||||
|
||||
debug "Lines: $AllJobs"
|
||||
|
||||
echo "$Files" | while read line; do
|
||||
JobCounter="$(($JobCounter+1))"
|
||||
|
||||
#get filename on
|
||||
local job="`echo "$line" | rev | cut -d "/" -f 1 | rev `"
|
||||
@@ -505,91 +646,105 @@ function main() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
## subfunctions
|
||||
#echoerr [msg]
|
||||
function echoerr() {
|
||||
echo $@ >&2
|
||||
echo -e "\033[2K$@" >&2
|
||||
echo_Fortschritt
|
||||
}
|
||||
|
||||
#log_clear
|
||||
function log_clear() {
|
||||
echo "" > $HOME/.cache/shorter/Log.txt
|
||||
[ -z "$(find "$HOME/.cache/shorter/Log/" -type d -empty)" ] && rm -r "$HOME/.cache/shorter/Log/"*
|
||||
}
|
||||
|
||||
|
||||
function debug() {
|
||||
[ "$DEBUG" == "true" ] && echo "DEBUG: $@" >&2
|
||||
}
|
||||
|
||||
#Normalize_SuE [season] [episode] (extention) -> S??E??.ext | S??E??
|
||||
function Normalize_SuE() {
|
||||
local S="$1"
|
||||
local E="$2"
|
||||
local F="$3"
|
||||
|
||||
[ -z "$S" ] && [ -z "$E" ] && {
|
||||
echoerr "Normalize_SuE: Error: not all param exist: \"$@\""
|
||||
}
|
||||
|
||||
E="$(echo ${E} | sed 's/^[0]*//')"
|
||||
S="$(echo ${S} | sed 's/^[0]*//')"
|
||||
[ "${E}" -le 9 ] && E="0${E}"
|
||||
[ "${S}" -le 9 ] && S="0${S}"
|
||||
echo "S${S}E${E}${file_ext}"
|
||||
[ "$DEBUG" == "true" ] && echo -e "\033[2KDEBUG: $@" >&2
|
||||
echo_Fortschritt
|
||||
}
|
||||
|
||||
#init
|
||||
function init() {
|
||||
# wenn noch nie gelaufen creat cache and ..
|
||||
[ -d "$HOME/.cache/shorter/" ] || mkdir -p "$HOME/.cache/shorter/"
|
||||
[ -d "$HOME/.config/shorter/" ] || mkdir -p "$HOME/.config/shorter/"
|
||||
[ -d "$HOME/.cache/shorter/Log" ] || { echoerr "init: create Path ~/.cache/shorter/Log/"; mkdir -p "$HOME/.cache/shorter/Log"; }
|
||||
[ -d "$HOME/.config/shorter/" ] || { echoerr "init: create Path ~/.config/shorter/"; mkdir -p "$HOME/.config/shorter/"; }
|
||||
|
||||
[ -f "$HOME/.config/shorter/replaces.conf" ] || {
|
||||
echoerr "init: create replaces.conf ..."
|
||||
echo "#Don't use - ! Use _! " >> "$HOME/.config/shorter/replaces.conf"
|
||||
echo "IV=S04" >> "$HOME/.config/shorter/replaces.conf"
|
||||
echo "III=S03" >> "$HOME/.config/shorter/replaces.conf"
|
||||
echo "II=S02" >> "$HOME/.config/shorter/replaces.conf"
|
||||
echo "480p=_" >> "$HOME/.config/shorter/replaces.conf"
|
||||
echo "720p=_" >> "$HOME/.config/shorter/replaces.conf"
|
||||
echo "#geht nicht 2 =S02" >> "$HOME/.config/shorter/replaces.conf"
|
||||
|
||||
|
||||
}
|
||||
|
||||
[ -f "$HOME/.config/shorter/pattern-season.conf" ] || {
|
||||
echoerr "init: create pattern-season.conf ..."
|
||||
echo "#Don't use - ! Use _! " >> "$HOME/.config/shorter/pattern-season.conf"
|
||||
echo "S" >> "$HOME/.config/shorter/pattern-season.conf"
|
||||
echo "Season_" >> "$HOME/.config/shorter/pattern-season.conf"
|
||||
echo "Season." >> "$HOME/.config/shorter/pattern-season.conf"
|
||||
echo "S_" >> "$HOME/.config/shorter/pattern-season.conf"
|
||||
echo "" >> "$HOME/.config/shorter/pattern-season.conf"
|
||||
echo "#.S" >> "$HOME/.config/shorter/pattern-season.conf"
|
||||
echo "#_S" >> "$HOME/.config/shorter/pattern-season.conf"
|
||||
echo "Staffel_" >> "$HOME/.config/shorter/pattern-season.conf"
|
||||
|
||||
|
||||
}
|
||||
|
||||
[ -f "$HOME/.config/shorter/pattern-episode.conf" ] || {
|
||||
echoerr "init: create pattern-episode.conf ..." ;
|
||||
echo "E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "Episode" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "Episode_" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "Ep." >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "Ep_" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "_" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "#Don't use - ! Use _! " >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "Episode" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "Episode_" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "Ep." >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "Ep_" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "Folge_" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "#0E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "#1E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "#2E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "#3E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "#4E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "#5E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "#6E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "#7E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "#8E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
echo "#9E" >> "$HOME/.config/shorter/pattern-episode.conf"
|
||||
|
||||
}
|
||||
|
||||
|
||||
[ -f "$HOME/.config/shorter/defaults.conf" ] || {
|
||||
echoerr "init: create defaults.conf ..." ;
|
||||
echo '#Deflaut configs for shorter:' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'search_depth=1' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'path="`pwd`"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'mod_force="false"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'mod_silence="false"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo '#formats: mp4,avi,... | all'>> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'formats="mp4"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'DEBUG="false"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo '#Deflaut configs for shorter:'>> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'search_depth=1' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'path="`pwd`"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'mod_force="false"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'mod_silence="false"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo '#formats: mp4,avi,... | all' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'formats="mp4"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'DEBUG="false"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo '#Start_String="E"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'Start_String=""' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo 'End_String_bevore_Ext=""' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo '' >> "$HOME/.config/shorter/defaults.conf"
|
||||
echo '#Start_String="_"' >> "$HOME/.config/shorter/defaults.conf"
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
####################### Programm start ###############################
|
||||
|
||||
init
|
||||
@@ -601,5 +756,8 @@ else
|
||||
undo
|
||||
fi
|
||||
|
||||
echo -e "\033[2K"
|
||||
exit
|
||||
|
||||
|
||||
#Globales ToDo: alle info & Error ausgaben nach stderr
|
||||
|
Reference in New Issue
Block a user