Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
ximper-builder
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
ximper-builder
Commits
6ab45cd6
Commit
6ab45cd6
authored
Feb 14, 2025
by
Roman Alifanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some torrent tools
parent
907dd7d7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
235 additions
and
0 deletions
+235
-0
torrents_create
bin/torrents_create
+112
-0
torrents_deploy
bin/torrents_deploy
+123
-0
No files found.
bin/torrents_create
0 → 100755
View file @
6ab45cd6
#!/bin/bash
TRACKER
=
"udp://tracker.eterfund.ru:6969"
SCRIPT_NAME
=
$(
basename
"
$0
"
)
check_dependencies
()
{
if
!
command
-v
transmission-create &> /dev/null
;
then
echo
"Ошибка: transmission-cli не установлен"
>
&2
echo
"Установите пакет: sudo apt install transmission-cli"
>
&2
exit
1
fi
}
validate_files
()
{
local
missing
=()
for
file
in
"
${
FILES
[@]
}
"
;
do
if
[
!
-f
"
$file
"
]
;
then
missing+
=(
"
$file
"
)
fi
done
if
[
${#
missing
[@]
}
-gt
0
]
;
then
echo
"Не найдены следующие файлы:"
>
&2
printf
'• %s\n'
"
${
missing
[@]
}
"
>
&2
exit
1
fi
}
show_help
()
{
cat
<<
EOF
Использование:
$SCRIPT_NAME
[ОПЦИИ] [ФАЙЛЫ...]
Создает торрент-файлы для указанных ISO-образов
Если файлы не указаны, обрабатывает все *.iso в текущей директории
Примеры:
$SCRIPT_NAME
myfile.iso
$SCRIPT_NAME
*.iso
$SCRIPT_NAME
# Обработать все ISO-файлы
Опции:
-h, --help Показать справку и выйти
-t, --tracker Указать другой трекер (по умолчанию:
$TRACKER
)
EOF
}
parse_arguments
()
{
while
[[
$#
-gt
0
]]
;
do
case
$1
in
-h
|
--help
)
show_help
exit
0
;;
-t
|
--tracker
)
if
[
-z
"
$2
"
]
;
then
echo
"Ошибка: Не указан URL трекера"
>
&2
exit
1
fi
TRACKER
=
"
$2
"
shift
;;
-
*
)
echo
"Неизвестная опция:
$1
"
>
&2
show_help
exit
1
;;
*
)
FILES+
=(
"
$1
"
)
;;
esac
shift
done
if
[
${#
FILES
[@]
}
-eq
0
]
;
then
shopt
-s
nullglob
FILES
=(
*
.iso
)
shopt
-u
nullglob
if
[
${#
FILES
[@]
}
-eq
0
]
;
then
echo
"Не найдено ISO-файлов для обработки"
>
&2
exit
1
fi
fi
}
main
()
{
local
FILES
=()
parse_arguments
"
$@
"
check_dependencies
validate_files
for
iso_file
in
"
${
FILES
[@]
}
"
;
do
torrent_file
=
"
${
iso_file
%.iso
}
.torrent"
echo
"Создаю:
$torrent_file
"
echo
"Трекер:
$TRACKER
"
if
transmission-create
-o
"
$torrent_file
"
-t
"
$TRACKER
"
"
$iso_file
"
;
then
echo
"✓ Успешно создан:
$torrent_file
"
echo
else
echo
"✕ Ошибка при создании
$torrent_file
"
>
&2
exit
1
fi
done
echo
"Готово! Создано торрентов:
${#
FILES
[@]
}
"
}
main
"
$@
"
bin/torrents_deploy
0 → 100755
View file @
6ab45cd6
#!/bin/python3
import
argparse
import
base64
import
os
import
requests
import
getpass
import
logging
from
urllib.parse
import
urljoin
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
'
%(asctime)
s -
%(levelname)
s -
%(message)
s'
,
handlers
=
[
logging
.
FileHandler
(
'/tmp/transmission_add.log'
),
logging
.
StreamHandler
()
]
)
class
TransmissionClient
:
def
__init__
(
self
,
base_url
,
username
,
password
):
self
.
base_url
=
base_url
self
.
username
=
username
self
.
password
=
password
self
.
session
=
requests
.
Session
()
self
.
session
.
auth
=
(
username
,
password
)
self
.
session_id
=
None
def
get_session_id
(
self
):
try
:
response
=
self
.
session
.
get
(
self
.
base_url
,
headers
=
{
'Accept'
:
'application/json'
},
timeout
=
10
)
if
response
.
status_code
==
409
:
self
.
session_id
=
response
.
headers
.
get
(
'X-Transmission-Session-Id'
)
return
True
response
.
raise_for_status
()
return
True
except
Exception
as
e
:
logging
.
error
(
f
"Ошибка подключения: {str(e)}"
)
return
False
def
add_torrent
(
self
,
torrent_path
,
download_dir
):
if
not
self
.
session_id
:
if
not
self
.
get_session_id
():
return
False
try
:
with
open
(
torrent_path
,
'rb'
)
as
f
:
torrent_data
=
base64
.
b64encode
(
f
.
read
())
.
decode
(
'utf-8'
)
except
Exception
as
e
:
logging
.
error
(
f
"Ошибка чтения файла {torrent_path}: {str(e)}"
)
return
False
payload
=
{
"method"
:
"torrent-add"
,
"arguments"
:
{
"metainfo"
:
torrent_data
,
"download-dir"
:
download_dir
,
"paused"
:
False
}
}
try
:
response
=
self
.
session
.
post
(
self
.
base_url
,
json
=
payload
,
headers
=
{
'X-Transmission-Session-Id'
:
self
.
session_id
},
timeout
=
30
)
response
.
raise_for_status
()
result
=
response
.
json
()
if
result
.
get
(
'result'
)
==
'success'
:
logging
.
info
(
f
"Торрент успешно добавлен: {torrent_path}"
)
return
True
else
:
logging
.
error
(
f
"Ошибка добавления: {result.get('result', 'Unknown error')}"
)
return
False
except
Exception
as
e
:
logging
.
error
(
f
"API ошибка: {str(e)}"
)
if
hasattr
(
e
,
'response'
)
and
e
.
response
is
not
None
:
logging
.
error
(
f
"Ответ сервера: {e.response.text}"
)
return
False
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Добавление торрентов в Transmission'
)
parser
.
add_argument
(
'torrents'
,
nargs
=
'+'
,
help
=
'Пути к .torrent файлам'
)
args
=
parser
.
parse_args
()
username
=
input
(
"Логин Transmission: "
)
password
=
getpass
.
getpass
(
"Пароль Transmission: "
)
base_url
=
"https://tr.download.etersoft.ru/rpc"
client
=
TransmissionClient
(
base_url
,
username
,
password
)
for
torrent_path
in
args
.
torrents
:
if
not
os
.
path
.
isfile
(
torrent_path
):
logging
.
error
(
f
"Файл не существует: {torrent_path}"
)
continue
download_dir
=
os
.
path
.
realpath
(
os
.
path
.
dirname
(
torrent_path
))
if
not
os
.
access
(
torrent_path
,
os
.
R_OK
):
logging
.
error
(
f
"Нет прав на чтение файла: {torrent_path}"
)
continue
if
not
os
.
access
(
download_dir
,
os
.
W_OK
):
logging
.
error
(
f
"Нет прав на запись в папку: {download_dir}"
)
continue
if
not
client
.
add_torrent
(
torrent_path
,
download_dir
):
logging
.
error
(
f
"Не удалось добавить торрент: {torrent_path}"
)
if
__name__
==
"__main__"
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment