Skip to content

Commit 25f227a

Browse files
committed
Clean up logs when saving to db
parsing \r\n's to not show the detail of the youtubedl percent per percent
1 parent 1ea0c38 commit 25f227a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

youtube-dl-server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def dl_worker():
9898
job = Job(url, 0, "")
9999
db.insert_job(job)
100100
try:
101-
job.log = download(url, options)
101+
job.log = Job.clean_logs(download(url, options))
102102
job.status = 1
103103
except Exception as e:
104104
job.status = 2

youtube_dl_logdb.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sqlite3
3+
import re
34

45
STATUS_NAME =["Running",
56
"Completed",
@@ -12,6 +13,17 @@ def __init__(self, name, status, log):
1213
self.log = log
1314
self.last_update = ""
1415

16+
@staticmethod
17+
def clean_logs(logs):
18+
if not logs:
19+
return logs
20+
clean = ""
21+
for line in logs.split('\n'):
22+
line = re.sub('.*\r', '', line)
23+
if len(line) > 0:
24+
clean = '%s%s\n' % (clean, line)
25+
return clean
26+
1527
class JobsDB:
1628
def __init__(self, db_path, readonly=True):
1729
if not os.path.isfile(db_path):

0 commit comments

Comments
 (0)