diff --git a/files/classes/__init__.py b/files/classes/__init__.py index 7e8f93c05..23647e7ab 100644 --- a/files/classes/__init__.py +++ b/files/classes/__init__.py @@ -24,4 +24,5 @@ from .lottery import * from .casino_game import * from .hats import * from .marsey import * -from .transactions import * \ No newline at end of file +from .transactions import * +from .streamers import * \ No newline at end of file diff --git a/files/classes/streamers.py b/files/classes/streamers.py new file mode 100644 index 000000000..575481785 --- /dev/null +++ b/files/classes/streamers.py @@ -0,0 +1,13 @@ +from files.helpers.const import SITE + +if SITE == 'pcmemes.net': + from sqlalchemy import * + from files.__main__ import Base + + class Streamer(Base): + + __tablename__ = "streamers" + id = Column(String, primary_key=True) + + def __repr__(self): + return f"" \ No newline at end of file diff --git a/files/routes/static.py b/files/routes/static.py index 260ab55db..3996f165c 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -436,31 +436,8 @@ def donate(v): 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' - ) +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) @@ -470,6 +447,9 @@ if SITE_NAME == 'PCM': def live_cached(): live = [] offline = [] + 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'}, proxies=proxies) @@ -479,12 +459,12 @@ if SITE_NAME == 'PCM': 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)) + live.append((x, req.url, t.group(1), y.group(2), y.group(1), count)) except: - offline.append((req.url.rstrip('/live'), t.group(1), y.group(2))) + offline.append((x, req.url.rstrip('/live'), t.group(1), y.group(2))) else: y = offline_regex.search(txt) - try: offline.append((req.url.rstrip('/live'), y.group(2), y.group(1))) + try: offline.append((x, req.url.rstrip('/live'), y.group(2), y.group(1))) except: print(x) live = sorted(live, key=lambda x: x[4], reverse=True) @@ -495,4 +475,32 @@ if SITE_NAME == 'PCM': @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 + return render_template(f'live.html', v=v, live=live_cached()[0], offline=live_cached()[1]) + + @app.post('/live/add') + @admin_level_required(2) + def live_add(v): + id = request.values.get('id') + if not id: abort(400) + existing = g.db.get(Streamer, id) + if not existing: + streamer = Streamer(id=id) + g.db.add(streamer) + g.db.flush() + 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})") + cache.delete_memoized(live_cached) + return redirect(f'/live') + + @app.post('/live/remove') + @admin_level_required(2) + def live_remove(v): + id = request.values.get('id') + if not id: abort(400) + streamer = g.db.get(Streamer, id) + if streamer: + if v.id != KIPPY_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) + cache.delete_memoized(live_cached) + return redirect(f'/live') \ No newline at end of file diff --git a/files/templates/live.html b/files/templates/live.html index 3578b3798..4e22d7108 100644 --- a/files/templates/live.html +++ b/files/templates/live.html @@ -13,17 +13,32 @@ border-radius: 4px; } +

Live

- {% for link, thumb, name, title, viewers in live %} - + {% for id, link, thumb, name, title, viewers in live %} + + {% if v and v.admin_level > 1 %} + + {% endif %} {% endfor %} @@ -34,16 +49,34 @@
{{name}} thumbnail {{name}} {{title}} {{viewers}} +
+ + + +
+
- {% for link, thumb, name in offline %} - + {% for id, link, thumb, name in offline %} + + {% if v and v.admin_level > 1 %} + + {% endif %} {% endfor %}
{{name}} thumbnail {{name}} +
+ + + +
+
+ + {% 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/sub/exilees.html b/files/templates/sub/exilees.html index 8e4e1f134..c5f7ea8c6 100644 --- a/files/templates/sub/exilees.html +++ b/files/templates/sub/exilees.html @@ -28,7 +28,7 @@ {% if v.mods(sub.name) %}
- +
{% endif %} diff --git a/files/templates/sub/mods.html b/files/templates/sub/mods.html index 08f1fb7a4..6ad60d96d 100644 --- a/files/templates/sub/mods.html +++ b/files/templates/sub/mods.html @@ -25,7 +25,7 @@
- +
{% endif %} @@ -38,7 +38,7 @@
- +
{% endif %}