Skip to content

Commit

Permalink
fixed log page
Browse files Browse the repository at this point in the history
  • Loading branch information
blastbeng committed Oct 8, 2024
1 parent 6778b66 commit c752b4d
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 252 deletions.
19 changes: 10 additions & 9 deletions spotisub/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,10 @@ def insert_song(playlist_info, subsonic_track,
else:
conn.rollback()
return None


else:
conn.rollback()
return None
else:
conn.rollback()
return None
Expand Down Expand Up @@ -979,21 +982,21 @@ def insert_spotify_song(conn, artist_spotify, track_spotify):
song_db = select_spotify_song_by_uri(conn, track_spotify["uri"])
song_uuid = None
if song_db is None:
song_uuid = str(uuid.uuid4().hex)
album = None
if "album" in track_spotify:
album = insert_spotify_album(conn, track_spotify["album"])
if album is not None:
return_dict["album_ignored"] = (album.ignored == 1)
stmt = insert(
dbms.spotify_song).values(
uuid=song_uuid,
uuid=str(uuid.uuid4().hex),
album_uuid=album.uuid,
title=track_spotify["name"],
spotify_uri=track_spotify["uri"])
stmt.compile()
conn.execute(stmt)
return_dict["song_uuid"] = song_uuid
song_db = select_spotify_song_by_uri(conn, track_spotify["uri"])
return_dict["song_uuid"] = song_db.uuid
return_dict["song_ignored"] = False
elif song_db is not None and song_db.uuid is not None:
return_dict["song_uuid"] = song_db.uuid
Expand Down Expand Up @@ -1052,10 +1055,9 @@ def insert_spotify_artist(conn, artist_spotify):
"""insert spotify artist"""
artist_db = select_spotify_artist_by_uri(conn, artist_spotify["uri"])
if artist_db is None:
artist_uuid = str(uuid.uuid4().hex)
stmt = insert(
dbms.spotify_artist).values(
uuid=artist_uuid,
uuid=str(uuid.uuid4().hex),
name=artist_spotify["name"],
spotify_uri=artist_spotify["uri"])
stmt.compile()
Expand All @@ -1068,15 +1070,14 @@ def insert_spotify_album(conn, album_spotify):
"""insert spotify artist"""
album = select_spotify_album_by_uri(conn, album_spotify["uri"])
if album is None:
album_uuid = str(uuid.uuid4().hex)
stmt = insert(
dbms.spotify_album).values(
uuid=album_uuid,
uuid=str(uuid.uuid4().hex),
name=album_spotify["name"],
spotify_uri=album_spotify["uri"])
stmt.compile()
conn.execute(stmt)
return select_spotify_album_by_uuid(conn, album_uuid)
return select_spotify_album_by_uri(conn, album_spotify["uri"])
return album


Expand Down
34 changes: 30 additions & 4 deletions spotisub/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import math
import string
import urllib
import subprocess
from threading import Lock
from time import sleep
Expand Down Expand Up @@ -77,7 +78,7 @@ def all_exception_handler(error):
api = Api(blueprint, doc='/docs/')
spotisub.register_blueprint(blueprint)

socketio = SocketIO(spotisub, async_mode=None)
socketio = SocketIO(spotisub, async_mode=None, logger=False, engineio_logger=False)
thread = None
thread_lock = Lock()

Expand Down Expand Up @@ -389,8 +390,13 @@ def tasks():
@login_required
def logs():
title = 'Logs'
array_lines = []
with open(os.path.abspath(os.curdir) + '/cache/spotisub.log', 'r') as file_init:
for line in file_init:
array_lines.append(line.strip())
return render_template('logs.html',
title=title)
title=title,
lines = array_lines)


@socketio.event
Expand Down Expand Up @@ -437,8 +443,28 @@ def poll_tasks():
emit('tasks_response', generator.get_tasks(), namespace='/', broadcast=True)
socketio.sleep(5)

def poll_log():
return "work in progress"
def poll_log():
with spotisub.test_request_context('/'):
with open(os.path.abspath(os.curdir) + '/cache/spotisub.log', 'rt') as file:
seek = 0
sleep_t = None

while True:
file.seek(seek)
line = file.readline()
where = file.tell()

if line:
if seek != where:
sleep_t = None
emit('log_response', {'data': line.strip(), 'status': 1}, namespace='/', broadcast=True)
else:
sleep_t = 0.04

seek = where

if sleep_t:
sleep(sleep_t)


@spotisub.route('/ignore/<string:type>/<string:uuid>/<int:value>/')
Expand Down
30 changes: 20 additions & 10 deletions spotisub/static/css/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,23 @@ progress[value]::-webkit-progress-value {
border-color: black;
}

.MenuContent-menuContent-Log {
z-index: 2000;
display: flex;
flex-direction: column;
background-color: transparent;
line-height: 20px;
position: absolute;
max-height: 352px;
width: 300px;
will-change: transform;
bottom: 5%;
right: 1%;
color: white;

border: none;
}

.MenuContent-menuContent-rescan {
z-index: 2000;
display: flex;
Expand Down Expand Up @@ -809,20 +826,13 @@ progress[value]::-webkit-progress-value {

.output-log-div{
width: 100%;
height: 100%;
padding: 0px;
overflow-x: auto;
display: inline;
margin: 0px;
padding: 0px;
overflow: scroll;
display: block;
}
.output-log-pre{
width: 100%;
height: 100%;
padding: 0px;
display: inline;
margin: 0px;
padding: 0px;
overflow: hidden;
list-style-type: none;
}

Expand Down
8 changes: 8 additions & 0 deletions spotisub/static/js/logs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
$(document).ready(function() {
var msgdiv = document.getElementById('output-log-div');
msgdiv.scrollIntoView(false);
var header_baseh = $("#header-base").height();
var height_def = $(window).height() - header_baseh;
msgdiv.style.height = height_def + "px";
msgdiv.scrollTop = msgdiv.scrollHeight;
socket.on('log_response', function(msg, cb) {
if (msg.status == 1) {
var ul = document.getElementById('output-log');
var li = document.createElement("li");
li.appendChild(document.createTextNode(msg.data));
ul.appendChild(li);
var msgdiv = document.getElementById('output-log-div');
msgdiv.scrollTop = msgdiv.scrollHeight;
}
});
});
4 changes: 2 additions & 2 deletions spotisub/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@
{% else %}
<ul class="collapse list-unstyled" id="systemSubMenu">
{% endif %}
{% if title == "Status" %}
<!--{% if title == "Status" %}
<li class="active">
{% else %}
<li>
{% endif %}
<a href="#">Status</a>
</li>
</li>-->
{% if title == "Tasks" %}
<li class="active">
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion spotisub/templates/header.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul class="pagination">
<ul id="header-base" class="pagination">
<li>
<a href="{{ url_for('overview') }}"><img src="{{ url_for('static', filename='img/logo.png') }}" alt="Spotisub" width="34px" height="34px" id="logo" class="logo">
</img></a>
Expand Down
9 changes: 7 additions & 2 deletions spotisub/templates/logs.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
{% include '_flash_message.html' %}
<!-- End of flash message -->
{% include 'header.html' %}
<div class="output-log-div">
{% include 'toolbar.html'%}
<div id="output-log-div" class="output-log-div">
<ul id="output-log" class="output-log-pre">
<li></li>
{% for line in lines %}
<li>
{{ line }}
</li>
{% endfor %}
</ul>
</div>
{% endblock %}
Loading

0 comments on commit c752b4d

Please sign in to comment.