forked from rDrama/rDrama
Merge branch 'frost' of https://github.com/Aevann1/rDrama into frost
commit
3435389807
|
@ -1,6 +1,6 @@
|
||||||
from files.helpers.const import SITE
|
from files.helpers.const import SITE
|
||||||
|
|
||||||
if SITE == 'pcmemes.net' or True:
|
if SITE == 'pcmemes.net':
|
||||||
from sqlalchemy import *
|
from sqlalchemy import *
|
||||||
from files.__main__ import Base
|
from files.__main__ import Base
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,8 @@ def cron(every_5m, every_1h, every_1d, every_1mo):
|
||||||
lottery.check_if_end_lottery_task()
|
lottery.check_if_end_lottery_task()
|
||||||
spin_roulette_wheel()
|
spin_roulette_wheel()
|
||||||
offsitementions.offsite_mentions_task()
|
offsitementions.offsite_mentions_task()
|
||||||
if SITE == 'pcmemes.net' or True:
|
if SITE == 'pcmemes.net':
|
||||||
x = route_static.live_cached()
|
route_static.live_cached()
|
||||||
cache.set('live', x[0])
|
|
||||||
cache.set('offline', x[1])
|
|
||||||
|
|
||||||
if every_1h:
|
if every_1h:
|
||||||
awards.award_timers_bots_task()
|
awards.award_timers_bots_task()
|
||||||
|
|
|
@ -118,7 +118,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false"
|
||||||
if sort == 'hot':
|
if sort == 'hot':
|
||||||
ti = int(time.time()) + 3600
|
ti = int(time.time()) + 3600
|
||||||
if SITE_NAME == 'rDrama':
|
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,'<a href="https://','')))/5))/(func.power(((ti - Submission.created_utc)/1000), 1.23)), Submission.created_utc.desc())
|
posts = posts.order_by(-1000000*(Submission.realupvotes + 1 + Submission.comment_count/5 + func.least(10, (func.length(Submission.body_html)-func.length(func.replace(Submission.body_html,'<a href="https://','')))/5))/(func.power(((ti - Submission.created_utc)/1000), 1.23)), Submission.created_utc.desc())
|
||||||
else:
|
else:
|
||||||
posts = posts.order_by(-1000000*(Submission.upvotes - Submission.downvotes + 1)/(func.power(((ti - Submission.created_utc)/1000), 1.23)), Submission.created_utc.desc())
|
posts = posts.order_by(-1000000*(Submission.upvotes - Submission.downvotes + 1)/(func.power(((ti - Submission.created_utc)/1000), 1.23)), Submission.created_utc.desc())
|
||||||
elif sort == "bump":
|
elif sort == "bump":
|
||||||
|
|
|
@ -436,12 +436,77 @@ 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 == 'pcmemes.net' or True:
|
if SITE == 'pcmemes.net':
|
||||||
from files.classes.streamers import *
|
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_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)
|
||||||
offline_regex = re.compile('","title":"(.*?)".*?"width":48,"height":48\},\{"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, 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:
|
||||||
|
y = live_regex.search(text)
|
||||||
|
count = y.group(3)
|
||||||
|
if 'wacht' in count:
|
||||||
|
return process_streamer(id, '')
|
||||||
|
|
||||||
|
count = int(count.replace('.', ''))
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
if y:
|
||||||
|
views = y.group(3).replace('.', '')
|
||||||
|
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('dag'):
|
||||||
|
unit = 'day'
|
||||||
|
modifier = 1440
|
||||||
|
if unit.startswith('we'):
|
||||||
|
unit = 'week'
|
||||||
|
modifier = 10080
|
||||||
|
elif unit.startswith('maand'):
|
||||||
|
unit = 'month'
|
||||||
|
modifier = 43800
|
||||||
|
elif unit == 'jaar':
|
||||||
|
unit = 'year'
|
||||||
|
modifier = 525600
|
||||||
|
|
||||||
|
minutes = quantity * modifier
|
||||||
|
|
||||||
|
actual = f'{quantity} {unit}'
|
||||||
|
if quantity > 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():
|
def live_cached():
|
||||||
live = []
|
live = []
|
||||||
|
@ -449,26 +514,18 @@ if SITE == 'pcmemes.net' or True:
|
||||||
db = db_session()
|
db = db_session()
|
||||||
streamers = [x[0] for x in db.query(Streamer.id).all()]
|
streamers = [x[0] for x in db.query(Streamer.id).all()]
|
||||||
db.close()
|
db.close()
|
||||||
for x in streamers:
|
for id in streamers:
|
||||||
url = f'https://www.youtube.com/channel/{x}/live'
|
processed = process_streamer(id)
|
||||||
req = requests.get(url, cookies={'CONSENT': 'YES+1'}, timeout=5, proxies=proxies)
|
if processed:
|
||||||
text = req.text
|
if processed[0]: live.append(processed[1])
|
||||||
if '"videoDetails":{"videoId"' in text:
|
else: offline.append(processed[1])
|
||||||
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)
|
|
||||||
|
|
||||||
live = sorted(live, key=lambda x: x[5], reverse=True)
|
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('/live')
|
||||||
@app.get('/logged_out/live')
|
@app.get('/logged_out/live')
|
||||||
|
@ -482,13 +539,23 @@ if SITE == 'pcmemes.net' or True:
|
||||||
@app.post('/live/add')
|
@app.post('/live/add')
|
||||||
@admin_level_required(2)
|
@admin_level_required(2)
|
||||||
def live_add(v):
|
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 []
|
live = cache.get('live') or []
|
||||||
offline = cache.get('offline') or []
|
offline = cache.get('offline') or []
|
||||||
|
|
||||||
if not id or len(id) != 24:
|
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)
|
existing = g.db.get(Streamer, id)
|
||||||
if not existing:
|
if not existing:
|
||||||
|
@ -498,27 +565,16 @@ if SITE == 'pcmemes.net' or True:
|
||||||
if v.id != KIPPY_ID:
|
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})")
|
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'
|
processed = process_streamer(id)
|
||||||
req = requests.get(url, cookies={'CONSENT': 'YES+1'}, timeout=5, proxies=proxies)
|
if processed:
|
||||||
text = req.text
|
if processed[0]: live.append(processed[1])
|
||||||
if '"videoDetails":{"videoId"' in text:
|
else: offline.append(processed[1])
|
||||||
t = live_thumb_regex.search(text)
|
|
||||||
y = live_regex.search(text)
|
live = sorted(live, key=lambda x: x[5], reverse=True)
|
||||||
try:
|
offline = sorted(offline, key=lambda x: x[4])
|
||||||
count = int(y.group(3))
|
|
||||||
live.append((id, req.url, t.group(1), y.group(2), y.group(1), count))
|
if live: cache.set('live', live)
|
||||||
cache.set('live', live)
|
if offline: cache.set('offline', offline)
|
||||||
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)
|
|
||||||
|
|
||||||
return redirect('/live')
|
return redirect('/live')
|
||||||
|
|
||||||
|
@ -539,7 +595,7 @@ if SITE == 'pcmemes.net' or True:
|
||||||
live = [x for x in live if x[0] != id]
|
live = [x for x in live if x[0] != id]
|
||||||
offline = [x for x in offline if x[0] != id]
|
offline = [x for x in offline if x[0] != id]
|
||||||
|
|
||||||
cache.set('live', live)
|
if live: cache.set('live', live)
|
||||||
cache.set('offline', offline)
|
if offline: cache.set('offline', offline)
|
||||||
|
|
||||||
return redirect('/live')
|
return redirect('/live')
|
|
@ -53,7 +53,7 @@
|
||||||
<td width="48"><img loading="lazy" class="thumb" src="{{thumb}}" alt="{{name}} thumbnail" referrerpolicy="no-referrer" width="48"></td>
|
<td width="48"><img loading="lazy" 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}} watching</td>
|
||||||
{% if v and v.admin_level > 1 %}
|
{% if v and v.admin_level > 1 %}
|
||||||
<td>
|
<td>
|
||||||
<form action="/live/remove" method="post">
|
<form action="/live/remove" method="post">
|
||||||
|
@ -74,12 +74,12 @@
|
||||||
<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 id, link, thumb, name in offline %}
|
{% for id, link, thumb, name, minutes, actual, views in offline %}
|
||||||
<tr onclick="go_to(event,'{{link}}')">
|
<tr onclick="go_to(event,'{{link}}')">
|
||||||
<td width="48"><img loading="lazy" class="thumb" src="{{thumb}}" alt="{{name}} thumbnail" referrerpolicy="no-referrer" width="48"></td>
|
<td width="48"><img loading="lazy" class="thumb" src="{{thumb}}" alt="{{name}} thumbnail" referrerpolicy="no-referrer" width="48"></td>
|
||||||
<td>{{name}}</td>
|
<td>{{name}}</td>
|
||||||
<td></td>
|
<td>{{actual}} ago</td>
|
||||||
<td></td>
|
<td>{{views}} views</td>
|
||||||
{% if v and v.admin_level > 1 %}
|
{% if v and v.admin_level > 1 %}
|
||||||
<td>
|
<td>
|
||||||
<form action="/live/remove" method="post">
|
<form action="/live/remove" method="post">
|
||||||
|
@ -99,10 +99,13 @@
|
||||||
{% if v and v.admin_level > 1 %}
|
{% if v and v.admin_level > 1 %}
|
||||||
<form action="/live/add" method="post">
|
<form action="/live/add" 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:350px" autocomplete="off" type="text" name="id" class="form-control" placeholder="Enter channel id.." minlength="24" maxlength="24" required>
|
<input class="form-control" autocomplete="off" type="text" name="link" class="form-control" placeholder="Enter channel link.." required>
|
||||||
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Add Youtube Channel" style="margin-bottom:5px">
|
<input autocomplete="off" class="btn btn-primary mt-3" type="submit" onclick="disable(this)" value="Add Youtube Channel" style="float:right">
|
||||||
</form>
|
</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 %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
<pre>
|
||||||
|
|
||||||
|
|
||||||
|
</pre>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -138,7 +138,7 @@
|
||||||
<label class="custom-control-label" for="newtab"></label>
|
<label class="custom-control-label" for="newtab"></label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span class="text-small text-muted">Enable if you would like to automatically open links to other pages in the site in new tabs.</span>
|
<span class="text-small text-muted">Enable if you would like to automatically open links to other pages on the site in new tabs.</span>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -773,7 +773,7 @@
|
||||||
<label class="custom-control-label" for="spiderswitch"></label>
|
<label class="custom-control-label" for="spiderswitch"></label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span class="text-small text-muted">Have a spider friend accompany you during your journey in the site.</span>
|
<span class="text-small text-muted">Have a spider friend accompany you during your journey on the site.</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue