sane-bt-add: support moving torrents to new directories
This commit is contained in:
parent
e8265807a9
commit
afe27fd9cb
|
@ -3,9 +3,12 @@ from __future__ import annotations
|
||||||
from argparse import ArgumentParser, Namespace
|
from argparse import ArgumentParser, Namespace
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MediaMeta:
|
class MediaMeta:
|
||||||
title: str | None
|
title: str | None
|
||||||
|
@ -87,19 +90,41 @@ class TransmissionApi:
|
||||||
return open(self.PASSFILE, "r").read().strip()
|
return open(self.PASSFILE, "r").read().strip()
|
||||||
|
|
||||||
def add_torrent(self, meta: MediaMeta, torrent: str):
|
def add_torrent(self, meta: MediaMeta, torrent: str):
|
||||||
print(f"saving to {meta.fs_path()}")
|
self.call_transmission(
|
||||||
self.call_transmission([
|
description=f"saving to {meta.fs_path()}",
|
||||||
|
args=[
|
||||||
"--download-dir", meta.fs_path(),
|
"--download-dir", meta.fs_path(),
|
||||||
"--add", torrent,
|
"--add", torrent,
|
||||||
])
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def move_torrent(self, meta: MediaMeta, torrent: str):
|
||||||
|
self.call_transmission(
|
||||||
|
description=f"moving {torrent} to {meta.fs_path()}",
|
||||||
|
args=[
|
||||||
|
"--torrent", torrent,
|
||||||
|
"--move", meta.fs_path()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def add_or_move_torrent(self, meta: MediaMeta, torrent: str):
|
||||||
|
"""
|
||||||
|
if "torrent" represents a magnet or file URI, then add else
|
||||||
|
else assume it's a transmission identifier and move it to the location specified by @p meta.
|
||||||
|
"""
|
||||||
|
if torrent.isdigit():
|
||||||
|
self.move_torrent(meta, torrent)
|
||||||
|
else:
|
||||||
|
self.add_torrent(meta, torrent)
|
||||||
|
|
||||||
def rm_torrent(self, torrent: str | int):
|
def rm_torrent(self, torrent: str | int):
|
||||||
print(f"deleting {torrent}")
|
self.call_transmission(
|
||||||
self.call_transmission([
|
description=f"deleting {torrent}",
|
||||||
|
args=[
|
||||||
"--torrent", torrent,
|
"--torrent", torrent,
|
||||||
"--remove-and-delete"
|
"--remove-and-delete"
|
||||||
])
|
]
|
||||||
|
)
|
||||||
|
|
||||||
def list_(self) -> str:
|
def list_(self) -> str:
|
||||||
return self.call_transmission([
|
return self.call_transmission([
|
||||||
|
@ -108,11 +133,14 @@ class TransmissionApi:
|
||||||
|
|
||||||
def info(self, torrent: str) -> str:
|
def info(self, torrent: str) -> str:
|
||||||
return self.call_transmission([
|
return self.call_transmission([
|
||||||
"-t", torrent,
|
"--torrent", torrent,
|
||||||
"-i"
|
"--info"
|
||||||
])
|
])
|
||||||
|
|
||||||
def call_transmission(self, args: list[str]) -> str:
|
def call_transmission(self, args: list[str], description: str | None = None) -> str:
|
||||||
|
if description is not None:
|
||||||
|
logger.info(description)
|
||||||
|
|
||||||
return self.check_output([
|
return self.check_output([
|
||||||
"transmission-remote",
|
"transmission-remote",
|
||||||
self.ENDPOINT,
|
self.ENDPOINT,
|
||||||
|
|
|
@ -3,11 +3,15 @@
|
||||||
# vim: set filetype=python :
|
# vim: set filetype=python :
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
from sane_bt import MediaMeta, TransmissionApi
|
from sane_bt import MediaMeta, TransmissionApi
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
logging.basicConfig()
|
||||||
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="instruct servo to download some torrent")
|
parser = argparse.ArgumentParser(description="instruct servo to download some torrent")
|
||||||
TransmissionApi.add_arguments(parser)
|
TransmissionApi.add_arguments(parser)
|
||||||
MediaMeta.add_arguments(parser)
|
MediaMeta.add_arguments(parser)
|
||||||
|
@ -18,7 +22,7 @@ def main():
|
||||||
bt_api = TransmissionApi.from_arguments(args)
|
bt_api = TransmissionApi.from_arguments(args)
|
||||||
torrent = args.torrent
|
torrent = args.torrent
|
||||||
|
|
||||||
bt_api.add_torrent(meta, torrent)
|
bt_api.add_or_move_torrent(meta, torrent)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -3,11 +3,15 @@
|
||||||
# vim: set filetype=python :
|
# vim: set filetype=python :
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
from sane_bt import TransmissionApi
|
from sane_bt import TransmissionApi
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
logging.basicConfig()
|
||||||
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="remove a torrent and trash its data")
|
parser = argparse.ArgumentParser(description="remove a torrent and trash its data")
|
||||||
TransmissionApi.add_arguments(parser)
|
TransmissionApi.add_arguments(parser)
|
||||||
parser.add_argument("torrent", help="numerical ID of the torrent in the transmission list (see sane-bt-show)")
|
parser.add_argument("torrent", help="numerical ID of the torrent in the transmission list (see sane-bt-show)")
|
||||||
|
|
|
@ -3,10 +3,14 @@
|
||||||
# vim: set filetype=python :
|
# vim: set filetype=python :
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
from sane_bt import MediaMeta, TransmissionApi
|
from sane_bt import MediaMeta, TransmissionApi
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
logging.basicConfig()
|
||||||
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="show information about one or more torrents on servo")
|
parser = argparse.ArgumentParser(description="show information about one or more torrents on servo")
|
||||||
TransmissionApi.add_arguments(parser)
|
TransmissionApi.add_arguments(parser)
|
||||||
parser.add_argument("torrents", nargs="*", help="torrent id to show (acquire by first calling with no args)")
|
parser.add_argument("torrents", nargs="*", help="torrent id to show (acquire by first calling with no args)")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user