7
7
from library import usage
8
8
from library .mediafiles import torrents_start
9
9
from library .utils import arggroups , argparse_utils , consts , iterables , nums , path_utils , printing , processes , strings
10
+ from library .utils .log_utils import log
10
11
from library .utils .path_utils import domain_from_url , fqdn_from_url
11
12
12
13
@@ -472,8 +473,11 @@ def gen_row(t):
472
473
file_path .unlink (missing_ok = True )
473
474
break # Stop after deleting first valid path
474
475
475
- alt_move_syntax = any (k not in args .defaults for k in ["temp_drive" , "temp_prefix" , "download_drive" , "download_prefix" ])
476
+ alt_move_syntax = any (
477
+ k not in args .defaults for k in ["temp_drive" , "temp_prefix" , "download_drive" , "download_prefix" ]
478
+ )
476
479
if args .move or alt_move_syntax :
480
+
477
481
def set_temp_path (t , temp_path ):
478
482
if temp_path is None :
479
483
return
@@ -489,43 +493,51 @@ def set_download_path(t, download_path):
489
493
qbt_client .torrents_set_save_path (str (download_path ), torrent_hashes = [t .hash ])
490
494
491
495
for idx , t in enumerate (torrents ):
496
+ print ("Moving" , idx + 1 , "of" , len (torrents ))
497
+
492
498
originally_stopped = t .state_enum .is_stopped
493
499
qbt_client .torrents_stop (torrent_hashes = [t .hash ])
494
500
495
- print ("Moving" , idx + 1 , "of" , len (torrents ))
496
-
497
501
if "temp_drive" not in args .defaults :
498
502
temp_path = Path (args .temp_drive )
499
503
elif "temp_prefix" not in args .defaults :
500
- temp_path = Path (path_utils .mountpoint (t .download_path )) # keep existing drive
504
+ temp_path = Path (path_utils .mountpoint (t .download_path or t .content_path )) # keep existing drive
505
+ log .debug ("temp_path: using t.download_path %s mountpoint %s" , t .download_path , temp_path )
501
506
else :
502
507
temp_path = args .move
503
508
504
509
if "download_drive" not in args .defaults :
505
510
download_path = Path (args .download_drive )
506
511
elif "download_prefix" not in args .defaults :
507
- download_path = Path (path_utils .mountpoint (t .save_path )) # keep existing drive
512
+ download_path = Path (path_utils .mountpoint (t .save_path or t .content_path )) # keep existing drive
513
+ log .debug ("download_path: using t.save_path %s mountpoint %s" , t .save_path , download_path )
508
514
else :
509
515
download_path = args .move
510
516
511
- # --temp-drive or --move could be relative
512
- if not temp_path .is_absolute ():
513
- mountpoint = path_utils .mountpoint (t .content_path )
514
- temp_path = Path (mountpoint ) / temp_path
515
- if not download_path .is_absolute ():
516
- mountpoint = path_utils .mountpoint (t .content_path )
517
- download_path = Path (mountpoint ) / download_path
518
-
519
- if "temp_prefix" not in args .defaults :
520
- temp_path /= args .temp_prefix
521
- if "download_prefix" not in args .defaults :
522
- download_path /= args .download_prefix
523
-
524
- if args .tracker_dirnames :
525
- domain = t .tracker_domain ()
526
- if domain :
527
- temp_path /= domain
528
- download_path /= domain
517
+ if temp_path is not None :
518
+ if not temp_path .is_absolute (): # --X-drive or --move could be relative
519
+ mountpoint = path_utils .mountpoint (t .content_path )
520
+ temp_path = Path (mountpoint ) / temp_path
521
+ if args .temp_prefix :
522
+ temp_path /= args .temp_prefix
523
+ if args .tracker_dirnames :
524
+ domain = t .tracker_domain ()
525
+ if domain :
526
+ temp_path /= domain
527
+
528
+ if download_path is not None :
529
+ if not download_path .is_absolute ():
530
+ mountpoint = path_utils .mountpoint (t .content_path )
531
+ download_path = Path (mountpoint ) / download_path
532
+ if args .download_prefix :
533
+ download_path /= args .download_prefix
534
+ if args .tracker_dirnames :
535
+ domain = t .tracker_domain ()
536
+ if domain :
537
+ download_path /= domain
538
+
539
+ log .debug ("temp_path %s" , temp_path )
540
+ log .debug ("download_path %s" , download_path )
529
541
530
542
new_path = download_path if t .state_enum .is_complete else temp_path
531
543
if args .simulate :
@@ -536,16 +548,17 @@ def set_download_path(t, download_path):
536
548
new_path .mkdir (parents = True , exist_ok = True )
537
549
shutil .move (t .content_path , new_path )
538
550
539
- # update metadata
540
- if t .state_enum .is_complete : # temp path first
541
- set_temp_path (t , temp_path )
542
- set_download_path (t , download_path )
543
- else : # download path first
544
- set_download_path (t , download_path )
545
- set_temp_path (t , temp_path )
546
-
547
- if not originally_stopped :
548
- qbt_client .torrents_start (torrent_hashes = [t .hash ])
551
+ if not (args .delete_files or args .delete_rows ):
552
+ # update metadata
553
+ if t .state_enum .is_complete : # temp path first
554
+ set_temp_path (t , temp_path )
555
+ set_download_path (t , download_path )
556
+ else : # download path first
557
+ set_download_path (t , download_path )
558
+ set_temp_path (t , temp_path )
559
+
560
+ if not originally_stopped :
561
+ qbt_client .torrents_start (torrent_hashes = [t .hash ])
549
562
550
563
if args .start is not None :
551
564
print ("Starting" , len (torrents ))
0 commit comments