testing on pcm

remotes/1693176582716663532/tmp_refs/heads/watchparty
Aevann1 2022-09-25 06:11:06 +02:00
parent 0aa9893576
commit 4212cfa0b2
3 changed files with 55 additions and 43 deletions

View File

@ -1,6 +1,6 @@
from files.helpers.const import SITE from files.helpers.const import SITE
if SITE == 'pcmemes.net' or True: if SITE == 'pcmemes.net':
from sqlalchemy import * from sqlalchemy import *
from files.__main__ import Base from files.__main__ import Base

View File

@ -31,10 +31,8 @@ def cron(every_5m, every_1h, every_1d, every_1mo):
lottery.check_if_end_lottery_task() lottery.check_if_end_lottery_task()
spin_roulette_wheel() spin_roulette_wheel()
offsitementions.offsite_mentions_task() offsitementions.offsite_mentions_task()
if SITE == 'pcmemes.net' or True: if SITE == 'pcmemes.net':
x = route_static.live_cached() route_static.live_cached()
cache.set('live', x[0])
cache.set('offline', x[1])
if every_1h: if every_1h:
awards.award_timers_bots_task() awards.award_timers_bots_task()

View File

@ -436,12 +436,44 @@ def donate(v):
return render_template(f'donate_{SITE_NAME}.html', v=v) return render_template(f'donate_{SITE_NAME}.html', v=v)
if SITE == 'pcmemes.net' or True: if SITE == 'pcmemes.net':
from files.classes.streamers import * from files.classes.streamers import *
live_regex = re.compile('playerOverlayVideoDetailsRenderer":\{"title":\{"simpleText":"(.*?)"\},"subtitle":\{"runs":\[\{"text":"(.*?)"\},\{"text":""\},\{"text":"(.*?)"\}', flags=re.A) live_regex = re.compile('playerOverlayVideoDetailsRenderer":\{"title":\{"simpleText":"(.*?)"\},"subtitle":\{"runs":\[\{"text":"(.*?)"\},\{"text":""\},\{"text":"(.*?)"\}', flags=re.A)
live_thumb_regex = re.compile('\{"thumbnail":\{"thumbnails":\[\{"url":"(.*?)"', flags=re.A) live_thumb_regex = re.compile('\{"thumbnail":\{"thumbnails":\[\{"url":"(.*?)"', flags=re.A)
offline_regex = re.compile('","title":"(.*?)".*?"width":48,"height":48\},\{"url":"(.*?)"', flags=re.A) offline_regex = re.compile('","title":"(.*?)".*?"width":48,"height":48\},\{"url":"(.*?)"', flags=re.A)
offline_details_regex = re.compile('simpleText":"Gestreamd: ([0-9]*?) ([a-z]*?) geleden"\},"viewCountText":\{"simpleText":"([0-9]*?) weergaven"', flags=re.A)
def process_streamer(id):
url = f'https://www.youtube.com/channel/{id}/live'
req = requests.get(url, cookies={'CONSENT': 'YES+1'}, timeout=5, proxies=proxies)
text = req.text
if '"videoDetails":{"videoId"' in text:
t = live_thumb_regex.search(text)
y = live_regex.search(text)
try:
return_val = (True, (id, req.url, t.group(1), y.group(2), y.group(1), int(y.group(3))))
except:
print(id, flush=True)
return_val = None
else:
t = offline_regex.search(text)
y = offline_details_regex.search(text)
days = y.group(0)
modifier = y.group(1)
if modifier == 'weken': modifier = 7
elif modifier == 'maand': modifier = 30
elif modifier == 'jaar': modifier = 365
days *= modifier
try:
return_val = (False, (id, req.url.rstrip('/live'), t.group(2), t.group(1), days, y.group(2)))
except:
print(id, flush=True)
return_val = None
return return_val
def live_cached(): def live_cached():
live = [] live = []
@ -449,24 +481,17 @@ if SITE == 'pcmemes.net' or True:
db = db_session() db = db_session()
streamers = [x[0] for x in db.query(Streamer.id).all()] streamers = [x[0] for x in db.query(Streamer.id).all()]
db.close() db.close()
for x in streamers: for id in streamers:
url = f'https://www.youtube.com/channel/{x}/live' processed = process_streamer(id)
req = requests.get(url, cookies={'CONSENT': 'YES+1'}, timeout=5, proxies=proxies) if processed:
text = req.text if processed[0]: live.append(processed[1])
if '"videoDetails":{"videoId"' in text: else: offline.append(processed[1])
t = live_thumb_regex.search(text)
y = live_regex.search(text)
try:
count = int(y.group(3))
live.append((x, req.url, t.group(1), y.group(2), y.group(1), count))
except:
print(x)
else:
y = offline_regex.search(text)
try: offline.append((x, req.url.rstrip('/live'), y.group(2), y.group(1)))
except: print(x)
live = sorted(live, key=lambda x: x[5], reverse=True) live = sorted(live, key=lambda x: x[5], reverse=True)
offline = sorted(offline, key=lambda x: x[4])
cache.set('live', live)
cache.set('offline', offline)
return live, offline return live, offline
@ -498,27 +523,16 @@ if SITE == 'pcmemes.net' or True:
if v.id != KIPPY_ID: if v.id != KIPPY_ID:
send_repeatable_notification(KIPPY_ID, f"@{v.username} has added a [new YouTube channel](https://www.youtube.com/channel/{streamer.id})") send_repeatable_notification(KIPPY_ID, f"@{v.username} has added a [new YouTube channel](https://www.youtube.com/channel/{streamer.id})")
url = f'https://www.youtube.com/channel/{id}/live' processed = process_streamer(id)
req = requests.get(url, cookies={'CONSENT': 'YES+1'}, timeout=5, proxies=proxies) if processed:
text = req.text if processed[0]: live.append(processed[1])
if '"videoDetails":{"videoId"' in text: else: offline.append(processed[1])
t = live_thumb_regex.search(text)
y = live_regex.search(text) live = sorted(live, key=lambda x: x[5], reverse=True)
try: offline = sorted(offline, key=lambda x: x[4])
count = int(y.group(3))
live.append((id, req.url, t.group(1), y.group(2), y.group(1), count)) cache.set('live', live)
cache.set('live', live) cache.set('offline', offline)
except:
print(id, flush=True)
else:
with open("files/assets/txt9.txt", "w", encoding='utf_8') as f:
f.write(text)
y = offline_regex.search(text)
try:
offline.append((id, req.url.rstrip('/live'), y.group(2), y.group(1)))
cache.set('offline', offline)
except:
print(id, flush=True)
return redirect('/live') return redirect('/live')