Last active
June 12, 2024 05:38
-
-
Save iwconfig/c5acb558d3d720fb7f6c38650f89bf59 to your computer and use it in GitHub Desktop.
stuff i use
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 | |
## A simple script which is set in the Transmission config to execute one script after the other. | |
## In this case 'cleaned-public-torrents.sh' after filebot has processed the file(s). | |
# Copyright 2016 iwconfig | |
/bin/bash /home/osmc/.config/transmission-daemon/userscripts/filebot-watch-transmission.sh && wait | |
if [ ! "$(pidof /bin/filebot)" ]; then | |
/bin/bash /home/osmc/.config/transmission-daemon/userscripts/cleanup-public-torrents.sh | |
fi |
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 | |
## On torrent finnish, Filebot picks up and process the content | |
## It also determines which hard drive for filebot to store the content, | |
## although it may be a little messy. I dont even remember if that part works correctly. | |
## Anyways, in the end it also updates the kodi database, based on medium; | |
## video file --> video library, Music --> Music library | |
# MIT License | |
# Copyright (c) 2016 iwconfig | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
if [[ -e "$1" ]]; then | |
if [[ "$1" = /* ]]; then | |
TR_TORRENT_DIR="$(dirname "$1")" | |
TR_TORRENT_NAME="$(basename "$1")" | |
else | |
path="$(readlink -f "$1")" | |
TR_TORRENT_DIR="$(dirname "$path")" | |
TR_TORRENT_NAME="$(basename "$path")" | |
fi | |
else | |
echo "Fil eller mapp existerar ej..." | |
fi | |
if [[ $TR_TORRENT_DIR == *"/media/Media+backups/"* ]] || [[ $TR_TORRENT_DIR == *"/media/Media2/"* ]]; then | |
action="hardlink" | |
else | |
action="copy" | |
fi | |
run_filebot(){ | |
/usr/bin/filebot -script fn:amc \ | |
-rename "$TR_TORRENT_DIR/$TR_TORRENT_NAME" \ | |
--action ${action} \ | |
--conflict skip \ | |
-non-strict \ | |
--log-file amc.log \ | |
--def "subtitles=sv,en" \ | |
"excludeList=/usr/share/filebot/data/osmc/amc.excludes" \ | |
"unsorted=n" "music=y" "artwork=y" \ | |
"seriesFormat=/media/Media+backups/TV-serier/{n}/Säsong {s}/{n.replaceTrailingBrackets()} - {s+'x'}{e.pad(2)} - {t.replaceAll(/[!?.]+$/).replaceAll(/[\`\´\‘\’\ʻ]/, '\'').lowerTrail().replacePart(replacement = ', Part $1')}" \ | |
"movieFormat=/media/Media2/{genres.contains('Documentary') ? 'Dokumentärer' : genres.contains('Music') ? 'Musikvideor' : 'Filmer'}/{n.replaceAll(/[:|]/, ' - ')} ({y}) [{vf}]/{n.replaceAll(/[:|]/, ' - ')} ({y}{', '+director}) [{vf}{' '+source}]" \ | |
"musicFormat=/media/Media+backups/Musik/{media.Performer}/{media.Album}{' ('+y+')'}/{media.TrackPosition.pad(2)} {media.Title}" \ | |
&> /tmp/filebot.log | |
} | |
if ! echo "$TR_TORRENT_DIR/$TR_TORRENT_NAME" | egrep -iq "audiobook"; then | |
run_filebot | |
else | |
echo "$TR_TORRENT_DIR/$TR_TORRENT_NAME" >> /usr/share/filebot/data/osmc/amc.excludes | |
exit 0 | |
fi | |
## om uttrymme fattas | |
if grep ": No space left on device" /tmp/filebot.log; then | |
until tail -n 2 /tmp/filebot.log | grep "Done"; do | |
### /media/Media+backups (tv-serier och musik) ### | |
if grep -E "Group: \[music|Group: \[tvs:" /tmp/filebot.log; then | |
dl_path="$(du -s '$TR_TORRENT_DIR/$TR_TORRENT_NAME' | awk '{ print $1 }')" | |
hddrive="$(df | grep '/media/Media+backups' | awk '{ print $4 }')" | |
while [ "$dl_path" -gt "$hddrive" ]; do | |
dl_path="$(du -s '$TR_TORRENT_DIR/$TR_TORRENT_NAME' | awk '{ print $1 }')" | |
hddrive="$(df | grep '/media/Media+backups' | awk '{ print $4 }')" | |
#if (( "$dl_path" > "$hddrive" )); then | |
echo "file do not fit" > /tmp/blabla.log | |
curl --data-binary '{ "id": "filebot", "jsonrpc": "2.0", "method": "GUI.ShowNotification", "params":{"title": "Filebot: Frigör uttrymme på Media+backups!", "message": "Hårddisken är full!" }}' -H 'content-type: application/json;' http://localhost:80/jsonrpc | |
sleep 10 | |
#else | |
# echo "file fits alright" | |
#fi | |
done | |
fi | |
### /media/Media2 (Filmer och musikvideos) ### | |
if grep -E "Group: \[movies:" /tmp/filebot.log; then | |
dl_path="$(du -s '$TR_TORRENT_DIR/$TR_TORRENT_NAME' | awk '{ print $1 }')" | |
hddrive="$(df | grep '/media/Media2' | awk '{ print $4 }')" | |
while [ "$dl_path" -gt "$hddrive" ]; do | |
dl_path="$(du -s '$TR_TORRENT_DIR/$TR_TORRENT_NAME' | awk '{ print $1 }')" | |
hddrive="$(df | grep '/media/Media2' | awk '{ print $4 }')" | |
#if (( "$dl_path" > "$hddrive" )); then | |
echo "file do not fit" >/tmp/blabla.log | |
curl --data-binary '{ "id": "filebot", "jsonrpc": "2.0", "method": "GUI.ShowNotification", "params":{"title": "Filebot: Frigör uttrymme på Media2!", "message": "Hårddisken är full!" }}' -H 'content-type: application/json;' http://localhost:80/jsonrpc | |
sleep 10 | |
#else | |
# echo "file fits alright" | |
#fi | |
done | |
fi | |
run_filebot | |
done | |
fi | |
## Uppdatera biblioteken | |
if grep "Group: \[music:" /tmp/filebot.log; then | |
curl --data-binary '{ "jsonrpc": "2.0", "method": "AudioLibrary.Scan", "id": "filebot"}' -H 'content-type: application/json;' http://localhost:80/jsonrpc | |
elif ! grep "Group: \[tvs:null, mov:null, anime:null\]" /tmp/filebot.log; then | |
curl --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "filebot"}' -H 'content-type: application/json;' http://localhost:80/jsonrpc | |
fi | |
rm /tmp/filebot.log | |
exit |
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 | |
## Either updates or cleans the kodi libraries, or both. | |
## Either specific library or both (video or music). | |
# MIT License | |
# Copyright (c) 2016 iwconfig | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
halp() { | |
cat <<EOF | |
Uppdaterar kodi's mediadatabas. | |
Användning: | |
$(basename $0) { alternativ... } [ bibliotek... ] | |
-u, --update - Uppdaterar antingen hela mediacentrets databas eller enbart valt bibliotek (v eller a). | |
-c, --cleanup - Rensar och tar bort "döda" länkar i databasen, som inte längre finns kvar på hårddisken. | |
Antingen hela mediacentrets databas eller enbart valt bibliotek (v eller a). | |
-r, --refresh - Rensar och uppdaterar antingen hela mediacentrets databas eller enbat valt bibliotek (v eller a). | |
Bibliotek: | |
v, video - Uppdatera/rensa videobiblioteket. | |
a, audio - Uppdatera/rensa ljudbiblioteket. | |
EOF | |
} | |
video_scan() { | |
curl -s --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "kodi-db"}' -H 'content-type: application/json;' http://localhost:80/jsonrpc >/dev/null | |
echo "Videokataloger skannas och biblioteket uppdateras..." | |
} | |
audio_scan() { | |
curl -s --data-binary '{ "jsonrpc": "2.0", "method": "AudioLibrary.Scan", "id": "kodi-db"}' -H 'content-type: application/json;' http://localhost:80/jsonrpc >/dev/null | |
echo "Ljudkataloger skannas och biblioteket uppdateras..." | |
} | |
video_clean() { | |
curl -s --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Clean", "id": "kodi-db"}' -H 'content-type: application/json;' http://localhost:80/jsonrpc >/dev/null | |
echo "Videobiblioteket rensad." | |
} | |
audio_clean() { | |
curl -s --data-binary '{ "jsonrpc": "2.0", "method": "AudioLibrary.Clean", "id": "kodi-db"}' -H 'content-type: application/json;' http://localhost:80/jsonrpc >/dev/null | |
echo "Ljudbiblioteket rensad." | |
} | |
case "$1" in | |
"-u"|"--update") | |
if [ "$2" == "" ]; then | |
video_scan | |
audio_scan | |
exit 0 | |
fi | |
case "$2" in | |
"v"|"video") | |
video_scan | |
;; | |
"a"|"audio") | |
audio_scan | |
;; | |
*) | |
echo "fattar ej..." | |
halp | |
;; | |
esac | |
;; | |
"-c"|"--cleanup") | |
if [ "$2" == "" ]; then | |
video_clean | |
audio_clean | |
exit 0 | |
fi | |
case "$2" in | |
"v"|"video") | |
video_clean | |
;; | |
"a"|"audio") | |
audio_clean | |
;; | |
*) | |
echo "fattar ej..." | |
halp | |
;; | |
esac | |
;; | |
"-r"|"--refresh") | |
if [ "$2" == "" ]; then | |
video_clean | |
video_scan | |
audio_clean | |
audio_scan | |
exit 0 | |
fi | |
case "$2" in | |
"v"|"video") | |
video_clean | |
video_scan | |
;; | |
"a"|"audio") | |
audio_clean | |
audio_scan | |
;; | |
*) | |
echo "fattar ej..." | |
halp | |
;; | |
esac | |
;; | |
""|*) | |
halp | |
;; | |
esac |
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 | |
## Removes public torrents automatically from Transmission | |
## after they are finnished downloading. | |
## You could add a function to determine how long it has been seeding, | |
## if you want to contribute to the public trackers. | |
# MIT License | |
# Copyright (c) 2016 iwconfig | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
# Torrents with specific tracker URL:s to keep | |
private_trackers=( | |
'what.cd' | |
'broadcasthe.net' | |
'torrentday' | |
'bibliotik.me' | |
'passthepopcorn.me' | |
) | |
match=$(echo ${private_trackers[@]}|tr " " "|") | |
# Search all trackers which do NOT match the specified private trackers in the array above | |
# and delete the corresponding torrent | |
tor_id=( $(transmission-remote -l | grep "100%.*$TR_TORRENT_NAME" | awk '{ print $1 }') ) | |
for i in "${tor_id[@]}"; do | |
i=$(echo $i | grep -Eo "[0-9]+") | |
id="-t$i" | |
if ! transmission-remote $id -it | grep -E "$match" &>/dev/null; then | |
tor_name=$(transmission-remote $id -l | grep "100%" | sed -n -r 's/^.*(Idle|Seeding)\s+//p') | |
if transmission-remote $id --remove-and-delete | grep success; then | |
log="/home/osmc/.config/transmission-daemon/userscripts/cleaned-torrents.log" | |
[ ! -e "$log" ] && echo -e "REMOVED TORRENTS\n\nDate:\t\t\tTorrent name:" > "$log" | |
echo -e "$(date +%Y-%m-%d:%H:%M:%S)\t$tor_name" >> "$log" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment