From d55438afad40490417b9302304f6a308d2ff5f8f Mon Sep 17 00:00:00 2001 From: Aevann1 <59999695+Aevann1@users.noreply.github.com> Date: Thu, 22 Sep 2022 04:17:02 +0200 Subject: [PATCH 01/17] Live (#364) * test on devrama * fix prev commit * fix prev commit * try some shit * try some shit * try some shit * fix * make it easier to change notif colors with custom css * de * t * fgddfg * fds * fix * fds * dfs * pain * sdfsdf * df * xcv * fd * vxc * xcv * c * fgdfgd * sdf * fsd * fds * sfd * fdsf * fd * fds * fds * fsd * fds * fds * fds * fds * fsd * fds * df * fds * dfs * fd * fsd * fsd * dfs * sdf * fsd * fsd * df * dfs * fd * fsd * dfs * sdf * sdf * sdf * fsd * fds * sfd * sdf * fds * dfs * df * sdf * sdf * /live --- files/routes/static.py | 57 ++++++++++++++++++++++++++++++++++++++- files/templates/live.html | 44 ++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 files/templates/live.html diff --git a/files/routes/static.py b/files/routes/static.py index 6f79af7aa..651548383 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -433,4 +433,59 @@ if not os.path.exists(f'files/templates/donate_{SITE_NAME}.html'): @app.get('/donate') @auth_required def donate(v): - return render_template(f'donate_{SITE_NAME}.html', v=v) \ No newline at end of file + return render_template(f'donate_{SITE_NAME}.html', v=v) + + +if SITE_NAME == 'PCM': + streamers = ( + 'UCJrqlqe8DBZsfdMu7gGrVRA', + 'UCDDrY00FPYwLp9VqRhWiDgg', + 'UCdBzv8yzRgvnxV1M95qOsNA', + 'UCvRP7CKUHWTJamANqg8NCTQ', + 'UCPtDuLhreIEcjJr7WWaNaUw', + 'UCS8gM5S889oBPyN6K07ZC6A', + 'UCUn24NHjc8asGiYet1P9h5Q', + 'UCqdJpVkTPem_iKcoVqoZtAg', + 'UCtcVe3ucfS-AZVcNc2GabPw', + 'UCDk0PdOMRfknGhVE8R-S_DQ', + 'UC0UFeYG5aSGZT2e8lOjQ7oA', + 'UC1yC2i8t5ivhh5RsRpGWMlw', + 'UCP_YnD-BO8ctnKgUW89Si6Q', + 'UCoxFxZirbfLvy9tres71eSA', + 'UClf1Wfw54YBjJNlX3NjSOPA', + 'UC8X10knH1xD3PTeds8glyNw', + 'UCgKTJAN-IrVyX-jIJ5INEhA', + 'UCgjAbjJZgBCF3OVGkJV5kCw', + 'UC7xWZT4HPMFYzFoijmH8POg', + 'UCoBfUpZXvWjS995ZXCPxxVQ', + 'UCoOh1fOZBN7uCc3qu-TTAJQ', + 'UCo8wWQvRSoKL57vjv4vyXQw' + ) + + 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) + + @app.get('/live') + @app.get('/logged_out/live') + @auth_desired_with_logingate + def live(v): + live = [] + offline = [] + for x in streamers: + url = f'https://www.youtube.com/channel/{x}/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((req.url, t.group(1), y.group(2), y.group(1), count)) + except: + offline.append((req.url, t.group(1), y.group(2))) + else: + y = offline_regex.search(txt) + offline.append((req.url, y.group(2), y.group(1))) + + return render_template(f'live.html', v=v, live=live, offline=offline) \ No newline at end of file diff --git a/files/templates/live.html b/files/templates/live.html new file mode 100644 index 000000000..025afcc76 --- /dev/null +++ b/files/templates/live.html @@ -0,0 +1,44 @@ +{% extends "default.html" %} + +{% block title %} + {{SITE_NAME}} - Live +{% endblock %} + +{% block content %} + +

Live

+
+ + + {% for link, thumb, name, title, viewers in live %} + + + + + + + {% endfor %} + +
{{name}} thumbnail{{name}}{{title}}{{viewers}}
+
+ +

Offline

+
+ + + {% for link, thumb, name in offline %} + + + + + + + {% endfor %} + +
{{name}} thumbnail{{name}}
+
+{% endblock %} \ No newline at end of file From c20fc347047e29c2820466f61c3312e776127512 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 22 Sep 2022 04:20:47 +0200 Subject: [PATCH 02/17] dfs --- files/routes/static.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/routes/static.py b/files/routes/static.py index 651548383..b1ef00c2c 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -486,6 +486,7 @@ if SITE_NAME == 'PCM': offline.append((req.url, t.group(1), y.group(2))) else: y = offline_regex.search(txt) - offline.append((req.url, y.group(2), y.group(1))) + try: offline.append((req.url, y.group(2), y.group(1))) + except: print(x) return render_template(f'live.html', v=v, live=live, offline=offline) \ No newline at end of file From 71309f86fb1cffb09d3a8a64606675a1bdf060d7 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 22 Sep 2022 04:22:21 +0200 Subject: [PATCH 03/17] order by viewer count --- files/routes/static.py | 1 + 1 file changed, 1 insertion(+) diff --git a/files/routes/static.py b/files/routes/static.py index b1ef00c2c..5db41b7ba 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -489,4 +489,5 @@ if SITE_NAME == 'PCM': try: offline.append((req.url, y.group(2), y.group(1))) except: print(x) + live = sorted(live, key=lambda x: x[4], reverse=True) return render_template(f'live.html', v=v, live=live, offline=offline) \ No newline at end of file From 61f4ae873146480969a3e272bd5963fae03c3103 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 22 Sep 2022 04:25:03 +0200 Subject: [PATCH 04/17] add a red circle to /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 025afcc76..d5e2f65ca 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -10,7 +10,7 @@ border: 2.5px solid var(--primary); } -

