{% block script %}
-const PATH_PREFIX_TAGS_UPDATE = '/{{page_names.file_tags}}/';
const CLS_PLAYLIST_ROW = 'playlist_row';
-path_tags_update = '?';
events_params += 'playlist=1';
-function get_el_and_empty(id) {
- let el = document.getElementById(id);
- el.textContent = '';
- return el; }
-
function new_child_to(tag, parent, textContent='') {
const el = document.createElement(tag);
parent.appendChild(el);
tr.classList.add(CLS_PLAYLIST_ROW);
const td_entry_control = new_child_to('td', tr);
td_entry_control.classList.add('entry_control');
- if (data.current_file && data.current_file.digest == file.digest) {
+ if (data.title_digest == file.digest) {
td_entry_control.textContent = 'playing'; }
else {
for (const [symbol, prefix] of [['>', 'jump'],
btn.onclick = function() { player_command(`${prefix}_${i}`) }; }}
const td_link = new_child_to('td', tr);
const a_file = new_child_to('a', td_link, file.rel_path);
- a_file.href = `/${data.link_prefix}/${file.digest}`; }})
-
-event_handlers.push(function(data) { // update current_file table
- const td_current_path = get_el_and_empty('current_path');
- const td_current_yt_id = get_el_and_empty('current_yt_id');
- const table_current_tags = get_el_and_empty('current_tags');
- const datalist_unused_tags = get_el_and_empty('unused_tags');
- const btn_update = document.getElementById('btn_update_tags');
- btn_update.disabled = true;
- path_tags_update = '?';
- if (data.current_file) {
- const a_path = new_child_to('a', td_current_path, data.current_file.rel_path);
- a_path.href = `/${data.link_prefix}/${data.current_file.digest}`;
- if (data.current_file.yt_id) {
- const a_yt = new_child_to('a', td_current_yt_id, data.current_file.yt_id);
- a_yt.href = `/${data.yt_result_prefix}/${data.current_file.yt_id}` }
- for (const tag of data.current_file.tags) {
- const tr = new_child_to('tr', table_current_tags);
- const td_checkbox = new_child_to('td', tr);
- td_checkbox.classList.add('tag_checkbox');
- const checkbox = new_child_to('input', td_checkbox);
- checkbox.type = 'checkbox';
- checkbox.name = 'tag_input';
- checkbox.value = tag;
- checkbox.checked = true;
- new_child_to('td', tr, tag); }
- const tr = new_child_to('tr', table_current_tags);
- new_child_to('td', tr, 'add:');
- const td_input = new_child_to('td', tr);
- const tag_input = new_child_to('input', td_input);
- tag_input.setAttribute('list', 'unused_tags');
- tag_input.name = 'tag_input';
- for (const tag of data.current_file.unused_tags) {
- const option = new_child_to('option', datalist_unused_tags, tag);
- option.value = tag; }
- btn_update.disabled = false;
- path_tags_update = `${PATH_PREFIX_TAGS_UPDATE}${data.current_file.digest}`; }});
-
-function update_tags() {
- var tags = [];
- for (const tag_input of document.getElementsByName('tag_input')) {
- if (tag_input.value && ('checkbox' != tag_input.type || tag_input.checked)) {
- tags.push(tag_input.value); }}
- send_to({tags: tags}, path_tags_update); }
+ a_file.href = `${PATH_PREFIX_FILE}${file.digest}`; }})
function redo_playlist() {
send_to({filter_path: document.getElementsByName('filter_path')[0].value,
td.screen_half { width: 50%; }
th.screen_half_titles { text-align: center; }
td.entry_control { width: 5em; }
-td.tag_checkboxes { width: 1em; }
{% endblock %}
<tr><td colspan=2><button onclick="redo_playlist()">reload</button></td></tr>
</table>
-<table>
-<tr><th colspan=2 class="screen_half_titles">current selection</th></tr>
-<tr><th>path:</th><td id="current_path"></td></tr>
-<tr><th>YouTube ID:</th><td id="current_yt_id"></td>
-</tr>
-<tr><th>tags</th><td><table id="current_tags"></table></td></tr>
-</table>
-<button id="btn_update_tags" onclick="update_tags()" disabled>update</button>
-<datalist id="unused_tags"></datalist>
-
</td>
<td class="screen_half">
'download': Path('dl'),
'events': Path('events'),
'file': Path('file'),
- 'file_tags': Path('file_tags'),
'files': Path('files'),
'missing': Path('missing'),
'player': Path('player'),
self._receive_files_command(postvars)
elif PAGE_NAMES['file'] == page_name:
self._receive_file_data(Hash.from_b64(toks_url[2]), postvars)
- elif PAGE_NAMES['file_tags'] == page_name:
- self._receive_file_tags(Hash.from_b64(toks_url[2]), postvars)
elif PAGE_NAMES['yt_queries'] == page_name:
self._receive_yt_query(QueryText(postvars.first_for('query')))
elif PAGE_NAMES['player'] == page_name:
self.server.player.inject_and_play(file)
self._redirect(Path(postvars.first_for('redir_target')))
- def _receive_file_tags(self, digest: Hash, postvars: _ReqMap) -> None:
- with DbConn() as conn:
- file = VideoFile.get_one(conn, digest)
- file.tags = {Tag(t) for t in postvars.all_for('tags')}
- file.save(conn)
- conn.commit()
- self._send_http('OK', code=200)
-
def _receive_file_data(self, digest: Hash, postvars: _ReqMap) -> None:
with DbConn() as conn:
file = VideoFile.get_one(conn, digest)
with DbConn() as conn:
playing = VideoFile.get_one(
conn, self.server.player.current_digest)
- last_playing_update = (
- VideoFile.last_updates_since_start.get(playing.digest, '')
- if playing
- else '')
- if playing and last_playing_update > playing.last_update:
- with DbConn() as conn:
- playing = VideoFile.get_one(conn, playing.digest)
- last_update = max(self.server.player.last_update,
- last_playing_update)
- if last_sent < last_update:
- last_sent = last_update
+ if last_sent < self.server.player.last_update:
+ last_sent = self.server.player.last_update
data = {
'last_update': self.server.player.last_update,
'running': self.server.player.is_running,
data['playlist_files'] = [
{'rel_path': str(f.rel_path), 'digest': f.digest.b64}
for f in self.server.player.files]
- data['link_prefix'] = str(PAGE_NAMES['file'])
- if playing:
- with DbConn() as conn:
- unused_tags = playing.unused_tags(conn)
- data['current_file'] = {
- 'digest': playing.digest.b64,
- 'rel_path': str(playing.rel_path),
- 'yt_id': playing.yt_id,
- 'tags': list(playing.tags),
- 'unused_tags': list(unused_tags)}
- data['yt_link_prefix'] = str(PAGE_NAMES['yt_result'])
try:
self.wfile.write(
f'data: {json_dumps(data)}\n\n'.encode())