Вики IT-KB

Пошаговые руководства, шпаргалки, полезные ссылки...

Инструменты пользователя

Инструменты сайта


apple-mac-os:macos-monterey:automate-torrent-downloads-on-macos

Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слеваПредыдущая версия
Следующая версия
Предыдущая версия
apple-mac-os:macos-monterey:automate-torrent-downloads-on-macos [08.02.2022 15:19] Виталий Якобapple-mac-os:macos-monterey:automate-torrent-downloads-on-macos [08.11.2023 20:36] (текущий) Виталий Якоб
Строка 16: Строка 16:
         then         then
  #Authentication  #Authentication
-          HOST=My-Router.local+          HOST=My-Router.local
           PORT=9092           PORT=9092
           USER=torruser           USER=torruser
Строка 22: Строка 22:
  
             #Encoding torrent file             #Encoding torrent file
-            METAINFO=$(base64 $file)+            METAINFO=$(base64 -i $file)
             # set true if you want every torrent to be paused initially             # set true if you want every torrent to be paused initially
             #PAUSED="true"             #PAUSED="true"
Строка 38: Строка 38:
  
 В итоге получился рабочий вариант, который не зависит от устаревающего **Automator**, также добавлена обработка ошибок и уведомления. В итоге получился рабочий вариант, который не зависит от устаревающего **Automator**, также добавлена обработка ошибок и уведомления.
-Сохраняем скрипт в каталоге ''~/Library/Workflows/Applications/Folder Actions/''+Сохраняем скрипт в каталоге ''~/Library/Scripts/Folder Action Scripts''
  
-<code applescript>--Обрабатываемый тип файлов+<code AppleScript> 
 +--Глобальная переменная, передаём расширение файла
 property FileExt : "torrent" property FileExt : "torrent"
 +--Выполняется при любом добавлении файла в каталог
 on adding folder items to this_folder after receiving added_items on adding folder items to this_folder after receiving added_items
  repeat with torrentFile in added_items  repeat with torrentFile in added_items
- tell application "Finder+ tell application "System Events" 
- if the name extension of the torrentFile is in the FileExt then + --если добавленный файл имеет расширение torrent, процесс запускается 
- (* + if the name extension of the torrentFile is equal to FileExt then 
-Параметры переменных подключения к серверу + --Параметры переменных подключения к серверу 
-Пользователь, пароль, порт настраиваются в /opt/etc/transmission/settings.json на стороне сервера + --Пользователь, пароль, порт настраиваются в /opt/etc/transmission/settings.json на стороне сервера
-*)+
  set transmissionuser to "torruser"  set transmissionuser to "torruser"
  set transmissionpass to "torrpassword"  set transmissionpass to "torrpassword"
Строка 58: Строка 58:
  set transmissionurl to "http://" & transmissionhost & ":" & transmissionport  set transmissionurl to "http://" & transmissionhost & ":" & transmissionport
  set rpcurl to transmissionurl & "/transmission/rpc"  set rpcurl to transmissionurl & "/transmission/rpc"
- --Проверяем доступность сервера + --Если сервер доступенотправляем файл 
- try + if (my CheckServer(transmissionhost, transmissionport)) is true ¬ 
- do shell script "nc -z " & transmissionhost & space & transmissionport + then my SendTorrent(torrentFile, rpcurl, transmissionauth)
- try +
- set metainfo to do shell script "base64 " & quoted form of (POSIX path of (torrentFile)) +
- set sessionid to do shell script "curl --silent " & rpcurl & " --anyauth --user " & transmissionauth & ¬ +
- " | sed 's/.*<code>//g;s/<\\/code>.*//g'" +
- set json to "{\"method\": \"torrent-add\", \"arguments\":{\"metainfo\":\"" & metainfo & "\" }}" +
- set answer to do shell script "curl --silent --anyauth --user " & transmissionauth & space & rpcurl & " --header " & ¬ +
- quoted form of (sessionid) & " -d " & quoted form of (json) & " | sed 's/.*result\\\":\\\"//g;s/\\\"}//g'" +
- if answer = "success" then +
- -- Показ уведомления об успешной отправке +
- display notification (name of torrentFile as text) with title "Transmission-RPC" subtitle "Успешно отправлен на закачку" +
- --Удаление обработанного .torrent файла +
- --delete torrentFile -- удаление в корзину +
- do shell script "rm -f " & quoted form of (POSIX path of (torrentFile)) +
- else +
- -- Сообщение об ошибке отправки .torrent файла, исчезает через 10 сек +
- set errMsg to do shell script "echo " & quoted form of (answer) & " | sed 's/.*<p>//g;s/<\\/p>.*//g'" +
- display dialog "Ошибка отправки файла: " & (name of torrentFile) & ". +
- +
-Ответ сервера: " & errMsg with title "Transmission-RPC" buttons {"OK"} default button 1 with icon stop giving up after 10 +
- end if +
- end try +
- on error +
- -- Сообщение об ошибке связи с сервером, исчезает через 10 сек +
- display dialog "Сервер transmission " & transmissionhost & " недоступен" with title ¬ +
- "Transmission-RPC" buttons {"OK"} default button 1 with icon stop giving up after 10 +
- end try+
  end if  end if
  end tell  end tell
  end repeat  end repeat
