Skip to content

Commit

Permalink
only read stdout, dont read stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
back-to committed Jun 15, 2022
1 parent 4124fd8 commit cf5b345
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions liveproxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import subprocess
import sys
from http.server import BaseHTTPRequestHandler, HTTPServer
from select import select
from shutil import which
from socketserver import ThreadingMixIn
from time import time
Expand All @@ -21,8 +20,8 @@
errno.EPIPE,
)

_re_streamlink = re.compile(r'streamlink$', re.IGNORECASE)
_re_youtube_dl = re.compile(r'(?:youtube|yt)[_-]dl(?:p)?$', re.IGNORECASE)
_re_streamlink = re.compile(r'streamlink', re.IGNORECASE)
_re_youtube_dl = re.compile(r'(?:youtube|yt)[_-]dl(?:p)?', re.IGNORECASE)

log = logging.getLogger(__name__.replace('liveproxy.', ''))

Expand Down Expand Up @@ -110,20 +109,11 @@ def do_GET(self):

log.info(f'Stream started {random_id}')
try:
while True:
reads, _, _ = select([process.stdout.fileno(), process.stderr.fileno()], [], [])
for descriptor in reads:
# stdout
if descriptor == process.stdout.fileno():
read = process.stdout.readline()
if read:
self.wfile.write(read)
# stderr
if descriptor == process.stderr.fileno():
read = process.stderr.readline()
if read:
log.debug(f'{read[0:-1].decode("utf-8")}')
sys.stdout.flush()
while True:
read = process.stdout.readline()
if read:
self.wfile.write(read)
sys.stdout.flush()
if process.poll() is not None:
self.wfile.close()
break
Expand Down

0 comments on commit cf5b345

Please sign in to comment.