make addition and removal of channels happen instantly (testing in devrama)

master
Aevann1 2022-09-25 05:08:44 +02:00
parent 4a0c0db55d
commit f4b41f0049
2 changed files with 45 additions and 12 deletions

View File

@ -31,8 +31,10 @@ 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_NAME == 'PCM': if SITE == 'pcmemes.net' or True:
cache.set('live_cached', route_static.live_cached()) x = 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,7 +436,7 @@ 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': if SITE == 'pcmemes.net' or True:
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)
@ -460,7 +460,7 @@ if SITE == 'pcmemes.net':
count = int(y.group(3)) count = int(y.group(3))
live.append((x, req.url, t.group(1), y.group(2), y.group(1), count)) live.append((x, req.url, t.group(1), y.group(2), y.group(1), count))
except: except:
offline.append((x, req.url.rstrip('/live'), t.group(1), y.group(2))) print(x)
else: else:
y = offline_regex.search(txt) y = offline_regex.search(txt)
try: offline.append((x, req.url.rstrip('/live'), y.group(2), y.group(1))) try: offline.append((x, req.url.rstrip('/live'), y.group(2), y.group(1)))
@ -473,20 +473,22 @@ if SITE == 'pcmemes.net':
@app.get('/live') @app.get('/live')
@app.get('/logged_out/live') @app.get('/logged_out/live')
@auth_desired_with_logingate @auth_desired_with_logingate
def live(v): def live_list(v):
live_cached = cache.get('live_cached') or [[],[]] live = cache.get('live') or []
offline = cache.get('offline') or []
return render_template('live.html', v=v, live=live_cached[0], offline=live_cached[1]) return render_template('live.html', v=v, live=live, offline=offline)
@app.post('/live/add') @app.post('/live/add')
@admin_level_required(2) @admin_level_required(2)
def live_add(v): def live_add(v):
id = request.values.get('id').strip() id = request.values.get('id').strip()
live_cached = cache.get('live_cached') or [[],[]] live = cache.get('live') or []
offline = cache.get('offline') or []
if not id or len(id) != 24: if not id or len(id) != 24:
return render_template('live.html', v=v, live=live_cached[0], offline=live_cached[1], error="Invalid ID") return render_template('live.html', v=v, live=live, offline=offline, error="Invalid ID")
existing = g.db.get(Streamer, id) existing = g.db.get(Streamer, id)
if not existing: if not existing:
@ -496,7 +498,28 @@ if SITE == 'pcmemes.net':
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})")
return render_template('live.html', v=v, live=live_cached[0], offline=live_cached[1], msg="Channel added successfuly!") url = f'https://www.youtube.com/channel/{id}/live'
req = requests.get(url, cookies={'CONSENT': 'YES+1'}, proxies=proxies)
txt = req.text
if '"videoDetails":{"videoId"' in txt:
t = live_thumb_regex.search(txt)
y = live_regex.search(txt)
try:
count = int(y.group(3))
live.append((id, req.url, t.group(1), y.group(2), y.group(1), count))
cache.set('live', live)
except:
print(id)
else:
y = offline_regex.search(txt)
try:
offline.append((id, req.url.rstrip('/live'), y.group(2), y.group(1)))
cache.set('offline', offline)
except:
print(id)
return render_template('live.html', v=v, live=live, offline=offline, msg="Channel added successfuly!")
@app.post('/live/remove') @app.post('/live/remove')
@admin_level_required(2) @admin_level_required(2)
@ -509,5 +532,13 @@ if SITE == 'pcmemes.net':
send_repeatable_notification(KIPPY_ID, f"@{v.username} has removed a [YouTube channel](https://www.youtube.com/channel/{streamer.id})") send_repeatable_notification(KIPPY_ID, f"@{v.username} has removed a [YouTube channel](https://www.youtube.com/channel/{streamer.id})")
g.db.delete(streamer) g.db.delete(streamer)
live_cached = cache.get('live_cached') or [[],[]] live = cache.get('live') or []
return render_template('live.html', v=v, live=live_cached[0], offline=live_cached[1], msg="Channel removed successfuly!") offline = cache.get('offline') or []
live = [x for x in live if x[0] != id]
offline = [x for x in offline if x[0] != id]
cache.set('live', live)
cache.set('offline', offline)
return render_template('live.html', v=v, live=live, offline=offline, msg="Channel removed successfuly!")