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/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,' 1: actual += 's' + else: + minutes = 0 + actual = '???' + views = 0 + + print(req.url, flush=True) + thumb = t.group(2) + name = t.group(1) + + return (False, (id, req.url.rstrip('/live'), thumb, name, minutes, actual, views)) + def live_cached(): live = [] @@ -449,26 +514,18 @@ 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]) + + if live: cache.set('live', live) + if offline: cache.set('offline', offline) - return live, offline @app.get('/live') @app.get('/logged_out/live') @@ -482,13 +539,23 @@ if SITE == 'pcmemes.net' or True: @app.post('/live/add') @admin_level_required(2) def live_add(v): - id = request.values.get('id').strip() + if v.id not in (AEVANN_ID, KIPPY_ID, 1550): + return {"error": 'Only Kippy can add channels!'}, 403 + + link = request.values.get('link').strip() + + 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"} 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: @@ -498,27 +565,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]) + + if live: cache.set('live', live) + if offline: cache.set('offline', offline) return redirect('/live') @@ -539,7 +595,7 @@ if SITE == 'pcmemes.net' or True: 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 diff --git a/files/templates/live.html b/files/templates/live.html index 30fa68b48..7d0fd19a8 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -53,7 +53,7 @@ {{name}} thumbnail {{name}} {{title}} - {{viewers}} + {{viewers}} watching {% if v and v.admin_level > 1 %}
@@ -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 %}
{{name}} thumbnail {{name}}{{actual}} ago{{views}} views @@ -99,10 +99,13 @@ {% 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 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.