1
|
|
|
#!/usr/bin/python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
1 |
|
import argparse |
5
|
1 |
|
import logging |
6
|
|
|
|
7
|
1 |
|
from saucenao.files import Constraint, FileHandler, Filter |
8
|
1 |
|
from saucenao.saucenao import SauceNao, SauceNaoDatabase |
9
|
1 |
|
from saucenao.worker import Worker |
10
|
|
|
|
11
|
1 |
|
__all__ = [SauceNao, SauceNaoDatabase, FileHandler, Filter, Constraint] |
12
|
|
|
|
13
|
|
|
|
14
|
1 |
|
def run_application(): |
15
|
|
|
"""Run SauceNao based on arguments passed to the file |
16
|
|
|
|
17
|
|
|
:return: |
18
|
|
|
""" |
19
|
1 |
|
parser = argparse.ArgumentParser() |
20
|
1 |
|
parser.add_argument('-d', '--dir', help='directory to sort', required=True) |
21
|
1 |
|
parser.add_argument('-db', '--databases', default=999, type=int, help='which databases should be searched') |
22
|
1 |
|
parser.add_argument('-min', '--minimum-similarity', default=65, type=float, |
23
|
|
|
help='minimum similarity percentage') |
24
|
1 |
|
parser.add_argument('-c', '--combine-api-types', action='store_true', |
25
|
|
|
help='combine html and json api response to retrieve more information') |
26
|
1 |
|
parser.add_argument('-k', '--api-key', help='API key of your account on SauceNao') |
27
|
1 |
|
parser.add_argument('-p', '--premium', help='is API key related user premium') |
28
|
1 |
|
parser.add_argument('-x', '--exclude-categories', type=str, help='exclude specific categories from moving') |
29
|
1 |
|
parser.add_argument('-mv', '--move-to-categories', action='store_true', help='move images to categories') |
30
|
1 |
|
parser.add_argument('-author', '--use-author-as-category', default=False, action='store_true', |
31
|
|
|
help='use author as category key instead of material') |
32
|
1 |
|
parser.add_argument('-o', '--output-type', default=0, type=int, help='0(html) or 2(json) API response') |
33
|
1 |
|
parser.add_argument('-sf', '--start-file', |
34
|
|
|
help='with which file the checks start in case of after reaching the daily limit') |
35
|
1 |
|
parser.add_argument('-log', '--log-level', default=logging.ERROR, type=int, |
36
|
|
|
help='which log level should be used, check logging._levelNames for options') |
37
|
|
|
|
38
|
1 |
|
parser.add_argument('-fcrdt', '--filter-creation-date', type=str, |
39
|
|
|
help='filters files for created after given date. ' |
40
|
|
|
'Format of date has to match "d.m.Y[ H:M[:S]]"') |
41
|
1 |
|
parser.add_argument('-fmdt', '--filter-modified-date', type=str, |
42
|
|
|
help='filters files for modified after given date. ' |
43
|
|
|
'Format of date has to match "d.m.Y[ H:M[:S]]"') |
44
|
|
|
|
45
|
1 |
|
parser.add_argument('-tmin', '--title-minimum-similarity', default=95, type=float, |
46
|
|
|
help='minimum similarity percentage for title search with BakaUpdates, MyAnimeList and ' |
47
|
|
|
'VisualNovelDatabase') |
48
|
|
|
|
49
|
1 |
|
args = parser.parse_args() |
50
|
|
|
|
51
|
1 |
|
file_filter = Filter(assert_is_file=True) |
52
|
1 |
|
if args.filter_creation_date: |
53
|
|
|
file_filter._filter_creation_date = Constraint(value=args.filter_creation_date, |
54
|
|
|
cmp_func=Constraint.cmp_value_bigger_or_equal) |
55
|
1 |
|
if args.filter_modified_date: |
56
|
|
|
file_filter._filter_modified_date = Constraint(value=args.filter_modified_date, |
57
|
|
|
cmp_func=Constraint.cmp_value_bigger_or_equal) |
58
|
1 |
|
working_files = FileHandler.get_files(args.dir, file_filter) |
59
|
|
|
|
60
|
1 |
|
saucenao_worker = Worker(files=working_files, directory=args.dir, databases=args.databases, |
61
|
|
|
minimum_similarity=args.minimum_similarity, combine_api_types=args.combine_api_types, |
62
|
|
|
api_key=args.api_key, is_premium=args.premium, |
63
|
|
|
exclude_categories=args.exclude_categories, move_to_categories=args.move_to_categories, |
64
|
|
|
use_author_as_category=args.use_author_as_category, start_file=args.start_file, |
65
|
|
|
log_level=args.log_level, title_minimum_similarity=args.title_minimum_similarity) |
66
|
|
|
return saucenao_worker.run() |
67
|
|
|
|