forked from soju6jan/metadata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.py
executable file
·349 lines (318 loc) · 13.4 KB
/
plugin.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
import os
import time
from io import BytesIO
# third-party
import requests
from flask import Blueprint, Response, redirect, request, send_file, abort
from PIL import Image
# sjva 공용
from framework import app, check_api, path_data, py_urllib
from framework.logger import get_logger
from lib_metadata import SiteUtil, SiteNaverMovie
from tool_base import ToolUtil
from plugin import Logic, default_route, get_model_setting
# 패키지
#########################################################
class P:
package_name = __name__.split(".", maxsplit=1)[0]
logger = get_logger(package_name)
blueprint = Blueprint(
package_name,
package_name,
url_prefix=f"/{package_name}",
template_folder=os.path.join(os.path.dirname(__file__), "templates"),
)
menu = {
"main": [package_name, "메타데이터"],
"sub": [
["movie", "영화"],
["ktv", "국내TV"],
["ftv", "외국TV"],
["music_normal", "음악 일반"],
["jav_censored", "JavCensored"],
["jav_censored_ama", "JavCensored AMA"],
["jav_uncensored", "JavUnCensored"],
["jav_fc2", "JavFc2"],
["book", "책"],
["log", "로그"],
],
"category": "tool",
"sub2": {
"ktv": [
["setting", "설정"],
["test", "테스트"], # ['daum', 'Daum'], ['wavve', '웨이브'], ['tving', '티빙'],
],
"movie": [
["setting", "설정"],
[
"test",
"테스트",
], # ['naver', '네이버'], ['daum', 'Daum'], ['tmdb', 'TMDB'], ['watcha', '왓챠'], ['tmdb', 'TMDB'], ['wavve', '웨이브'], ['tving', '티빙'],
],
"ftv": [
["setting", "설정"],
["test", "테스트"],
],
"music_normal": [
["setting", "설정"],
["test", "테스트"],
],
"jav_censored": [
["setting", "설정"],
["dmm", "DMM"],
["mgs", "MGS"],
["javbus", "Javbus"],
],
"jav_censored_ama": [
["setting", "설정"],
["mgs", "MGS"],
["jav321", "Jav321"],
],
"jav_uncensored": [
["setting", "설정"],
["1pondo", "1Pondo"],
["10musume", "10Musume"],
["heyzo", "HEYZO"],
["carib", "Caribbeancom"],
],
"jav_fc2": [
["setting", "설정"],
["setting_site", "사이트별 설정"],
["test_all", "통합 테스트"],
],
"book": [
["naver", "네이버 책 검색 API"],
],
},
}
plugin_info = {
"version": "0.2.0.0p",
"name": package_name,
"category": "tool",
"icon": "",
"developer": "by275",
"description": "Metadata",
"home": "https://github.com/by275/" + package_name,
"more": "",
"dependency": [
{
"name": "lib_metadata",
"home": "https://github.com/by275/lib_metadata",
}
],
}
ModelSetting = get_model_setting(package_name, logger)
logic = None
module_list = None
home_module = "setting"
def initialize():
try:
app.config["SQLALCHEMY_BINDS"][P.package_name] = "sqlite:///" + os.path.join(
path_data, "db", f"{P.package_name}.db"
)
ToolUtil.save_dict(P.plugin_info, os.path.join(os.path.dirname(__file__), "info.json"))
from .logic_book import LogicBook
from .logic_ftv import LogicFtv
from .logic_jav_censored import LogicJavCensored
from .logic_jav_censored_ama import LogicJavCensoredAma
from .logic_jav_fc2 import LogicJavFc2
from .logic_jav_uncensored import LogicJavUncensored
from .logic_ktv import LogicKtv
from .logic_lyric import LogicLyric
from .logic_movie import LogicMovie
from .logic_music import LogicMusic
from .logic_music_normal import LogicMusicNormal
from .logic_ott_show import LogicOttShow
from .logic_videostation import LogicVideoStation
P.module_list = [
LogicKtv(P),
LogicJavCensored(P),
LogicJavCensoredAma(P),
LogicJavUncensored(P),
LogicJavFc2(P),
LogicOttShow(P),
LogicMovie(P),
LogicFtv(P),
LogicLyric(P),
LogicBook(P),
LogicVideoStation(P),
LogicMusic(P),
LogicMusicNormal(P),
]
P.logic = Logic(P)
default_route(P)
except Exception:
P.logger.exception("플러그인 초기 구성 중 예외:")
logger = P.logger
initialize()
#########################################################
# API - 외부
#########################################################
@P.blueprint.route("/api/<sub>", methods=["GET", "POST"])
@check_api
def baseapi(sub):
try:
if sub == "image":
# 2020-06-02 proxy 사용시 포스터처리
image_url = request.args.get("url")
logger.debug(image_url)
method = P.ModelSetting.get("javdb_landscape_poster")
if method == "0":
if FileProcess.Vars.proxies is None:
return redirect(image_url)
im = Image.open(requests.get(image_url, stream=True, proxies=FileProcess.Vars.proxies, timeout=30).raw)
filename = os.path.join(path_data, "tmp", "rotate.jpg")
im.save(filename)
return send_file(filename, mimetype="image/jpeg")
im = Image.open(requests.get(image_url, stream=True, proxies=FileProcess.Vars.proxies, timeout=30).raw)
width, height = im.size
logger.debug(width)
logger.debug(height)
if height > width * 1.5:
return redirect(image_url)
if method == "1":
if width > height:
im = im.rotate(-90, expand=True)
elif method == "2":
if width > height:
im = im.rotate(90, expand=True)
elif method == "3":
new_height = int(width * 1.5)
new_im = Image.new("RGB", (width, new_height))
new_im.paste(im, (0, int((new_height - height) / 2)))
im = new_im
filename = os.path.join(path_data, "tmp", "rotate.jpg")
im.save(filename)
return send_file(filename, mimetype="image/jpeg")
elif sub == "image_proxy":
image_url = py_urllib.unquote_plus(request.args.get("url"))
proxy_url = request.args.get("proxy_url")
if proxy_url is not None:
proxy_url = py_urllib.unquote_plus(proxy_url)
# image open
res = SiteUtil.get_response(image_url, proxy_url=proxy_url)
bytes_im = BytesIO(res.content)
im = Image.open(bytes_im)
imformat = im.format
mimetype = im.get_format_mimetype()
# apply crop - quality loss
crop_mode = request.args.get("crop_mode")
if crop_mode is not None:
crop_mode = py_urllib.unquote_plus(crop_mode)
im = SiteUtil.imcrop(im, position=crop_mode)
with BytesIO() as buf:
im.save(buf, format=imformat, quality=95)
return Response(buf.getvalue(), mimetype=mimetype)
bytes_im.seek(0)
return send_file(bytes_im, mimetype=mimetype)
elif sub == "discord_proxy":
image_url = py_urllib.unquote_plus(request.args.get("url"))
proxy_url = request.args.get("proxy_url")
if proxy_url is not None:
proxy_url = py_urllib.unquote_plus(proxy_url)
crop_mode = request.args.get("crop_mode")
if crop_mode is not None:
crop_mode = py_urllib.unquote_plus(crop_mode)
ret = SiteUtil.discord_proxy_image(image_url, proxy_url=proxy_url, crop_mode=crop_mode)
return redirect(ret)
elif sub == "video":
site = request.args.get("site")
param = request.args.get("param")
if site == "naver":
ret = SiteNaverMovie.get_video_url(param)
elif site == "youtube":
command = [
"youtube-dl",
"-f",
"best",
"-g",
"https://www.youtube.com/watch?v=%s" % request.args.get("param"),
]
from system.logic_command import SystemLogicCommand
ret = SystemLogicCommand.execute_command_return(command).strip()
elif site == "kakao":
url = "https://tv.kakao.com/katz/v2/ft/cliplink/{}/readyNplay?player=monet_html5&profile=HIGH&service=kakao_tv§ion=channel&fields=seekUrl,abrVideoLocationList&startPosition=0&tid=&dteType=PC&continuousPlay=false&contentType=&{}".format(
param, int(time.time())
)
data = requests.get(url, timeout=30).json()
# logger.debug(json.dumps(data, indent=4))
ret = data["videoLocation"]["url"]
logger.debug(ret)
return redirect(ret)
except Exception:
logger.exception("API 요청 처리 중 예외:")
abort(404)
return
@P.blueprint.route("/normal/<sub>", methods=["GET", "POST"])
def basenormal(sub):
try:
if sub == "image_process.jpg":
mode = request.args.get("mode")
if mode == "landscape_to_poster":
image_url = py_urllib.unquote_plus(request.args.get("url"))
im = Image.open(requests.get(image_url, stream=True, timeout=30).raw)
width, height = im.size
left = width / 1.895734597
top = 0
right = width
bottom = height
filename = os.path.join(path_data, "tmp", "proxy_%s.jpg" % str(time.time()))
poster = im.crop((left, top, right, bottom))
poster.save(filename)
return send_file(filename, mimetype="image/jpeg")
elif sub == "stream":
mode = request.args.get("mode")
param = request.args.get("param")
if mode == "naver":
ret = SiteNaverMovie.get_video_url(param)
elif mode == "youtube":
try:
import yt_dlp
except ImportError:
try:
os.system("{} install yt-dlp".format(app.config["config"]["pip"]))
except Exception:
pass
ydl_opts = {
"quiet": True,
}
ydl = yt_dlp.YoutubeDL(ydl_opts)
target_url = f"https://www.youtube.com/watch?v={request.args.get('param')}"
result = ydl.extract_info(target_url, download=False)
if "formats" in result:
for item in reversed(result["formats"]):
if (
item["ext"] == "mp4"
and item["acodec"].startswith("mp4a")
and item["vcodec"].startswith("avc1")
):
ret = item["url"]
break
elif mode == "kakao":
url = "https://tv.kakao.com/katz/v2/ft/cliplink/{}/readyNplay?player=monet_html5&profile=HIGH&service=kakao_tv§ion=channel&fields=seekUrl,abrVideoLocationList&startPosition=0&tid=&dteType=PC&continuousPlay=false&contentType=&{}".format(
param, int(time.time())
)
data = requests.get(url, timeout=30).json()
# logger.debug(json.dumps(data, indent=4))
ret = data["videoLocation"]["url"]
elif mode == "tving_movie":
from support.site.tving import SupportTving
data = SupportTving.ins.get_info(param, "stream50")
ret = data["url"]
elif mode == "tving":
from support.site.tving import SupportTving
data = SupportTving.ins.get_info(param, "stream50")
ret = data["url"]
elif mode == "wavve_movie":
import framework.wavve.api as Wavve
data = {"wavve_url": Wavve.streaming2("movie", param, "FHD", return_url=True)}
ret = data["wavve_url"]
elif mode == "wavve":
import framework.wavve.api as Wavve
data = Wavve.streaming("vod", param, "1080p", return_url=True)
ret = data
return redirect(ret)
except Exception:
logger.exception("API 요청 처리 중 예외:")
abort(404)
return