forked from 8ei/offcloud2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic_base.py
More file actions
88 lines (75 loc) · 2.81 KB
/
logic_base.py
File metadata and controls
88 lines (75 loc) · 2.81 KB
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
# -*- coding: utf-8 -*-
#########################################################
# python
import os
import traceback
import time
import threading
# third-party
# sjva 공용
from framework import db, scheduler, path_app_root
from framework.job import Job
from framework.util import Util
from .rss_nyaa import RssUtil
# 패키지
from .plugin import logger, package_name
from .model import ModelSetting, ModelOffcloud2Account, ModelOffcloud2Job, ModelOffcloud2Item, ModelOffcloud2Cache
from .offcloud_api import Offcloud
#########################################################
class LogicBase(object):
@staticmethod
def hash(req):
try:
apikey = ModelSetting.get('apikey')
cache_hash = req.form['hash'].strip().lower()
if cache_hash.startswith('magnet'):
cache_hash = cache_hash[20:60]
cached_list = Offcloud.get_cache_list(apikey, [cache_hash])
if len(cached_list) == 1:
if cached_list[0] == cache_hash:
return "true"
return "false"
except Exception as e:
logger.error('Exception:%s', e)
logger.error(traceback.format_exc())
return "fail"
@staticmethod
def request_download(req):
try:
apikey = ModelSetting.get('apikey')
h = req.form['hash'].strip().lower()
if len(h) == 40:
h = 'magnet:?xt=urn:btih:' + h
username = req.form['default_username']
entity = ModelOffcloud2Account.get(username)
if entity is not None:
remoteOptionId = entity.option_id
else:
return 'not exist username'
folder_id = req.form['folder_id']
ret = Offcloud.add_remote_by_magnet(apikey, h, remoteOptionId, folder_id)
return ret
except Exception as e:
logger.debug('Exception:%s', e)
logger.debug(traceback.format_exc())
return str(e)
@staticmethod
def add_remote_default_setting(req):
try:
apikey = ModelSetting.get('apikey')
h = req.form['hash'].strip().lower()
if len(h) == 40:
h = 'magnet:?xt=urn:btih:' + h
username = ModelSetting.get('default_username')
entity = ModelOffcloud2Account.get(username)
if entity is not None:
remoteOptionId = entity.option_id
else:
return 'not exist username'
folder_id = ModelSetting.get('default_folder_id')
ret = Offcloud.add_remote_by_magnet(apikey, h, remoteOptionId, folder_id)
return ret
except Exception as e:
logger.debug('Exception:%s', e)
logger.debug(traceback.format_exc())
return str(e)