-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver_util.py
executable file
·129 lines (111 loc) · 4.71 KB
/
server_util.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
# -*- coding: utf-8 -*-
# python
import os, traceback, time, json
# third-party
import requests
from flask import Blueprint, request, send_file, redirect
# sjva 공용
from framework import app, path_data, check_api, py_urllib, SystemModelSetting
from framework.logger import get_logger
from framework.util import Util
from .plugin import P
logger = P.logger
from .site_util import SiteUtil
# 패키지
server_plugin_ddns = app.config['DEFINE']['METADATA_SERVER_URL']
try:
if SystemModelSetting.get('ddns') == server_plugin_ddns:
server_plugin_ddns = 'http://127.0.0.1:19999'
except:
pass
class MetadataServerUtil(object):
@classmethod
def get_metadata(cls, code):
try:
from framework import py_urllib
url = f"{app.config['DEFINE']['WEB_DIRECT_URL']}/meta/get_meta.php?"
url += py_urllib.urlencode({'type':'meta', 'code':code})
logger.warning(url)
data = requests.get(url).json()
if data['ret'] == 'success':
return data['data']
except Exception as exception:
#logger.debug('Exception:%s', exception)
#logger.debug(traceback.format_exc())
logger.error('metaserver connection fail.. get_metadata')
"""
@classmethod
def search_metadata(cls, keyword):
try:
from framework import py_urllib
url = '{server_plugin_ddns}/server/normal/metadata/search?keyword={keyword}'.format(server_plugin_ddns=server_plugin_ddns, keyword=keyword)
data = requests.get(url).json()
if data['ret'] == 'success':
return data['data']
except Exception as exception:
logger.error('metaserver connection fail.. search_metadata')
"""
@classmethod
def set_metadata(cls, code, data, keyword):
try:
from framework import py_urllib
url = '{server_plugin_ddns}/server/normal/metadata/set'.format(server_plugin_ddns=server_plugin_ddns)
param = {'code':code, 'data':json.dumps(data), 'user':SystemModelSetting.get('sjva_me_user_id'), 'keyword':keyword}
#logger.debug(param)
data = requests.post(url, data=param).json()
if data['ret'] == 'success':
logger.info('%s Data save success. Thanks!!!!', code)
except Exception as exception:
logger.error('metaserver connection fail.. set_metadata')
@classmethod
def set_metadata_jav_censored(cls, code, data, keyword):
try:
if data['thumb'] is None or (code.startswith('C') and len(data['thumb']) < 2) or (code.startswith('D') and len(data['thumb']) < 1):
return
for tmp in data['thumb']:
if tmp['value'] is None or tmp['value'].find('.discordapp.') == -1:
return
if requests.get(tmp['value']).status_code != 200:
return
if SiteUtil.is_include_hangul(data['plot']) == False:
return
"""
if data['fanart'] is not None:
for tmp in data['fanart']:
if tmp.find('.discordapp.') == -1:
return
"""
cls.set_metadata(code, data, keyword)
except Exception as exception:
logger.error('Exception:%s', exception)
logger.error(traceback.format_exc())
@classmethod
def set_metadata_jav_uncensored(cls, code, data, keyword):
try:
if data['thumb'] is None:
return
for tmp in data['thumb']:
if tmp['value'] is None or tmp['value'].find('.discordapp.') == -1:
return
if requests.get(tmp['value']).status_code != 200:
return
if SiteUtil.is_include_hangul(data['tagline']) == False:
return
if data['plot'] is not None and SiteUtil.is_include_hangul(data['plot']) == False:
return
cls.set_metadata(code, data, keyword)
logger.debug(f'set metadata uncensored complete, {code}')
except Exception as exception:
logger.error('Exception:%s', exception)
logger.error(traceback.format_exc())
@classmethod
def get_meta_extra(cls, code):
try:
from framework import py_urllib
url = f"{app.config['DEFINE']['WEB_DIRECT_URL']}/meta/get_meta.php?"
url += py_urllib.urlencode({'type':'extra', 'code':code})
data = requests.get(url).json()
if data['ret'] == 'success':
return data['data']
except Exception as exception:
logger.error('metaserver connection fail.. get_meta_extra')