Update from local disk cleanup
This commit is contained in:
55
cli.py
55
cli.py
@@ -1,6 +1,7 @@
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
import time
|
||||
from src.core.torrent_session import TorrentSession
|
||||
from src.data.database_manager import DatabaseManager
|
||||
|
||||
@@ -24,10 +25,14 @@ def main():
|
||||
status_parser = subparsers.add_parser("status", help="Get status of a specific torrent")
|
||||
status_parser.add_argument("hash", help="Info hash of the torrent")
|
||||
|
||||
# Monitor command
|
||||
monitor_parser = subparsers.add_parser("monitor", help="Monitor status of a specific torrent in real-time")
|
||||
monitor_parser.add_argument("hash", help="Info hash of the torrent")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
app_dir = get_app_dir()
|
||||
db_path = os.path.join(app_dir, "citorrent.db")
|
||||
db_path = os.path.join(app_dir, "citorrent.data")
|
||||
save_path = os.path.join(app_dir, "downloads")
|
||||
os.makedirs(save_path, exist_ok=True)
|
||||
|
||||
@@ -45,6 +50,9 @@ def main():
|
||||
|
||||
if handle:
|
||||
info_hash = handle.info_hash().to_string()
|
||||
if isinstance(info_hash, bytes):
|
||||
info_hash = info_hash.hex()
|
||||
|
||||
# Simplified adding to DB for CLI tool
|
||||
db.add_torrent({
|
||||
"info_hash": info_hash,
|
||||
@@ -69,7 +77,10 @@ def main():
|
||||
print(f"{'Hash':<40} {'Name':<30} {'Status':<15} {'Progress':<10}")
|
||||
print("-" * 95)
|
||||
for t in torrents:
|
||||
print(f"{t.get('info_hash', 'N/A'):<40} {t.get('name', 'N/A'):<30} {t.get('status', 'N/A'):<15} {t.get('progress', 0):<10}")
|
||||
h = t.get('info_hash', 'N/A')
|
||||
if isinstance(h, bytes):
|
||||
h = h.hex()
|
||||
print(f"{h:<40} {t.get('name', 'N/A'):<30} {t.get('status', 'N/A'):<15} {t.get('progress', 0):<10}")
|
||||
|
||||
elif args.command == "status":
|
||||
# For status, we need to check if it's currently in the session
|
||||
@@ -86,8 +97,12 @@ def main():
|
||||
|
||||
# Now check specific hash
|
||||
found = False
|
||||
for handle in session.handles():
|
||||
if handle.info_hash().to_string() == args.hash:
|
||||
print(f"Checking {len(session.get_all_handles())} active handles...")
|
||||
for handle in session.get_all_handles():
|
||||
h = handle.info_hash().to_string()
|
||||
if isinstance(h, bytes): h = h.hex()
|
||||
print(f"Found handle: {h}")
|
||||
if h == args.hash:
|
||||
status = session.get_status(handle)
|
||||
print(f"Torrent {args.hash} Status:")
|
||||
print(f" Name: {status['name']}")
|
||||
@@ -98,6 +113,38 @@ def main():
|
||||
if not found:
|
||||
print(f"Torrent with hash {args.hash} not found in active session.")
|
||||
|
||||
elif args.command == "monitor":
|
||||
import time
|
||||
print("Resuming torrents from DB to monitor status...")
|
||||
existing = db.get_all_torrents()
|
||||
for t in existing:
|
||||
source = t.get("source", "")
|
||||
if source.startswith("magnet:"):
|
||||
session.add_magnet(source)
|
||||
elif os.path.exists(source):
|
||||
session.add_torrent_file(source)
|
||||
|
||||
print(f"Monitoring torrent {args.hash}. Press Ctrl+C to stop.")
|
||||
try:
|
||||
while True:
|
||||
found = False
|
||||
for handle in session.get_all_handles():
|
||||
h = handle.info_hash().to_string()
|
||||
if isinstance(h, bytes): h = h.hex()
|
||||
if h == args.hash:
|
||||
status = session.get_status(handle)
|
||||
print(f"[{time.strftime('%H:%M:%S')}] {status['name']} | Progress: {status['progress']:.2%} | State: {status['state']}")
|
||||
found = True
|
||||
if str(status['state']) == 'seeding':
|
||||
print("Torrent is now seeding!")
|
||||
break
|
||||
break
|
||||
if not found:
|
||||
print(f"[{time.strftime('%H:%M:%S')}] Torrent {args.hash} not found in active session.")
|
||||
time.sleep(5)
|
||||
except KeyboardInterrupt:
|
||||
print("\nMonitoring stopped.")
|
||||
|
||||
else:
|
||||
parser.print_help()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user