-end adding folder items to</code>+end adding folder items to 
 + 
 +--Проверка доступности сервера 
 +on CheckServer(thost, tport) 
 + try 
 + do shell script "nc -z" & space & thost & space & tport 
 + return true 
 + on error 
 + display dialog "Сервер transmission" & space & thost & space & "недоступен." with title ¬ 
 + "Transmission-RPC" buttons {"OK"} default button 1 with icon stop giving up after 10 
 + end try 
 +end CheckServer 
 + 
 +--Отправка torrent файла в формате base64 
 +on SendTorrent(torrentFile, rpcurl, transmissionauth) 
 + set metainfo to do shell script "base64 -i " & quoted form of (POSIX path of (torrentFile)) 
 + set sessionid to do shell script "curl --silent " & rpcurl & " --anyauth --user " & transmissionauth & ¬ 
 + " | sed 's/.*<code>//g;s/<\\/code>.*//g'" 
 + set json to "{\"method\": \"torrent-add\", \"arguments\":{\"metainfo\":\"" & metainfo & "\" }}" 
 + set answer to do shell script "curl --silent --anyauth --user " & transmissionauth & space & rpcurl & " --header " & ¬ 
 + quoted form of (sessionid) & " -d " & quoted form of (json) & " | sed 's/.*result\\\":\\\"//g;s/\\\"}//g'" 
 + if answer is equal to "success" then 
 + my SuccessAction(torrentFile) 
 + else 
 + my ErrorAction(answer, torrentFile) 
 + end if 
 +end SendTorrent 
 + 
 +--В случае успеха отправки 
 +on SuccessAction(torrentFile) 
 + -- Показ уведомления об успешной отправке 
 + display notification name of (info for (torrentFile as alias)) with title "Transmission-RPC" subtitle "Успешно отправлен на закачку" 
 + --Удаление обработанного .torrent файла 
 + --delete torrentFile -- удаление в корзину 
 + do shell script "rm -f " & quoted form of (POSIX path of (torrentFile)) 
 +end SuccessAction 
 + 
 +--В случае неудачи отправки 
 +on ErrorAction(answer, torrentFile) 
 + -- Сообщение об ошибке отправки .torrent файла, исчезает через 10 сек 
 + set errMsg to do shell script "echo " & quoted form of (answer) & " | sed 's/.*<p>//g;s/<\\/p>.*//g'" 
 + display dialog "Ошибка отправки файла: " & quoted form of (name of (info for (torrentFile as alias))) & "." & return & "Ответ сервера:" & space & ¬ 
 + errMsg with title "Transmission-RPC" buttons {"OK"} default button 1 with icon stop giving up after 10 
 +end ErrorAction 
 +</code>
  
 Для установки скрипта вызываем контекстное меню на каталоге: Для установки скрипта вызываем контекстное меню на каталоге:
Строка 110: Строка 128:
 ^ Версия ОС                                   ^ ^ Версия ОС                                   ^
 | Apple macOS Monterey (12.0)  | | Apple macOS Monterey (12.0)  |
 +| Apple macOS Ventura (13.0)  |
 +| Apple macOS Sonoma (14.0)  |
  
 ---- ----
apple-mac-os/macos-monterey/automate-torrent-downloads-on-macos.1644322750.txt.gz · Последнее изменение: 08.02.2022 15:19 — Виталий Якоб

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki