123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #!/bin/bash
- # Coding: utf-8
- # Editor: kate
- # Created 2022-04-08
- #_sudo_apt_install_ transmission-remote
- #_sudo_dpkg_i_
- source $HOME/.SCR/lib.sh
- fun_log_dir_create $0 360 4
- con_test_not_exist_process
- case "$1" in
- "pc" )
- device="pc"
- device_name="pc"
- ip="127.0.0.1"
- port="9091"
- hash_dir="$tmp1"
- deleted_torrent_log="$tmp2"
- ;;
- "tvbox" )
- device="tvbox"
- device_name="tv box"
- ip="192.168.100.101"
- port="9091"
- hash_dir="$tmp3"
- deleted_torrent_log="$tmp4"
- ;;
- * )
- fun_echo_stadia 11 0 "Unknow device"
- exit
- ;;
- esac
- con_test_ip_port_open "$ip" "$port"
- con_transmission_not_download "$device"
- fun_echo_variable device device_name ip port hash_dir deleted_torrent_log
- fun_percent_down () # первый аргумент - id
- {
- percent_down="$(fun_transmission "$device" -t "$1" -i | grep "Percent Done" | cut -f5- -d " ")" # находим объем скачанного в процентах
- }
- torennts_ids="$(fun_transmission "$device" -l | awk '{print $1}' | sed -e "s/*//g" | grep -v "ID" | grep -v "Sum" | sort -n | tee ${dir_script}/${device}_torrents_ids)" # создаем список id
- for id in $torennts_ids
- do
- echo ""
- fun_echo_stadia 15 0 "Torrent number $id"
- fun_percent_down $id
- if [ "$percent_down" == "100%" ]
- then
- fun_echo_stadia 15 0 "Downloading persent is $percent_down"
- torrent_hash="$(fun_transmission "$device" -t $id -i | grep "Hash" | cut -f4 -d " ")" # находим хэш каждого торрэнта
- if [ ! -f "$hash_dir/$torrent_hash" ] # проверка торрэнта
- then
- ,speech_en.sh "Torrent number $id in $device_name downloaded"
- fun_echo_stadia 15 0 "Hash $torrent_hash not exist in any file name in folder $hash_dir"
- verify_number="1"
- percent_down="99%"
- while [ "$percent_down" != "100%" ]
- do
- fun_transmission "$device" --torrent "$id" --verify
- fun_analize_command "Start verification number $verify_number. Torrent number $id."
- torrent_status="Verifying"
- sec="0"
- while [ "$torrent_status" == "Verifying" ]
- do
- sleep 3
- fun_echo_stadia 15 0 "Verification number $verify_number. Torrent number $id. $sec seconds have passed"
- torrent_status="$(fun_transmission "$device" --torrent "$id" --info | grep "State" | cut -f4 -d" ")" # находим статус торрэнта
- sec=$(($sec+3))
- done
- fun_percent_down $id
- verify_number=$(($verify_number+1))
- if [ "${verify_number}" -gt "3" ]
- then
- fun_echo_stadia 15 0 "The number of verifications exceeded 3. Exit"
- ,speech_en.sh "Fatal errors verification torrent number $id in $device_name"
- exit 111
- fi
- done
- fun_transmission "$device" --torrent "$id" --start --seedratio-default
- fun_analize_command "Redownload torrent number $id. Set default ratio limit"
- ,speech_en.sh "Torrent number $id in $device_name verified"
- echo "hash: $torrent_hash verify number: $verify_number" > "${hash_dir}/${torrent_hash}"
- fun_analize_command "Write hash to file name ${hash_dir}/${torrent_hash}"
- else
- fun_echo_stadia 15 0 "Hash $torrent_hash exist in file name in $hash_dir"
- torrent_state="$(fun_transmission "$device" -t "$id" -i | grep "State:" | cut -f4 -d " ")" # узнаем статус торрэнта
- fun_echo_stadia 15 0 "Torrent status is $torrent_state"
- if [ "$torrent_state" == "Finished" ] # удаление завершенного торрэнта
- then
- while read torrent_folder
- do
- torrent_path="$(fun_transmission "$device" -t "$id" -i | grep "Location:" | cut -f4 -d " ")" # путь до торрэнта
- if [[ "$torrent_path" == *"$torrent_folder"* ]]
- then
- fun_echo_stadia 15 0 "Torrent located in work folder $torrent_path"
- fun_transmission "$device" -t "$id" -i > "${deleted_torrent_log}/$(date +%y-%m-%d_%H-%M-%S_%6N)_deleted_torrent" # выводим данные удаляемого торрэнта в файл
- fun_transmission "$device" -t "$id" --remove
- fun_analize_command "Remove torrent number $id"
- rm -rf "${hash_dir}/${torrent_hash}"
- fun_analize_command "Delete hash in file name in ${hash_dir}/${torrent_hash}"
- ,speech_en.sh "Torrent number $id in $device_name removed"
- else
- fun_echo_stadia 15 0 "Torrent number $id not located in $torrent_dir"
- fi
- done < "$HOME/.SCR/list/torrent_folders.list"
- else
- fun_echo_stadia 15 0 "Upload torrent number $id not complited"
- fi
- fi
- else
- fun_echo_stadia 15 0 "Torrent number $id not downloaded"
- fi
- done
|