forked from zoexmh99/wvd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
site_tving.py
62 lines (54 loc) · 3.04 KB
/
site_tving.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
import os, sys, traceback, re, json, threading, time, shutil, subprocess, psutil
from datetime import datetime
from .site_base import SiteBase, d, logger, package_name, ModelSetting, Utility, P, webdriver, WebDriverWait, EC, By, Keys
class SiteTving(SiteBase):
name = 'tving'
name_on_filename = 'TV'
url_regex = request_url_regex = re.compile(r'tving\.com\/(vod|movie)\/player\/(?P<code>.*?)$')
def __init__(self, db_id, json_filepath):
super(SiteTving, self).__init__(db_id, json_filepath)
def prepare(self):
self.meta['season_number'] = 1
try:
for item in self.data['har']['log']['entries']:
if item['request']['method'] == 'GET' and item['request']['url'].startswith('https://api.tving.com/v2a/media/stream/info'):
res = self.get_response(item)
self.meta['source'] = res.json()
Utility.write_json(os.path.join(self.temp_dir, f'{self.code}.meta.json'), self.meta['source'])
break
self.meta['title'] = self.meta['source']['body']['content']['info']['vod_name']['ko']
frequency = self.meta['source']['body']['content'].get('frequency')
if frequency == None:
self.meta['content_type'] = 'movie'
else:
self.meta['content_type'] = 'show'
self.meta['episode_number'] = frequency
self.add_log("타입 : %s" % self.meta['content_type'])
if self.meta['content_type'] == 'show':
regex_list = [
'(?P<title>.*?)\s?시즌\s?(?P<season>\d+)',
'(?P<title>.*?)\s?(?P<episode>\d+)\s?화',
'(?P<title>.*?)\s?(?P<season>\d+)\s?기',
'(?P<title>.*?)\sSeason\s(?P<season>\d+)$',
]
for regex in regex_list:
match = re.match(regex, self.meta['title'])
if match:
self.meta['title'] = match.group('title')
if match.groupdict().get('season'):
self.meta['season_number'] = int(match.groupdict().get('season'))
break
log = f"제목: [{self.meta['title']}] 시즌:[{self.meta['season_number']}], 에피:[{self.meta['episode_number']}]"
logger.debug(log)
self.add_log(log)
except Exception as e:
P.logger.error('Exception:%s', e)
P.logger.error(traceback.format_exc())
@classmethod
def do_driver_action(cls, ins):
WebDriverWait(ins.dm.driver, 5).until(lambda driver: driver.find_element_by_class_name('cjp-quality')).find_element_by_tag_name('button').click()
WebDriverWait(ins.dm.driver, 5).until(
EC.element_to_be_clickable((By.XPATH, '//div[@class="cjp-quality-menu"]/div[1]'))
).click()
ins.stop_timestamp = time.time()
lic_url = 'https://cj.drmkeyserver.com/widevine_license'