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