mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-10-10 05:46:55 +08:00
Merge pull request #37 from SamuelCook/OrphanedFilesExcludePattern
Allow file patterns to exclude from orphan detection.
This commit is contained in:
commit
00088d057f
4 changed files with 40 additions and 10 deletions
|
@ -26,6 +26,7 @@ To run the script in an interactive terminal run:
|
|||
* Add the `tag` definition based on tracker URL
|
||||
* Modify the `nohardlinks` by specifying your completed movies/series category to match with qBittorrent. Please ensure the `root_dir` and/or `remote_dir` is added in the `directory` section
|
||||
* `root_dir` needs to be defined in order to use the RecycleBin function. If optional `empty_after_x_days` is not defined then it will never empty the RecycleBin. Setting it to 0 will empty the RecycleBin immediately.
|
||||
* Modify the `orphaned` section to define file patterns not to consider as orphans. Use this to exclude your incomplete torrents directory, or to ignore auto-generated files such as Thumbs.db.
|
||||
* To run the script in an interactive terminal with a list of possible commands run:
|
||||
|
||||
```bash
|
||||
|
|
|
@ -76,3 +76,12 @@ recyclebin:
|
|||
# If this variable is not defined it, the RecycleBin will never be emptied.
|
||||
# Setting this variable to 0 will delete files immediately.
|
||||
empty_after_x_days: 60
|
||||
|
||||
# Orphaned files are those in the root_dir download directory that are not referenced by any active torrents.
|
||||
orphaned:
|
||||
# File patterns that will not be considered orphaned files. Handy for generated files that aren't part of the torrent but belong with the torrent's files
|
||||
exclude_patterns:
|
||||
- "**/.DS_Store"
|
||||
- "**/Thumbs.db"
|
||||
- "**/@eaDir"
|
||||
- "/data/torrents/temp/**"
|
|
@ -78,3 +78,12 @@ recyclebin:
|
|||
# If this variable is not defined it, the RecycleBin will never be emptied.
|
||||
# WARNING: Setting this variable to 0 will delete all files immediately upon script run!
|
||||
empty_after_x_days: 60
|
||||
|
||||
# Orphaned files are those in the root_dir download directory that are not referenced by any active torrents.
|
||||
orphaned:
|
||||
# File patterns that will not be considered orphaned files. Handy for generated files that aren't part of the torrent but belong with the torrent's files
|
||||
exclude_patterns:
|
||||
- "**/.DS_Store"
|
||||
- "**/Thumbs.db"
|
||||
- "**/@eaDir"
|
||||
- "/data/torrents/temp/**"
|
|
@ -13,6 +13,7 @@ import datetime
|
|||
import time
|
||||
import stat
|
||||
import sys
|
||||
import fnmatch
|
||||
|
||||
try:
|
||||
from qbittorrentapi import Client
|
||||
|
@ -42,7 +43,6 @@ parser.add_argument('-sr', '--skip-recycle', dest='skip_recycle', action="store_
|
|||
parser.add_argument('-dr', '--dry-run', dest='dry_run', action="store_true", default=False, help='If you would like to see what is gonna happen but not actually move/delete or tag/categorize anything.')
|
||||
parser.add_argument('-ll', '--log-level', dest='log_level', action="store", default='INFO', type=str, help='Change your log level.')
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
def get_arg(env_str, default, arg_bool=False, arg_int=False):
|
||||
|
@ -537,6 +537,7 @@ def set_rem_unregistered():
|
|||
if (len(pot_unr) > 0):
|
||||
logger.debug(f'Potential Unregistered torrents: {pot_unr}')
|
||||
|
||||
|
||||
def set_rem_orphaned():
|
||||
if rem_orphaned:
|
||||
torrent_files = []
|
||||
|
@ -554,10 +555,20 @@ def set_rem_orphaned():
|
|||
|
||||
orphaned_files = set(root_files) - set(torrent_files)
|
||||
orphaned_files = sorted(orphaned_files)
|
||||
|
||||
excluded_orphan_files = []
|
||||
if 'orphaned' in cfg and cfg["orphaned"] is not None and 'exclude_patterns' in cfg['orphaned'] and cfg['orphaned']['exclude_patterns'] != '':
|
||||
exclude_patterns = cfg['orphaned']['exclude_patterns']
|
||||
excluded_orphan_files = [file for file in orphaned_files for exclude_pattern in exclude_patterns if fnmatch.fnmatch(file, exclude_pattern)]
|
||||
|
||||
orphaned_files = set(orphaned_files) - set(excluded_orphan_files)
|
||||
|
||||
logger.debug('----------torrent files-----------')
|
||||
logger.debug("\n".join(torrent_files))
|
||||
logger.debug('----------root_files-----------')
|
||||
logger.debug("\n".join(root_files))
|
||||
logger.debug('----------excluded_orphan_files-----------')
|
||||
logger.debug("\n".join(excluded_orphan_files))
|
||||
logger.debug('----------orphaned_files-----------')
|
||||
logger.debug("\n".join(orphaned_files))
|
||||
logger.debug('----------Deleting orphan files-----------')
|
||||
|
|
Loading…
Add table
Reference in a new issue