Last active
September 20, 2022 10:39
-
-
Save ParsaAlizadeh/7e4c85a52b9bca6593f0d43b5ef31ac8 to your computer and use it in GitHub Desktop.
Remember which episode you had watched
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Desktop Entry] | |
Type=Service | |
X-KDE-ServiceTypes=KonqPopupMenu/Plugin | |
MimeType=inode/directory; | |
Actions=fimlAction; | |
Icon=videoclip-amarok | |
[Desktop Action fimlAction] | |
Name=Fiml | |
Icon=videoclip-amarok | |
Exec=/path/to/fiml.sh "%u" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
dialog() { | |
kdialog --title "fiml" "$@" 2>/dev/null | |
} | |
return-code() { | |
local result=0 | |
"$@" || { result=$?; } | |
echo ${result} | |
} | |
play-vlc() { | |
local -r film="$1" sub="$2" | |
local cmd=(vlc "${film}") | |
if [[ -n "${sub}" ]]; then | |
cmd+=(--sub-file "${sub}") | |
fi | |
"${cmd[@]}" >/dev/null 2>&1 | |
} | |
find-by-ext() { | |
local -r ext="$1" | |
find -iname "*.${ext}" -print0 | |
} | |
find-films() { | |
{ find-by-ext mp4; find-by-ext mkv; } | sort -z | |
} | |
find-subs() { | |
find-by-ext srt | sort -z | |
} | |
find-and-set() { | |
readarray -d '' films < <(find-films) | |
readarray -d '' subs < <(find-subs) | |
} | |
play-nth() { | |
local -r n="$1" | |
play-vlc "${films[$n]}" "${subs[$n]:-""}" | |
} | |
read-counter() { | |
[[ -f ".fiml" ]] && counter=$(< ".fiml") || counter=0 | |
} | |
write-counter() { | |
echo ${counter} > ".fiml" | |
} | |
choose-film() { | |
local radiopts=() toggle item | |
for i in ${!films[@]}; do | |
(( counter == i )) && toggle=on || toggle=off | |
item="${films[$i]}" | |
if [[ -n "${subs[$i]:-""}" ]]; then | |
item="${item} + subtitle" | |
fi | |
radiopts+=($i "${item}" ${toggle}) | |
done | |
dialog --radiolist "Which episode?" "${radiopts[@]}" | |
} | |
ask-reset-counter() { | |
local result | |
result=$(return-code dialog --yesnocancel "Reset the counter?") | |
if (( result == 2 )); then | |
return 1 | |
elif (( result == 0 )); then | |
counter="${selected}" | |
fi | |
} | |
ask-complete-watch() { | |
local result | |
result=$(return-code dialog --yesno "Did you watch the episode?") | |
if (( result == 0 )); then | |
(( counter += 1 )) | |
fi | |
} | |
main() { | |
local path="$1" | |
[[ -n "${path}" ]] || path="./" | |
cd "${path}" | |
find-and-set | |
read-counter | |
local selected | |
selected="$(choose-film)" | |
[[ -n "${selected}" ]] || exit | |
(( selected == counter )) || ask-reset-counter || exit | |
play-nth "${selected}" | |
(( selected != counter )) || ask-complete-watch | |
write-counter | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment