Skip to content

Instantly share code, notes, and snippets.

@taking
Last active November 15, 2020 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taking/32b7eb0abf47e70cb4a96d17faaaeac3 to your computer and use it in GitHub Desktop.
Save taking/32b7eb0abf47e70cb4a96d17faaaeac3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# 이 스크립트는 토렌트 다운로드 시, 폴더로 받아지는 경우 다음과 같은 작업을 진행한다.
# 1. 폴더 내 txt 가 있는 경우 제거
# 2. 폴더 내 mkv, mp4 확장자가 있는 경우, 다운로드 루트 폴더로 이동
# 2.1. 폴더 내 smi, srt 확장자가 있는 경우, 다운로드 루트 폴더로 이동
# 2.2. 폴더 내 .url 확장자가 있는 경우, 삭제
# - down-folder\test\1.mp4 -> down-folder\1.mp4
# 3. 빈 폴더는 삭제
# by taking
# A shell scirpt designed to be executed by qBittorrent's "Run external program on torrent completion"
# An example how to fill in qBittorrent's "Run external program on torrent completion" to execute this script
# /bin/bash -c "chmod +x /path/to/qbittorrent-txtremove-filemove.sh; /path/to/qbittorrent-txtremove-filemove.sh '%D'"
#
# Supported parameters (case sensitive):
# - %N: Torrent name
# - %L: Category
# - %G: Tags (separated by comma)
# - %F: Content path (same as root path for multifile torrent)
# - %R: Root path (first torrent subdirectory path)
# - %D: Save path
# - %C: Number of files
# - %Z: Torrent size (bytes)
# - %T: Current tracker
# - %I: Info hash
downpath="$1"
if [ -z "$downpath" ]; then
echo "ERROR: Expected <downpath> as the 1st argument but none given, <downpath> should be the Torrent Download Path (\"%D\") from qBittorrent"
exit 1
fi
echo 'downpath is' $downpath
find $downpath/* -maxdepth 2 -type f -iregex '.*.\.\(mkv\|mp4\|wmv\|flv\|webm\|avi\|mov\)' -size +1k -exec mv -t $downpath {} +
find $downpath/* -maxdepth 2 -type f -iregex '.*.\.\(smi\|srt\)' -size +1k -exec mv -t $downpath {} +
find $downpath/* -name "*.url" -type f -exec rm {} +
find $downpath/* -depth -type d -empty -exec rmdir {} \;
chown -R 1000:1000 $downpath
@taking
Copy link
Author

taking commented Nov 15, 2020

2개 실행 하려면,

/bin/bash -c "chmod +x /config/scripts/*.sh; /config/scripts/qbittorrent-discord-notify.sh '%N' '%Z' 'https://discord.com/api/webhooks/XXXXXXXXXXXXX/YYYYYYYYYYYYYYYYYYYY'; /config/scripts/qbittorrent-txtremove-filemove.sh '%D'"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment