allow PCM chadmins to add or remove channels (#365)
* testing on devrama * fix for devrama * fix * fix * fix * fix * fix * fix * test * fix * test * test * commitremotes/1693176582716663532/tmp_refs/heads/watchparty
parent
bf5abefc4c
commit
2ef91698f4
|
@ -24,4 +24,5 @@ from .lottery import *
|
||||||
from .casino_game import *
|
from .casino_game import *
|
||||||
from .hats import *
|
from .hats import *
|
||||||
from .marsey import *
|
from .marsey import *
|
||||||
from .transactions import *
|
from .transactions import *
|
||||||
|
from .streamers import *
|
|
@ -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"<Streamer(id={self.id})>"
|
|
@ -436,31 +436,8 @@ 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_NAME == 'PCM':
|
if SITE == 'pcmemes.net':
|
||||||
streamers = (
|
from files.classes.streamers import *
|
||||||
'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_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)
|
live_thumb_regex = re.compile('\{"thumbnail":\{"thumbnails":\[\{"url":"(.*?)"', flags=re.A)
|
||||||
|
@ -470,6 +447,9 @@ if SITE_NAME == 'PCM':
|
||||||
def live_cached():
|
def live_cached():
|
||||||
live = []
|
live = []
|
||||||
offline = []
|
offline = []
|
||||||
|
db = db_session()
|
||||||
|
streamers = [x[0] for x in db.query(Streamer.id).all()]
|
||||||
|
db.close()
|
||||||
for x in streamers:
|
for x in streamers:
|
||||||
url = f'https://www.youtube.com/channel/{x}/live'
|
url = f'https://www.youtube.com/channel/{x}/live'
|
||||||
req = requests.get(url, cookies={'CONSENT': 'YES+1'}, proxies=proxies)
|
req = requests.get(url, cookies={'CONSENT': 'YES+1'}, proxies=proxies)
|
||||||
|
@ -479,12 +459,12 @@ if SITE_NAME == 'PCM':
|
||||||
y = live_regex.search(txt)
|
y = live_regex.search(txt)
|
||||||
try:
|
try:
|
||||||
count = int(y.group(3))
|
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:
|
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:
|
else:
|
||||||
y = offline_regex.search(txt)
|
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)
|
except: print(x)
|
||||||
|
|
||||||
live = sorted(live, key=lambda x: x[4], reverse=True)
|
live = sorted(live, key=lambda x: x[4], reverse=True)
|
||||||
|
@ -495,4 +475,32 @@ if SITE_NAME == 'PCM':
|
||||||
@app.get('/logged_out/live')
|
@app.get('/logged_out/live')
|
||||||
@auth_desired_with_logingate
|
@auth_desired_with_logingate
|
||||||
def live(v):
|
def live(v):
|
||||||
return render_template(f'live.html', v=v, live=live_cached()[0], offline=live_cached()[1])
|
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')
|
|
@ -13,17 +13,32 @@
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<script>
|
||||||
|
function go_to(e, link) {
|
||||||
|
if (e.target.type != "submit")
|
||||||
|
window.open('{{link}}', '_blank');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<div class="px-2">
|
<div class="px-2">
|
||||||
<h1 class="py-3"><i class="fas fa-circle mr-3" style="color:red"></i>Live</h1>
|
<h1 class="py-3"><i class="fas fa-circle mr-3" style="color:red"></i>Live</h1>
|
||||||
<div class="overflow-x-auto">
|
<div class="overflow-x-auto">
|
||||||
<table class="table table-striped mb-5">
|
<table class="table table-striped mb-5">
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for link, thumb, name, title, viewers in live %}
|
{% for id, link, thumb, name, title, viewers in live %}
|
||||||
<tr onclick="window.open('{{link}}', '_blank')">
|
<tr onclick="go_to(event,'{{link}}')">
|
||||||
<td width="48"><img class="thumb" src="{{thumb}}" alt="{{name}} thumbnail" referrerpolicy="no-referrer" width="48"></td>
|
<td width="48"><img class="thumb" src="{{thumb}}" alt="{{name}} thumbnail" referrerpolicy="no-referrer" width="48"></td>
|
||||||
<td>{{name}}</td>
|
<td>{{name}}</td>
|
||||||
<td>{{title}}</td>
|
<td>{{title}}</td>
|
||||||
<td>{{viewers}}</td>
|
<td>{{viewers}}</td>
|
||||||
|
{% if v and v.admin_level > 1 %}
|
||||||
|
<td>
|
||||||
|
<form action="/live/remove" method="post">
|
||||||
|
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||||
|
<input type="hidden" name="id" value="{{id}}">
|
||||||
|
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Remove Channel">
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -34,16 +49,34 @@
|
||||||
<div class="overflow-x-auto">
|
<div class="overflow-x-auto">
|
||||||
<table class="table table-striped mb-5">
|
<table class="table table-striped mb-5">
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for link, thumb, name in offline %}
|
{% for id, link, thumb, name in offline %}
|
||||||
<tr onclick="window.open('{{link}}', '_blank')">
|
<tr onclick="go_to(event,'{{link}}')">
|
||||||
<td width="48"><img class="thumb" src="{{thumb}}" alt="{{name}} thumbnail" referrerpolicy="no-referrer" width="48"></td>
|
<td width="48"><img class="thumb" src="{{thumb}}" alt="{{name}} thumbnail" referrerpolicy="no-referrer" width="48"></td>
|
||||||
<td>{{name}}</td>
|
<td>{{name}}</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
{% if v and v.admin_level > 1 %}
|
||||||
|
<td>
|
||||||
|
<form action="/live/remove" method="post">
|
||||||
|
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||||
|
<input type="hidden" name="id" value="{{id}}">
|
||||||
|
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Remove Channel">
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if v and v.admin_level > 1 %}
|
||||||
|
<form action="/live/add" method="post">
|
||||||
|
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||||
|
<input class="form-control" style="display:inline;width:350px" autocomplete="off" type="text" name="id" class="form-control" placeholder="Enter channel id..">
|
||||||
|
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Add Youtube Channel" style="margin-top:-5px">
|
||||||
|
</form>
|
||||||
|
<p class="mt-3">you can get the channel id using this site <a href="https://streamweasels.com/tools/youtube-channel-id-and-user-id-convertor" rel="nofollow noopener noreferrer" target="_blank">https://streamweasels.com/tools/youtube-channel-id-and-user-id-convertor</a></p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -28,7 +28,7 @@
|
||||||
{% if v.mods(sub.name) %}
|
{% if v.mods(sub.name) %}
|
||||||
<form action="/h/{{sub}}/unexile/{{user.id}}" method="post">
|
<form action="/h/{{sub}}/unexile/{{user.id}}" method="post">
|
||||||
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||||
<input class="btn btn-primary" autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Unexile">
|
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Unexile">
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<form action="/h/{{sub}}/remove_mod" method="post">
|
<form action="/h/{{sub}}/remove_mod" method="post">
|
||||||
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||||
<input type="hidden" name="uid" value="{{user.id}}">
|
<input type="hidden" name="uid" value="{{user.id}}">
|
||||||
<input class="btn btn-primary" autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="{% if v.id == user.id %}Resign{% else %}Remove Mod{% endif %}">
|
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="{% if v.id == user.id %}Resign{% else %}Remove Mod{% endif %}">
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
<form action="/h/{{sub}}/add_mod" method="post">
|
<form action="/h/{{sub}}/add_mod" method="post">
|
||||||
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||||
<input class="form-control" style="display:inline;width:250px" autocomplete="off" type="text" name="user" class="form-control" placeholder="Enter username..">
|
<input class="form-control" style="display:inline;width:250px" autocomplete="off" type="text" name="user" class="form-control" placeholder="Enter username..">
|
||||||
<input class="btn btn-primary" autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Add Mod">
|
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Add Mod">
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue