From 4212cfa0b281ace2e5ac7e26f05f2bc7fcfd3152 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 06:11:06 +0200 Subject: [PATCH 01/29] testing on pcm --- files/classes/streamers.py | 2 +- files/helpers/cron.py | 6 +-- files/routes/static.py | 90 ++++++++++++++++++++++---------------- 3 files changed, 55 insertions(+), 43 deletions(-) diff --git a/files/classes/streamers.py b/files/classes/streamers.py index a98ce13ad..575481785 100644 --- a/files/classes/streamers.py +++ b/files/classes/streamers.py @@ -1,6 +1,6 @@ from files.helpers.const import SITE -if SITE == 'pcmemes.net' or True: +if SITE == 'pcmemes.net': from sqlalchemy import * from files.__main__ import Base diff --git a/files/helpers/cron.py b/files/helpers/cron.py index b7f4265d4..b3636c563 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -31,10 +31,8 @@ def cron(every_5m, every_1h, every_1d, every_1mo): lottery.check_if_end_lottery_task() spin_roulette_wheel() offsitementions.offsite_mentions_task() - if SITE == 'pcmemes.net' or True: - x = route_static.live_cached() - cache.set('live', x[0]) - cache.set('offline', x[1]) + if SITE == 'pcmemes.net': + route_static.live_cached() if every_1h: awards.award_timers_bots_task() diff --git a/files/routes/static.py b/files/routes/static.py index 503a360cc..f34f84b56 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -436,12 +436,44 @@ def donate(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 * 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) 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(): live = [] @@ -449,24 +481,17 @@ if SITE == 'pcmemes.net' or True: db = db_session() streamers = [x[0] for x in db.query(Streamer.id).all()] db.close() - for x in streamers: - url = f'https://www.youtube.com/channel/{x}/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: - 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) + for id in streamers: + processed = process_streamer(id) + if processed: + if processed[0]: live.append(processed[1]) + else: offline.append(processed[1]) 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 @@ -498,27 +523,16 @@ if SITE == 'pcmemes.net' or True: 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})") - 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: - 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, 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) + processed = process_streamer(id) + if processed: + if processed[0]: live.append(processed[1]) + else: offline.append(processed[1]) + + 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 redirect('/live') From 230b71c19be88ba8794698cb2201a5b695fe3c12 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 06:22:33 +0200 Subject: [PATCH 02/29] same as last commit --- files/routes/static.py | 31 ++++++++++++++++++++++++------- files/templates/live.html | 6 +++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index f34f84b56..4ea274dbf 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -460,15 +460,32 @@ if SITE == 'pcmemes.net': 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 + quantity = y.group(0) + unit = y.group(1) + + if unit == 'minuten': + unit = 'minute' + modifier = 1 + if unit == 'uur': + unit = 'hour' + modifier = 60 + if unit == 'weken': + unit = 'week' + modifier = 10080 + elif unit == 'maand': + unit = 'month' + modifier = 43800 + elif unit == 'jaar': + unit = 'year' + modifier = 525600 + + minutes = quantity * modifier + + if quantity > 1: unit += 's' + actual = quantity + ' ' + unit try: - return_val = (False, (id, req.url.rstrip('/live'), t.group(2), t.group(1), days, y.group(2))) + return_val = (False, (id, req.url.rstrip('/live'), t.group(2), t.group(1), minutes, actual, y.group(2))) except: print(id, flush=True) return_val = None diff --git a/files/templates/live.html b/files/templates/live.html index 30fa68b48..5b9920a7d 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -74,12 +74,12 @@
- {% for id, link, thumb, name in offline %} + {% for id, link, thumb, name, minutes, actual, views in offline %} - - + + {% if v and v.admin_level > 1 %} - + {% if v and v.admin_level > 1 %}
{{name}} thumbnail {{name}}{{actual}} ago{{views}} views
From 351a7ca17bb7d637d06147652fe840958070b972 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 06:27:28 +0200 Subject: [PATCH 03/29] fix --- files/routes/static.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index 4ea274dbf..730166426 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -460,8 +460,8 @@ if SITE == 'pcmemes.net': t = offline_regex.search(text) y = offline_details_regex.search(text) - quantity = y.group(0) - unit = y.group(1) + quantity = y.group(1) + unit = y.group(2) if unit == 'minuten': unit = 'minute' @@ -479,13 +479,15 @@ if SITE == 'pcmemes.net': unit = 'year' modifier = 525600 + print(unit, flush=True) + minutes = quantity * modifier if quantity > 1: unit += 's' actual = quantity + ' ' + unit try: - return_val = (False, (id, req.url.rstrip('/live'), t.group(2), t.group(1), minutes, actual, y.group(2))) + return_val = (False, (id, req.url.rstrip('/live'), t.group(2), t.group(1), minutes, actual, y.group(3))) except: print(id, flush=True) return_val = None From 97b2e09b651983bd859e4f99fe096f9c24a431cc Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 06:31:59 +0200 Subject: [PATCH 04/29] fix --- files/routes/static.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index 730166426..a50173a02 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -460,7 +460,7 @@ if SITE == 'pcmemes.net': t = offline_regex.search(text) y = offline_details_regex.search(text) - quantity = y.group(1) + quantity = int(y.group(1)) unit = y.group(2) if unit == 'minuten': @@ -479,12 +479,10 @@ if SITE == 'pcmemes.net': unit = 'year' modifier = 525600 - print(unit, flush=True) - minutes = quantity * modifier - if quantity > 1: unit += 's' - actual = quantity + ' ' + unit + actual = f'{quantity} {unit}' + if quantity > 1: actual += 's' try: return_val = (False, (id, req.url.rstrip('/live'), t.group(2), t.group(1), minutes, actual, y.group(3))) @@ -514,6 +512,8 @@ if SITE == 'pcmemes.net': return live, offline + live_cached() + @app.get('/live') @app.get('/logged_out/live') @auth_desired_with_logingate From 015074c4ca1d114ed4c8afe264a9b5cbe9b1b9f3 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 06:33:55 +0200 Subject: [PATCH 05/29] the fuck --- files/routes/static.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/files/routes/static.py b/files/routes/static.py index a50173a02..f44971142 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -478,6 +478,8 @@ if SITE == 'pcmemes.net': elif unit == 'jaar': unit = 'year' modifier = 525600 + else: + print(unit, flush=True) minutes = quantity * modifier From 695fca5d35bc8dd63fa7fa5e18f2cec09ba7e9e4 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 06:35:56 +0200 Subject: [PATCH 06/29] fix --- files/routes/static.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index f44971142..c790d1148 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -463,16 +463,16 @@ if SITE == 'pcmemes.net': quantity = int(y.group(1)) unit = y.group(2) - if unit == 'minuten': + if unit.startswith('minu'): unit = 'minute' modifier = 1 if unit == 'uur': unit = 'hour' modifier = 60 - if unit == 'weken': + if unit.startswith('we'): unit = 'week' modifier = 10080 - elif unit == 'maand': + elif unit.startswith('maand'): unit = 'month' modifier = 43800 elif unit == 'jaar': From 78f0721bb0b730a71a9d90e542b537655869f011 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 06:37:16 +0200 Subject: [PATCH 07/29] fix --- files/routes/static.py | 50 +++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index c790d1148..7d1643330 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -460,31 +460,35 @@ if SITE == 'pcmemes.net': t = offline_regex.search(text) y = offline_details_regex.search(text) - quantity = int(y.group(1)) - unit = y.group(2) + if y: + quantity = int(y.group(1)) + unit = y.group(2) - if unit.startswith('minu'): - unit = 'minute' - modifier = 1 - if unit == 'uur': - unit = 'hour' - modifier = 60 - if unit.startswith('we'): - unit = 'week' - modifier = 10080 - elif unit.startswith('maand'): - unit = 'month' - modifier = 43800 - elif unit == 'jaar': - unit = 'year' - modifier = 525600 + if unit.startswith('minu'): + unit = 'minute' + modifier = 1 + if unit == 'uur': + unit = 'hour' + modifier = 60 + if unit.startswith('we'): + unit = 'week' + modifier = 10080 + elif unit.startswith('maand'): + unit = 'month' + modifier = 43800 + elif unit == 'jaar': + unit = 'year' + modifier = 525600 + else: + print(unit, flush=True) + + minutes = quantity * modifier + + actual = f'{quantity} {unit}' + if quantity > 1: actual += 's' else: - print(unit, flush=True) - - minutes = quantity * modifier - - actual = f'{quantity} {unit}' - if quantity > 1: actual += 's' + minutes = 0 + actual = '???' try: return_val = (False, (id, req.url.rstrip('/live'), t.group(2), t.group(1), minutes, actual, y.group(3))) From 5d30c3a632a056f829c60921b153d58a4e7a86e8 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 06:38:43 +0200 Subject: [PATCH 08/29] fix --- files/routes/static.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/files/routes/static.py b/files/routes/static.py index 7d1643330..15fbed388 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -461,6 +461,7 @@ if SITE == 'pcmemes.net': y = offline_details_regex.search(text) if y: + views = y.group(3) quantity = int(y.group(1)) unit = y.group(2) @@ -470,6 +471,9 @@ if SITE == 'pcmemes.net': if unit == 'uur': unit = 'hour' modifier = 60 + if unit.startswith('dag'): + unit = 'day' + modifier = 1440 if unit.startswith('we'): unit = 'week' modifier = 10080 @@ -489,9 +493,10 @@ if SITE == 'pcmemes.net': else: minutes = 0 actual = '???' + views = 0 try: - return_val = (False, (id, req.url.rstrip('/live'), t.group(2), t.group(1), minutes, actual, y.group(3))) + return_val = (False, (id, req.url.rstrip('/live'), t.group(2), t.group(1), minutes, actual, views)) except: print(id, flush=True) return_val = None From 2b0a798fec5bab99950cd54512cc2a5d02df1b5d Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 06:40:19 +0200 Subject: [PATCH 09/29] fix --- files/routes/static.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index 15fbed388..9ac9f9f65 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -523,8 +523,6 @@ if SITE == 'pcmemes.net': return live, offline - live_cached() - @app.get('/live') @app.get('/logged_out/live') @auth_desired_with_logingate From e9e8b5cc5a02c6dc2d82646f3ac0cc5daee3edb5 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 06:45:22 +0200 Subject: [PATCH 10/29] fix grammar (i think) --- files/templates/settings_filters.html | 2 +- files/templates/settings_profile.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/files/templates/settings_filters.html b/files/templates/settings_filters.html index 87c45de69..1338c5e55 100644 --- a/files/templates/settings_filters.html +++ b/files/templates/settings_filters.html @@ -138,7 +138,7 @@ - Enable if you would like to automatically open links to other pages in the site in new tabs. + Enable if you would like to automatically open links to other pages on the site in new tabs. diff --git a/files/templates/settings_profile.html b/files/templates/settings_profile.html index 78a432afc..986b7598b 100644 --- a/files/templates/settings_profile.html +++ b/files/templates/settings_profile.html @@ -773,7 +773,7 @@ - Have a spider friend accompany you during your journey in the site. + Have a spider friend accompany you during your journey on the site. From 63a7183f7e76f991a5d77a1ab6b2d32afb5e5017 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 06:53:53 +0200 Subject: [PATCH 11/29] fix /live regex --- files/routes/static.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index 9ac9f9f65..fe71b9be7 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -442,7 +442,7 @@ if SITE == 'pcmemes.net': 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) 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) + 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' @@ -461,7 +461,7 @@ if SITE == 'pcmemes.net': y = offline_details_regex.search(text) if y: - views = y.group(3) + views = y.group(3).replace('.', ',') quantity = int(y.group(1)) unit = y.group(2) From fc2758df50d8bc488fc5b32ba61f91a623610b49 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 07:24:59 +0200 Subject: [PATCH 12/29] fix --- files/routes/static.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index fe71b9be7..1607566c2 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -444,18 +444,25 @@ if SITE == 'pcmemes.net': 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' + def process_streamer(id, live='live'): + 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 + count = y.group(3) + if 'wacht' in count: + return process_streamer(id, '') + + count = int(count) + + t = live_thumb_regex.search(text) + + thumb = t.group(1) + name = y.group(2) + title = y.group(1) + + return (True, (id, req.url, thumb, name, title, count)) else: t = offline_regex.search(text) y = offline_details_regex.search(text) @@ -495,12 +502,10 @@ if SITE == 'pcmemes.net': actual = '???' views = 0 - try: - return_val = (False, (id, req.url.rstrip('/live'), t.group(2), t.group(1), minutes, actual, views)) - except: - print(id, flush=True) - return_val = None - return return_val + thumb = t.group(2) + name = t.group(1) + + return (False, (id, req.url.rstrip('/live'), thumb, name, minutes, actual, views)) def live_cached(): From 92bdd678840b3adec0442bb47e1096487fc23502 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 07:31:55 +0200 Subject: [PATCH 13/29] debug --- files/routes/static.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index 1607566c2..04b3a4320 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -490,8 +490,6 @@ if SITE == 'pcmemes.net': elif unit == 'jaar': unit = 'year' modifier = 525600 - else: - print(unit, flush=True) minutes = quantity * modifier @@ -502,6 +500,7 @@ if SITE == 'pcmemes.net': actual = '???' views = 0 + print(req.url, flush=True) thumb = t.group(2) name = t.group(1) From 4ebd8fb552f2fda30eef82d39d1c344fbfd3ace3 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 07:42:29 +0200 Subject: [PATCH 14/29] limit adding channels to kip --- files/routes/static.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/files/routes/static.py b/files/routes/static.py index 04b3a4320..d1bd790cf 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -539,6 +539,9 @@ if SITE == 'pcmemes.net': @app.post('/live/add') @admin_level_required(2) def live_add(v): + if v.id != KIPPY_ID: + return {"error": 'Only Kippy can add channels!'}, 403 + id = request.values.get('id').strip() live = cache.get('live') or [] From f8fccd34db3cbdbbf24f7fe410320a6e7fff7b74 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 07:43:44 +0200 Subject: [PATCH 15/29] allow me to add channels --- files/routes/static.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/static.py b/files/routes/static.py index d1bd790cf..f2b4a45de 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -539,7 +539,7 @@ if SITE == 'pcmemes.net': @app.post('/live/add') @admin_level_required(2) def live_add(v): - if v.id != KIPPY_ID: + if v.id not in (AEVANN_ID, KIPPY_ID): return {"error": 'Only Kippy can add channels!'}, 403 id = request.values.get('id').strip() From 13a3d5c27e9012c50a9be6b114acc8a1cd8906b1 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 07:45:02 +0200 Subject: [PATCH 16/29] fix --- files/routes/static.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index f2b4a45de..042e50cb6 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -454,7 +454,7 @@ if SITE == 'pcmemes.net': if 'wacht' in count: return process_streamer(id, '') - count = int(count) + count = int(count.replace('.', '')) t = live_thumb_regex.search(text) @@ -468,7 +468,7 @@ if SITE == 'pcmemes.net': y = offline_details_regex.search(text) if y: - views = y.group(3).replace('.', ',') + views = y.group(3).replace('.', '') quantity = int(y.group(1)) unit = y.group(2) From 8d6937e237b5afac9b1c2e0030dead839fd06c81 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 07:46:02 +0200 Subject: [PATCH 17/29] add obese --- files/routes/static.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/static.py b/files/routes/static.py index 042e50cb6..e0022723a 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -539,7 +539,7 @@ if SITE == 'pcmemes.net': @app.post('/live/add') @admin_level_required(2) def live_add(v): - if v.id not in (AEVANN_ID, KIPPY_ID): + if v.id not in (AEVANN_ID, KIPPY_ID, 1550): return {"error": 'Only Kippy can add channels!'}, 403 id = request.values.get('id').strip() From 164b583e7c46cffb8560542dd453a489e00015e4 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 08:00:02 +0200 Subject: [PATCH 18/29] added "watching" in /live --- files/templates/live.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/templates/live.html b/files/templates/live.html index 5b9920a7d..3cdd56c29 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -53,7 +53,7 @@
{{name}} thumbnail {{name}} {{title}}{{viewers}}{{viewers}} watching From c79067f7f13fb58c562cd8ac9c786bfe6582fa8e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 08:14:21 +0200 Subject: [PATCH 19/29] make it possible to add channels by name --- files/routes/static.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/files/routes/static.py b/files/routes/static.py index e0022723a..322c31598 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -544,6 +544,10 @@ if SITE == 'pcmemes.net': id = request.values.get('id').strip() + if not id.startswith('UC'): + req = requests.get(f'https://www.googleapis.com/youtube/v3/channels?key={YOUTUBE_KEY}&forUsername={id}&part=id', timeout=5, proxies=proxies).json() + id = req['items']['id'] + live = cache.get('live') or [] offline = cache.get('offline') or [] From 10d06b7ba9196667528eb63b9cb490738399ea57 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 08:15:17 +0200 Subject: [PATCH 20/29] same as last commit --- files/templates/live.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/files/templates/live.html b/files/templates/live.html index 3cdd56c29..3f1709549 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -99,10 +99,9 @@ {% if v and v.admin_level > 1 %} - + -

