-
Notifications
You must be signed in to change notification settings - Fork 10
/
logic_download.py
133 lines (111 loc) · 4.92 KB
/
logic_download.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
#########################################################
# python
import os, sys, traceback, re, json, threading, time, shutil
from datetime import datetime
# third-party
import requests
# third-party
from flask import request, render_template, jsonify, redirect
from sqlalchemy import or_, and_, func, not_, desc
import lxml.html
from lxml import etree as ET
# sjva 공용
from framework import db, scheduler, path_data, socketio, SystemModelSetting, app, celery
from framework.util import Util
from framework.common.util import headers, get_json_with_auth_session
from framework.common.plugin import LogicModuleBase, default_route_socketio
from tool_expand import ToolExpandFileProcess
from lib_wvtool import WVTool
# 패키지
from .plugin import P, d, logger, package_name, ModelSetting, download_dir, tmp_dir, proxy_dir, output_dir
#########################################################
from .queue_chrome_request import QueueChromeRequest
from .queue_download import QueueDownload
from .model import ModelWVDItem
class LogicDownload(LogicModuleBase):
db_default = {
'download_db_version' : '1',
'download_interval' : '30',
'download_auto_start' : 'False',
'download_test_send_url' : '',
'download_test_video_result_json' : '',
'download_queue_list' : '',
'downloadl_last_list_option' : '',
}
def __init__(self, P):
super(LogicDownload, self).__init__(P, 'list')
self.name = 'download'
self.queue_chrome_request = QueueChromeRequest(self)
self.queue_download = QueueDownload(self)
def process_menu(self, sub, req):
arg = P.ModelSetting.to_dict()
arg['sub'] = self.name
arg['version'] = P.plugin_info['version']
try:
return render_template('{package_name}_{module_name}_{sub}.html'.format(package_name=P.package_name, module_name=self.name, sub=sub), arg=arg)
except Exception as e:
P.logger.error('Exception:%s', e)
P.logger.error(traceback.format_exc())
return render_template('sample.html', title='%s - %s' % (P.package_name, sub))
def process_ajax(self, sub, req):
try:
ret = {'ret':'success'}
if sub == 'web_list':
return jsonify(ModelWVDItem.web_list(request))
elif sub == 'db_remove':
return jsonify(ModelWVDItem.delete_by_id(req.form['id']))
elif sub == 'request_url_add':
ret = self.queue_chrome_request.add_request_url(req.form['url'], req.form['memo'])
elif sub == 'command':
command = req.form['command']
if command == 'test_send_url':
url = req.form['url']
ModelSetting.set('download_test_send_url', url)
ret = self.queue_chrome_request.send_url(url)
elif command == 'test_video_result_json':
json_filepath = req.form['json_filepath']
ModelSetting.set('download_test_video_result_json', json_filepath)
self.queue_download.start_video_result(-1, json_filepath)
elif command == 'download_start':
self.download_start()
elif command == 'set_status':
logger.debug(req.form['status'])
logger.debug(req.form['db_id'])
db_item = ModelWVDItem.get_by_id(int(req.form['db_id']))
db_item.status = req.form['status']
db_item.save()
return jsonify(ret)
except Exception as e:
P.logger.error('Exception:%s', e)
P.logger.error(traceback.format_exc())
return jsonify({'ret':'exception', 'log':str(e)})
def process_normal(self, sub, req):
try:
ret = {'ret':'success'}
if sub == 'video_result':
data = req.json
self.queue_download.receive_data(data)
return jsonify(ret)
except Exception as e:
P.logger.error('Exception:%s', e)
P.logger.error(traceback.format_exc())
return jsonify({'ret':'exception', 'log':str(e)})
def plugin_load(self):
os.makedirs(tmp_dir, exist_ok=True)
os.makedirs(proxy_dir, exist_ok=True)
os.makedirs(output_dir, exist_ok=True)
def scheduler_function(self):
self.queue_chrome_request.enqueue()
self.queue_download.enqueue()
#########################################################
def queue_start(self):
"""
queue_list = ModelSetting.get_list('download_queue_list', '\n')
for item in queue_list:
logger.debug("URL : %s", item)
self.send_url(item)
"""
pass
def queue_stop(self):
pass