Live

+

Live

From 1dfbad69b8b28468a54cfaec4e70f15077de1c17 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 22 Sep 2022 04:27:41 +0200 Subject: [PATCH 05/17] cosmetic changes --- 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 d5e2f65ca..f2ceb13a7 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -10,7 +10,7 @@ border: 2.5px solid var(--primary); } -

Live

+

Live

From ddcebd10bea51fd3ebd0fa2f2a219f9d9fef88f4 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 22 Sep 2022 04:29:09 +0200 Subject: [PATCH 06/17] cosmetic changes --- 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 f2ceb13a7..8baacd9a9 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -26,7 +26,7 @@
-

Offline

+

Offline

From 59f7a7655bd1170b152840a215936b876fc9f043 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 22 Sep 2022 04:29:50 +0200 Subject: [PATCH 07/17] remove ordering as a test --- files/routes/static.py | 1 - 1 file changed, 1 deletion(-) diff --git a/files/routes/static.py b/files/routes/static.py index 5db41b7ba..b1ef00c2c 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -489,5 +489,4 @@ if SITE_NAME == 'PCM': try: offline.append((req.url, y.group(2), y.group(1))) except: print(x) - live = sorted(live, key=lambda x: x[4], reverse=True) return render_template(f'live.html', v=v, live=live, offline=offline) \ No newline at end of file From 553218aaa5a9f3df8968b79c55b3e2df5a52849e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 22 Sep 2022 04:33:45 +0200 Subject: [PATCH 08/17] make /live a cached cron job --- files/helpers/cron.py | 2 ++ files/routes/static.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/files/helpers/cron.py b/files/helpers/cron.py index 5b22796ea..c5393f5d2 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -39,6 +39,8 @@ def cron(every_5m, every_1h, every_1d, every_1mo): stats.generate_charts_task(SITE) route_static.stats_cached() sub_inactive_purge_task() + if SITE_NAME == 'PCM': + route_static.live_cached() if every_1mo: if KOFI_LINK: give_monthly_marseybux_task_kofi() diff --git a/files/routes/static.py b/files/routes/static.py index b1ef00c2c..54dfb0c03 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -466,10 +466,8 @@ if SITE_NAME == 'PCM': live_thumb_regex = re.compile('\{"thumbnail":\{"thumbnails":\[\{"url":"(.*?)"', flags=re.A) offline_regex = re.compile('","title":"(.*?)".*?"width":48,"height":48\},\{"url":"(.*?)"', flags=re.A) - @app.get('/live') - @app.get('/logged_out/live') - @auth_desired_with_logingate - def live(v): + @cache.memoize(timeout=86400) + def live_cached(): live = [] offline = [] for x in streamers: @@ -489,4 +487,12 @@ if SITE_NAME == 'PCM': try: offline.append((req.url, y.group(2), y.group(1))) except: print(x) - return render_template(f'live.html', v=v, live=live, offline=offline) \ No newline at end of file + live = sorted(live, key=lambda x: x[4], reverse=True) + + return live, offline + + @app.get('/live') + @app.get('/logged_out/live') + @auth_desired_with_logingate + def live(v): + return render_template(f'live.html', v=v, live=live_cached()[0], offline=live_cached()[1]) \ No newline at end of file From b85c1940edb39902064f932fc60630df303b461b Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 22 Sep 2022 04:46:44 +0200 Subject: [PATCH 09/17] [pcm] cosmetic change --- files/templates/live.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/files/templates/live.html b/files/templates/live.html index 8baacd9a9..8af3e5801 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -16,10 +16,12 @@ {% for link, thumb, name, title, viewers in live %} - - - - + + + + + + {% endfor %} From 0be4167069c25e667b97d6d58873de3ed0dba69f Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 22 Sep 2022 04:47:28 +0200 Subject: [PATCH 10/17] revert last commit --- files/templates/live.html | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/files/templates/live.html b/files/templates/live.html index 8af3e5801..8baacd9a9 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -16,12 +16,10 @@ {% for link, thumb, name, title, viewers in live %} - - - - - - + + + + {% endfor %} From 227810dec95372efa68c1ae41d5663bfb0c87956 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 22 Sep 2022 06:34:16 +0200 Subject: [PATCH 11/17] add /live icon --- files/assets/css/main.css | 17 ++++++++++------- files/templates/header.html | 12 +++++++++++- files/templates/util/assetcache.html | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/files/assets/css/main.css b/files/assets/css/main.css index 6be4b3756..767600d1d 100644 --- a/files/assets/css/main.css +++ b/files/assets/css/main.css @@ -3148,13 +3148,6 @@ small, .small { -webkit-animation: bounce-bot .7s 1 0s; } -@keyframes upmarsey -{ - 0% { top: -15px; } - 100% { top: 0px; } -} - - @keyframes bounce-top { 20% { transform: translateY(-9px); @@ -6270,4 +6263,14 @@ div.markdown { .text-brown { color: #433722; +} + +.live-circle { + animation: blinker 1s infinite; +} + +@keyframes blinker { + from { color: var(--gray-200) } + 50% { color:red } + to { color: var(--gray-200) } } \ No newline at end of file diff --git a/files/templates/header.html b/files/templates/header.html index 225c9eedd..2d5fbfd44 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -100,6 +100,10 @@ {% if g.webview %} {% endif %} + + {% if SITE_NAME == 'PCM' %} + + {% endif %} {% if v %} {% if v.notifications_count %} @@ -137,6 +141,12 @@
{{name}} thumbnail{{name}}{{title}}{{viewers}}{{name}} thumbnail{{name}}{{title}}{{viewers}}
{{name}} thumbnail{{name}}{{title}}{{viewers}}{{name}} thumbnail{{name}}{{title}}{{viewers}}