you can get the channel id using this site https://streamweasels.com/tools/youtube-channel-id-and-user-id-convertor

{% endif %} {% endblock %} \ No newline at end of file From 03f9a69a0df0c5910a7fabac588c2792161b55f5 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 08:15:30 +0200 Subject: [PATCH 21/29] same as last commit --- files/templates/live.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/templates/live.html b/files/templates/live.html index 3f1709549..1a6c3e075 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -99,7 +99,7 @@ {% if v and v.admin_level > 1 %}
- +
{% endif %} From 10d09f076cca7f4160d19341a7bfe13d8e0d5683 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 08:18:03 +0200 Subject: [PATCH 22/29] fix --- files/routes/static.py | 1 + files/templates/live.html | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/files/routes/static.py b/files/routes/static.py index 322c31598..c6bc1bb83 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -546,6 +546,7 @@ if SITE == 'pcmemes.net': if not id.startswith('UC'): req = requests.get(f'https://www.googleapis.com/youtube/v3/channels?key={YOUTUBE_KEY}&forUsername={id}&part=id', timeout=5, proxies=proxies).json() + print(req, flush=True) id = req['items']['id'] live = cache.get('live') or [] diff --git a/files/templates/live.html b/files/templates/live.html index 1a6c3e075..d529f3708 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -104,4 +104,8 @@ {% endif %} +
+
+
+
{% endblock %} \ No newline at end of file From 9d9783fe0eebb0263312d8e48b395ea710c2e4f9 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 08:27:58 +0200 Subject: [PATCH 23/29] fix --- files/routes/static.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index c6bc1bb83..8c003ab12 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -439,6 +439,7 @@ def donate(v): if SITE == 'pcmemes.net': from files.classes.streamers import * + id_regex = re.compile('"externalId":"([^"]*?)"', 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) offline_regex = re.compile('","title":"(.*?)".*?"width":48,"height":48\},\{"url":"(.*?)"', flags=re.A) @@ -491,6 +492,7 @@ if SITE == 'pcmemes.net': unit = 'year' modifier = 525600 + print(unit, flush=True) minutes = quantity * modifier actual = f'{quantity} {unit}' @@ -545,9 +547,9 @@ if SITE == 'pcmemes.net': id = request.values.get('id').strip() if not id.startswith('UC'): - req = requests.get(f'https://www.googleapis.com/youtube/v3/channels?key={YOUTUBE_KEY}&forUsername={id}&part=id', timeout=5, proxies=proxies).json() - print(req, flush=True) - id = req['items']['id'] + text = requests.get(f'https://www.youtube.com/c/{id}', timeout=5, proxies=proxies).text + try: id = id_regex.search(text).group(1) + except: return render_template('live.html', v=v, live=live, offline=offline, error="Invalid ID") live = cache.get('live') or [] offline = cache.get('offline') or [] From a28a4664c2f00755102c0813e9b3a21e1f3c03bd Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 08:30:49 +0200 Subject: [PATCH 24/29] huh? --- files/routes/static.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index 8c003ab12..72f2b6eea 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -548,14 +548,16 @@ if SITE == 'pcmemes.net': if not id.startswith('UC'): text = requests.get(f'https://www.youtube.com/c/{id}', timeout=5, proxies=proxies).text + with open('files/assets/t3.txt', 'w', encoding='utf-8') as f: + f.write(text) try: id = id_regex.search(text).group(1) - except: return render_template('live.html', v=v, live=live, offline=offline, error="Invalid ID") + except: return {"error": "Invalid ID"} live = cache.get('live') or [] offline = cache.get('offline') or [] if not id or len(id) != 24: - return render_template('live.html', v=v, live=live, offline=offline, error="Invalid ID") + return {"error": "Invalid ID"} existing = g.db.get(Streamer, id) if not existing: From 8a85c2413cfd31bafe02cf2ddc2ca6538c907adf Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 08:31:46 +0200 Subject: [PATCH 25/29] add consent --- files/routes/static.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index 72f2b6eea..e1d15bb9d 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -547,9 +547,7 @@ if SITE == 'pcmemes.net': id = request.values.get('id').strip() if not id.startswith('UC'): - text = requests.get(f'https://www.youtube.com/c/{id}', timeout=5, proxies=proxies).text - with open('files/assets/t3.txt', 'w', encoding='utf-8') as f: - f.write(text) + text = requests.get(f'https://www.youtube.com/c/{id}', cookies={'CONSENT': 'YES+1'}, timeout=5, proxies=proxies).text try: id = id_regex.search(text).group(1) except: return {"error": "Invalid ID"} From 5a97a6f6e64eb2fce839100c7f811b3fc0e35222 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 08:45:19 +0200 Subject: [PATCH 26/29] allow pcm /live to enter channel link --- files/routes/static.py | 8 +++++--- files/templates/live.html | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index e1d15bb9d..d7dfcac7a 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -544,10 +544,12 @@ if SITE == 'pcmemes.net': if v.id not in (AEVANN_ID, KIPPY_ID, 1550): return {"error": 'Only Kippy can add channels!'}, 403 - id = request.values.get('id').strip() + link = request.values.get('link').strip() - if not id.startswith('UC'): - text = requests.get(f'https://www.youtube.com/c/{id}', cookies={'CONSENT': 'YES+1'}, timeout=5, proxies=proxies).text + if 'youtube.com/channel/' in link: + id = link.split('youtube.com/channel/')[1].rstrip('/') + else: + text = requests.get(link, cookies={'CONSENT': 'YES+1'}, timeout=5, proxies=proxies).text try: id = id_regex.search(text).group(1) except: return {"error": "Invalid ID"} diff --git a/files/templates/live.html b/files/templates/live.html index d529f3708..d21108799 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -99,7 +99,7 @@ {% if v and v.admin_level > 1 %}
- +
{% endif %} From 8269b0dc0f2e06046c2f55e84842009e2878a28c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 09:09:48 +0200 Subject: [PATCH 27/29] make it look better --- files/templates/live.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/templates/live.html b/files/templates/live.html index d21108799..7d0fd19a8 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -99,8 +99,8 @@ {% if v and v.admin_level > 1 %}
- - + +
{% endif %} From 3339baee54eabeede0244920c5b1b3ad73db2ce7 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 13:28:53 +0200 Subject: [PATCH 28/29] fixing /live --- files/routes/static.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/files/routes/static.py b/files/routes/static.py index d7dfcac7a..bf09bfbc4 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -492,7 +492,6 @@ if SITE == 'pcmemes.net': unit = 'year' modifier = 525600 - print(unit, flush=True) minutes = quantity * modifier actual = f'{quantity} {unit}' @@ -524,10 +523,9 @@ if SITE == 'pcmemes.net': 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) + if live: cache.set('live', live) + if offline: cache.set('offline', offline) - return live, offline @app.get('/live') @app.get('/logged_out/live') @@ -575,8 +573,8 @@ if SITE == 'pcmemes.net': 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) + if live: cache.set('live', live) + if offline: cache.set('offline', offline) return redirect('/live') @@ -597,7 +595,7 @@ if SITE == 'pcmemes.net': 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) + if live: cache.set('live', live) + if offline: cache.set('offline', offline) return redirect('/live') \ No newline at end of file From a2f578c7b71f839b9d6f49625bf3f107acc05c30 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Sep 2022 13:30:22 +0200 Subject: [PATCH 29/29] fix exploit --- files/routes/front.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/front.py b/files/routes/front.py index fc22ce3fa..d3d540c09 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -118,7 +118,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false" if sort == 'hot': ti = int(time.time()) + 3600 if SITE_NAME == 'rDrama': - posts = posts.order_by(-1000000*(Submission.realupvotes + 1 + Submission.comment_count/5 + func.least(50, (func.length(Submission.body_html)-func.length(func.replace(Submission.body_html,'