-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmod_main.py
More file actions
165 lines (153 loc) · 7.68 KB
/
mod_main.py
File metadata and controls
165 lines (153 loc) · 7.68 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
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
from flask import render_template, jsonify
from plugin import PluginModuleBase
from tool import ToolUtil
from .setup import P
from support_site import SiteUtil
from .yaml_utils import YAMLUTILS
import re, os, traceback
import requests
logger = P.logger
DEFINE_DEV = False
if os.path.exists(os.path.join(os.path.dirname(__file__), 'get_code.py')):
DEFINE_DEV = True
try:
if DEFINE_DEV:
from .get_code import OTTCODE
else:
from support import SupportSC
OTTCODE = SupportSC.load_module_P(P, 'get_code').OTTCODE
except Exception as e:
P.logger.error(f'Exception:{str(e)}')
P.logger.error(traceback.format_exc())
name = 'main'
class ModuleMain(PluginModuleBase):
db_default = {
f'{name}_db_version' : '1',
f'ftv_first_order' : 'WAVVE, TVING, COUPANG, NF, DSNP, AMZN, ATVP',
f'is_primary' : 'false',
f'match_score' : '95',
f'extra_season' : 'True',
f'ep_thum' : 'false',
f'split_season' : '1',
f'delete_title' : 'True',
f'manual_target' : '',
f'use_proxy' : 'False',
f'proxy_url' : '',
f'chrome_url': '',
}
def __init__(self, P):
super(ModuleMain, self).__init__(P, name=name, first_menu='main')
def process_menu(self, sub, req):
arg = P.ModelSetting.to_dict()
arg["package_name"] = P.package_name
arg["module_name"] = self.name
if sub == "setting":
return render_template(f"{P.package_name}_{self.name}_{sub}.html", arg=arg)
return render_template(f"{P.package_name}_{self.name}.html", arg=arg, sub=sub)
def convert_title_format(self, original_title):
# 정규 표현식을 사용하여 제목과 연도를 추출
match = re.match(r'(.*) \((\d{4})\)', original_title)
if match:
title = match.group(1)
year = match.group(2)
return f"{title}|{year}"
else:
return None
def disney_redirect(self, code):
headers = {
"sec-ch-ua-platform": "\"Windows\"",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
"sec-ch-ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
"Content-Type": "text/plain;charset=UTF-8",
"Origin": "https://www.disneyplus.com",
"Referer": "https://www.disneyplus.com/",
}
url = 'https://www.disneyplus.com/ko-kr/browse/entity-' + code
response = requests.get(url, headers=headers, allow_redirects=True)
code = re.search(r'disneyplus\.com(\/ko-kr)?\/series\/.*?\/(?P<code>[^?=&]+)', response.url).group('code')
return code
def process_command(self, command, arg1, arg2, arg3, req):
self.code = ''
arg1 = arg1.strip()
if command == 'search_keyword':
keyword = arg1.split('|')
if len(keyword) == 1:
ottcode = OTTCODE(keyword[0].strip())
ottcode_list = ottcode.get_ott_code()
user_order = P.ModelSetting.get_list('ftv_first_order', ',')
self.code = YAMLUTILS.code_sort(user_order, ottcode_list)
elif len(keyword) == 2:
ottcode = OTTCODE(keyword[0].strip(), keyword[1].strip())
ottcode_list = ottcode.get_ott_code()
user_order = P.ModelSetting.get_list('ftv_first_order', ',')
self.code = YAMLUTILS.code_sort(user_order, ottcode_list)
else:
return jsonify({"msg":"검색어 실패", "ret":"fail"})
elif command == 'auto_target':
source = arg1
source_list = os.listdir(source)
for f in source_list:
#if f in ['가', '나', '다', '라','마','바']:
char = os.path.join(source, f)
if os.path.isdir(char):
char_list = os.listdir(char)
for t in char_list:
try:
target = os.path.join(char,t)
if os.path.isdir(target) and not os.path.isfile(os.path.join(target, "show.yaml")):
folder = os.path.basename(target)
keyword = self.convert_title_format(folder)
keyword = keyword.split('|')
if keyword:
ottcode = OTTCODE(keyword[0].strip(), keyword[1].strip())
ottcode_list = ottcode.get_ott_code()
user_order = P.ModelSetting.get_list('ftv_first_order', ',')
self.code = YAMLUTILS.code_sort(user_order, ottcode_list)
if self.code:
show_data = YAMLUTILS.get_data(self.code)
if SiteUtil.is_include_hangul(show_data['seasons'][-1]['episodes'][-1]['title']) or SiteUtil.is_include_hangul(show_data['seasons'][-1]['episodes'][-1]['summary']) :
YAMLUTILS.make_yaml(show_data, target)
else:
continue
except:
print("오류발생:", target)
continue
elif command == 'wavve_code':
self.code = 'KW'+arg1
elif command == 'tving_code':
self.code = 'KV'+arg1
elif command == 'cpang_code':
self.code = 'KC'+arg1
elif command == 'nf_code':
self.code = 'FN'+arg1
elif command == 'dsnp_code':
if len(arg1) > 20 and '-' in arg1:
arg1 = self.disney_redirect(arg1)
self.code = 'FD'+arg1
elif command == 'amzn_code':
self.code = 'FP'+arg1
elif command == 'atvp_code':
self.code = 'FA'+arg1
elif command == 'ebskids_code':
self.code = 'KE'+arg1
if self.code != '' and self.code != None :
site = self.code[:2]
site_name_dict = {
'KW' : '웨이브', 'KV' : '티빙', 'KC' : '쿠팡 플레이', 'FN' : '넷플릭스', 'FD' : '디즈니 플러스', 'FP' : '프라임 비디오', 'FA' : '애플TV', 'KE' : 'EBS',
}
show_data = YAMLUTILS.get_data(self.code)
if arg2 == 'test':
return jsonify({'ret':'success', 'json': show_data})
elif show_data !=[]:
if SiteUtil.is_include_hangul(show_data['seasons'][-1]['episodes'][-1]['title']) or SiteUtil.is_include_hangul(show_data['seasons'][-1]['episodes'][-1]['summary']) :
if P.ModelSetting.get_bool('is_primary'):
self.tmdb_code = 'FT'+str(ottcode.tmdb_search())
show_data = YAMLUTILS.tmdb_data(self.tmdb_code, show_data)
YAMLUTILS.make_yaml(show_data)
return jsonify({"msg":f"{site_name_dict[site]} 코드 실행", "ret":"success"})
else:
return jsonify({"msg":f"{site_name_dict[site]} 한글 메타데이터 아님", "ret":"fail"})
else:
return jsonify({"msg":"검색 실패", "ret":"fail"})
else:
return jsonify({"msg":"검색 실패", "ret":"fail"})