Get stream title from disk

By default from `title.txt`. Also replace newlines with spaces when setting the
title in js, for parity with the nojs info iframe.
l10n
n9k 6ヶ月前
コミット 8b4d6e8c09
  1. 1
      .gitignore
  2. 2
      anonstream/__init__.py
  3. 2
      anonstream/routes/nojs.py
  4. 10
      anonstream/static/anonstream.js
  5. 4
      anonstream/static/style.css
  6. 16
      anonstream/stream.py
  7. 1
      anonstream/templates/nojs_info.html
  8. 2
      anonstream/websocket.py
  9. 21
      anonstream/wrappers.py
  10. 4
      config.toml
  11. 1
      title.txt

1
.gitignore vendored

@ -1,3 +1,4 @@
__pycache__/
stream/
*~
title.txt

@ -32,6 +32,8 @@ def create_app(config_file):
'SEGMENT_SEARCH_COOLDOWN': config['segments']['search_cooldown'],
'SEGMENT_SEARCH_TIMEOUT': config['segments']['search_timeout'],
'SEGMENT_STREAM_INITIAL_BUFFER': config['segments']['stream_initial_buffer'],
'STREAM_TITLE': config['title']['file'],
'STREAM_TITLE_CACHE_LIFETIME': config['title']['file_cache_lifetime'],
'DEFAULT_HOST_NAME': config['names']['broadcaster'],
'DEFAULT_ANON_NAME': config['names']['anonymous'],
'MAX_STATES': config['memory']['states'],

@ -19,7 +19,7 @@ async def nojs_info(user):
return await render_template(
'nojs_info.html',
user=user,
title=get_stream_title(),
title=await get_stream_title(),
uptime=get_stream_uptime(),
)

@ -316,6 +316,12 @@ const disable_captcha = () => {
chat_form_captcha_image.removeAttribute("src");
}
const set_title = (title) => {
const element = document.createElement("h1");
element.innerText = title.replaceAll(/\r?\n/g, " ");
info_title.innerHTML = element.outerHTML;
}
let frozen_uptime = null;
let frozen_uptime_received = null;
const set_frozen_uptime = (x) => {
@ -357,7 +363,7 @@ const on_websocket_message = (event) => {
case "init":
console.log("ws init", receipt);
info_title.innerText = receipt.title;
set_title(receipt.title);
set_frozen_uptime(receipt.uptime);
update_uptime();
@ -395,7 +401,7 @@ const on_websocket_message = (event) => {
case "title":
console.log("ws title", receipt);
info_title.innerText = receipt.title;
set_title(receipt.title);
break;
case "ack":

@ -68,8 +68,10 @@ noscript {
float: right;
font-size: 11pt;
}
#info_js__title {
#info_js__title > h1 {
margin: 0;
font-size: 18pt;
line-height: 1.125;
overflow-wrap: anywhere;
}
#info_nojs {

@ -1,9 +1,21 @@
import time
import aiofiles
from quart import current_app
from anonstream.segments import get_playlist, Offline
from anonstream.wrappers import ttl_cache_async
CONFIG = current_app.config
def get_stream_title():
return 'Stream title'
@ttl_cache_async(CONFIG['STREAM_TITLE_CACHE_LIFETIME'])
async def get_stream_title():
try:
async with aiofiles.open(CONFIG['STREAM_TITLE']) as fp:
title = await fp.read(8192)
except FileNotFoundError:
title = ''
return title
def get_stream_uptime(rounded=True):
try:

@ -16,6 +16,7 @@
#title > h1 {
margin: 0;
font-size: 18pt;
line-height: 1.125;
overflow-wrap: anywhere;
}
</style>

@ -15,7 +15,7 @@ async def websocket_outbound(queue, user):
payload = {
'type': 'init',
'nonce': generate_nonce(),
'title': get_stream_title(),
'title': await get_stream_title(),
'uptime': get_stream_uptime(),
'messages': get_all_messages_for_websocket(),
'users': get_all_users_for_websocket(),

@ -53,3 +53,24 @@ def ttl_cache(ttl):
return wrapper
return ttl_cache_specific
def ttl_cache_async(ttl):
'''
Async version of `ttl_cache`. Wraps zero-argument coroutines.
'''
def ttl_cache_specific(f):
value, expires = None, None
@wraps(f)
async def wrapper():
nonlocal value, expires
if expires is None or time.monotonic() >= expires:
value = await f()
expires = time.monotonic() + ttl
return value
return wrapper
return ttl_cache_specific

@ -12,6 +12,10 @@ search_cooldown = 0.25
search_timeout = 5.0
stream_initial_buffer = 3
[title]
file = "title.txt"
file_cache_lifetime = 0.5
[captcha]
lifetime = 1800
fonts = []

@ -0,0 +1 @@
Lorem ipsum dolor sit amet
読み込み中…
キャンセル
保存