-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawljob.py
64 lines (49 loc) · 2.06 KB
/
crawljob.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from __future__ import unicode_literals, division, absolute_import
from builtins import * # noqa pylint: disable=unused-import, redefined-builtin
import os
from loguru import logger
from flexget import plugin
from flexget.event import event
from flexget.utils.pathscrub import pathscrub
plugin_name = 'crawljob'
logger = logger.bind(name=plugin_name)
class OutputCrawljob(object):
"""
This plugin (base make_html) create a .crawljob file for each accepted entry.
The file name is 'title' and there is 'url' in the text file.
This file (.crawljob) is for used with JDownloader2
Requis :
path: directory for the .crawljob files
(ex : "C:\\Users\\Julot\\AppData\\Local\\JDownloader 2.0\\folderwatch")
Example:
crawljob:
path: "{? jd2.watch ?}"
"""
schema = {
'type': 'object',
'properties': {
'path': {'type': 'string'}
},
'required': ['path'],
'additionalProperties': False
}
def on_task_output(self, task, config):
output = os.path.expanduser(config['path'])
# Output to config directory if absolute path has not been specified
if not os.path.isabs(output):
output = os.path.join(task.manager.config_base, output)
for entry in task.accepted:
crawljob_file = pathscrub(entry['title'], filename=True)
real_output = os.path.join(output, crawljob_file) + '.crawljob'
if task.options.test:
logger.verbose('Would write output crawljob file to {}', real_output)
continue
logger.verbose('Writing output crawljob file to {}', real_output)
with open(real_output, 'w', encoding='utf-8') as f:
f.write('text="{0}"\n'.format(entry['url']))
f.write('deepAnalyseEnabled=true\n')
f.write('autoStart=true\nautoConfirm=true\n')
f.write('packageName={0}\n'.format(crawljob_file))
@event('plugin.register')
def register_plugin():
plugin.register(OutputCrawljob, plugin_name, api_ver=2)