Skip to content

Commit

Permalink
- Version 0.8.8-beta6
Browse files Browse the repository at this point in the history
- Fixing playback for m3u8 on vlc
- Fixing "-u" functionality on Windows
- Fixing "no player" messages
- Stopping runaway threads from displaying messages
  after the player is stopped
  • Loading branch information
s-n-g committed Nov 24, 2020
1 parent b2121fe commit 5a35351
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 99 deletions.
16 changes: 14 additions & 2 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
2020-11-17
* Versio 0.8.8-beta4
2020-11-23 s-n-g
* Version 0.8.8-beta6
* Fixing playback for m3u8 (vlc)
* Fixing "-u" functionality on Windows
* Fixing "no player" messages
* Stopping runaway threads from displaying messages
after the player is stopped

2020-11-23 s-n-g
* Version 0.8.8-beta5
* Adding VLC support on Windows

2020-11-17 s-n-g
* Version 0.8.8-beta4
* Adding the "Force http connections" configuration
option (#113)
* Fixed a couple of bugs
Expand Down
2 changes: 1 addition & 1 deletion pyradio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# New stable version: ''
# Beta version: 'betax', x=1,2,3...
# RC version: 'RCx', x=1,23...
app_state = 'beta5'
app_state = 'beta6'

__version__ = version = '.'.join(map(str, version_info))
__project__ = __name__
Expand Down
2 changes: 0 additions & 2 deletions pyradio/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,7 @@ def get_data_dict(data):
logger.info('Asked to stop after working on "{}"...'.format(an_item))
self._terminated = True
return
# print('I am here')
lock.acquire()
# print('I am here too')
callback(my_data, ret)
lock.release()

Expand Down
6 changes: 6 additions & 0 deletions pyradio/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ def BACKGROUND(): return 1
('Normal Cursor', 6, 0, 0),
('Active Cursor', 9, 0, 0),
('Edit Cursor', 8, 0, 0 ) )

""" Messages to display when player starts / stops
Used in log to stop runaway threads from printing
messages after playback is stopped """
player_start_stop_token = ('Initialization: "', ': Playback stopped')

22 changes: 22 additions & 0 deletions pyradio/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from sys import version_info
import logging
import threading
from .common import player_start_stop_token

logger = logging.getLogger(__name__)

Expand All @@ -22,6 +23,8 @@ class Log(object):

lock = threading.Lock()

_player_stopped = 0

def __init__(self):
self.width = None

Expand All @@ -45,9 +48,24 @@ def _do_i_print_last_char(self, first_print):
def write(self, msg=None, suffix=None, counter=None, help_msg=False, error_msg=False, notify_function=None):
if self.cursesScreen:
with self.lock:
if msg:
if player_start_stop_token[1] in msg:
self._player_stopped += 1
elif msg.startswith(player_start_stop_token[0]):
self._player_stopped = 0
if msg and self._player_stopped > 1:
""" Refuse to print anything if "Playback stopped"
was the last message printed
"""
if logger.isEnabledFor(logging.DEBUG):
logger.debug('Refusing to show message; player is stopped: "{}"'.format(msg))
#return
elif self._player_stopped == 1:
self._player_stopped = 2
if self.asked_to_stop:
self.asked_to_stop = False
self.counter = None
self._player_stopped = 0
return
#if logger.isEnabledFor(logging.DEBUG):
# logger.debug('before ----------------------------')
Expand Down Expand Up @@ -76,6 +94,7 @@ def write(self, msg=None, suffix=None, counter=None, help_msg=False, error_msg=F
if self.asked_to_stop:
self.asked_to_stop = False
self.counter = None
self._player_stopped = 0
return
""" update main message """
if self.msg:
Expand All @@ -101,6 +120,7 @@ def write(self, msg=None, suffix=None, counter=None, help_msg=False, error_msg=F
if self.asked_to_stop:
self.asked_to_stop = False
self.counter = None
self._player_stopped = 0
return
""" display suffix """
if self.suffix:
Expand Down Expand Up @@ -153,8 +173,10 @@ def write(self, msg=None, suffix=None, counter=None, help_msg=False, error_msg=F
if self.asked_to_stop:
self.asked_to_stop = False
self.counter = None
self._player_stopped = 0
return
self.cursesScreen.refresh()
#logger.error('DE _player_stopped = {}'.format(self._player_stopped))

def readline(self):
pass
4 changes: 1 addition & 3 deletions pyradio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ def shell():
sys.exit(1)

if args.use_player != '':
if not platform.startswith('win'):
requested_player = args.use_player
requested_player = args.use_player

if args.list is False and args.add is False:
print('Reading playlist...')
Expand Down Expand Up @@ -229,7 +228,6 @@ def print_playlist_selection_error(a_selection, cnf, ret, exit_if_malformed=True
if exit_if_malformed:
if ret == -1:
print('Error: playlist is malformed: "{}"'.format(a_selection))
#print('Error: playlist is malformed: "{}"'.format(args.stations))
sys.exit(1)

if ret == -2:
Expand Down
77 changes: 48 additions & 29 deletions pyradio/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ def _do_save_volume(self, config_string):
self.PROFILE_FROM_USER = True
return ret_string

def _stop_delay_thread(self):
if self.delay_thread is not None:
try:
self.delay_thread.cancel()
except:
pass
self.delay_thread = None

def _is_in_playback_token(self, a_string):
for a_token in self._playback_token_tuple:
if a_token in a_string:
Expand Down Expand Up @@ -511,6 +519,7 @@ def updateStatus(self, *args):
new_input = self.oldUserInput['Title']
self.outputStream.write(msg=new_input, counter='')
self.playback_is_on = True
self._stop_delay_thread()
if 'AO: [' in subsystemOut:
with self.status_update_lock:
if version_info > (3, 0):
Expand All @@ -535,14 +544,23 @@ def updateStatus(self, *args):
#logger.error("***** icy_entry")
title = self._format_title_string(subsystemOut)
ok_to_display = False
if not self.playback_is_on:
if logger.isEnabledFor(logging.INFO):
logger.info('*** updateStatus(): Start of playback detected (Icy-Title received) ***')
self.playback_is_on = True
if title[len(self.icy_title_prefix):].strip():
#self._stop_delay_thread()
#logger.error("***** updating title")
self.oldUserInput['Title'] = title
# make sure title will not pop-up while Volume value is on
if self.delay_thread is None:
ok_to_display = True
if ok_to_display and self.playback_is_on:
string_to_show = self.title_prefix + title
self.outputStream.write(msg=string_to_show, counter='')
else:
if logger.isEnabledFor(logging.debug):
logger.debug('***** Title change inhibited: ok_to_display = {0}, playbabk_is_on = {1}'.format(ok_to_display, self.playback_is_on))
else:
ok_to_display = True
if (logger.isEnabledFor(logging.INFO)):
Expand All @@ -560,10 +578,14 @@ def updateStatus(self, *args):
else:
for a_token in self.icy_audio_tokens.keys():
if a_token in subsystemOut:
logger.error(' DE token = "{}"'.format(a_token))
logger.error(' DE icy_audio_tokens[a_token] = "{}"'.format(self.icy_audio_tokens[a_token]))
if not self.playback_is_on:
if logger.isEnabledFor(logging.INFO):
logger.info('*** updateStatus(): Start of playback detected (Icy audio token received) ***')
self.playback_is_on = True
#logger.error(' DE token = "{}"'.format(a_token))
#logger.error(' DE icy_audio_tokens[a_token] = "{}"'.format(self.icy_audio_tokens[a_token]))
a_str = subsystemOut.split(a_token)
logger.error(' DE str = "{}"'.format(a_str))
#logger.error(' DE str = "{}"'.format(a_str))
with self.status_update_lock:
if self.icy_audio_tokens[a_token] == 'icy-br':
self._icy_data[self.icy_audio_tokens[a_token]] = a_str[1].replace('kbit/s', '')
Expand Down Expand Up @@ -742,7 +764,7 @@ def updateWinVLCStatus(self, *args):
except:
pass
if (not self.playback_is_on) and (logger.isEnabledFor(logging.INFO)):
logger.info('*** updateStatus(): Start of playback detected ***')
logger.info('*** updateWinVLCStatus(): Start of playback detected ***')
#if self.outputStream.last_written_string.startswith('Connecting to'):
if self.oldUserInput['Title'] == '':
new_input = 'Playing: "{}"'.format(self.name)
Expand All @@ -761,6 +783,10 @@ def updateWinVLCStatus(self, *args):
elif self._is_icy_entry(subsystemOut):
if stop():
break
if not self.playback_is_on:
if logger.isEnabledFor(logging.INFO):
logger.info('*** updateWinVLCStatus(): Start of playback detected (Icy-Title received) ***')
self.playback_is_on = True

#logger.error("***** icy_entry")
title = self._format_title_string(subsystemOut)
Expand Down Expand Up @@ -792,10 +818,14 @@ def updateWinVLCStatus(self, *args):
break
for a_token in self.icy_audio_tokens.keys():
if a_token in subsystemOut:
logger.error(' DE token = "{}"'.format(a_token))
logger.error(' DE icy_audio_tokens[a_token] = "{}"'.format(self.icy_audio_tokens[a_token]))
if not self.playback_is_on:
if logger.isEnabledFor(logging.INFO):
logger.info('*** updateWinVLCStatus(): Start of playback detected (Icy audio token received) ***')
self.playback_is_on = True
#logger.error(' DE token = "{}"'.format(a_token))
#logger.error(' DE icy_audio_tokens[a_token] = "{}"'.format(self.icy_audio_tokens[a_token]))
a_str = subsystemOut.split(a_token)
logger.error(' DE str = "{}"'.format(a_str))
#logger.error(' DE str = "{}"'.format(a_str))
with self.status_update_lock:
if self.icy_audio_tokens[a_token] == 'icy-br':
self._icy_data[self.icy_audio_tokens[a_token]] = a_str[1].replace('kbit/s', '')
Expand Down Expand Up @@ -988,23 +1018,24 @@ def _set_mpv_playback_is_on(self, stop):

def threadUpdateTitle(self, delay=1):
if self.oldUserInput['Title'] != '':
try:
self.delay_thread.cancel()
except:
pass
self._stop_delay_thread()
try:
self.delay_thread = threading.Timer(delay,
self.updateTitle,
[ self.outputStream,
self.title_prefix + self._format_title_string(self.oldUserInput['Title']) ]
None ]
)
self.delay_thread.start()
except:
if (logger.isEnabledFor(logging.DEBUG)):
logger.debug("delay thread start failed")

def updateTitle(self, *arg, **karg):
arg[0].write(msg=arg[1])
self._stop_delay_thread()
if arg[1]:
arg[0].write(msg=arg[1])
else:
arg[0].write(msg=self.title_prefix + self._format_title_string(self.oldUserInput['Title']))

def _is_icy_entry(self, a_string):
#logger.error("**** a_string = {}".format(a_string))
Expand Down Expand Up @@ -1044,6 +1075,7 @@ def play(self, name, streamUrl, encoding = ''):
self.show_volume = True
self.title_prefix = ''
self.playback_is_on = False
self.delay_thread = None
self.outputStream.write(msg='Station: "{}" - Opening connection...'.format(name), counter='')
if logger.isEnabledFor(logging.INFO):
logger.info('Selected Station: "{}"'.format(name))
Expand Down Expand Up @@ -1130,11 +1162,7 @@ def close(self):
self.connection_timeout_thread.join()
except:
pass
if self.delay_thread is not None:
try:
self.delay_thread.cancel()
except:
pass
self._stop_delay_thread()
if self.process is not None:
if platform.startswith('win'):
try:
Expand Down Expand Up @@ -1165,11 +1193,7 @@ def toggleMute(self):
self.muted = not self.muted
self._mute()
if self.muted:
if self.delay_thread is not None:
try:
self.delay_thread.cancel()
except:
pass
self._stop_delay_thread()
self.title_prefix = '[Muted] '
self.show_volume = False
else:
Expand Down Expand Up @@ -1691,7 +1715,6 @@ class VlcPlayer(Player):
WIN = False
if platform.startswith('win'):
WIN = True
logger.error('DE WIN = {}'.format(WIN))
PLAYER_CMD = "cvlc"
if WIN:
# TODO: search and finde vlc.exe
Expand All @@ -1708,8 +1731,6 @@ class VlcPlayer(Player):
else:
executable_found = False

print('executable: {}'.format(REAL_PLAYER_CMD))

if executable_found:
""" items of this tupple are considered icy-title
and get displayed after first icy-title is received """
Expand All @@ -1734,7 +1755,7 @@ class VlcPlayer(Player):
max_volume = 512

""" When found in station transmission, playback is on """
_playback_token_tuple = ('main audio ', 'Content-Type: audio' )
_playback_token_tuple = ('main audio ', 'Content-Type: audio', ' Segment #' )

""" Windows only variables """
_vlc_stdout_log_file = ''
Expand Down Expand Up @@ -1951,7 +1972,6 @@ def _req(self, msg, ret_function=None, full=True):
try:
while (True):
received = (sock.recv(4096)).decode()
#print('received: "{}"'.format(received))
response = response + received
if full:
if response.count("\r\n") > 1:
Expand All @@ -1963,7 +1983,6 @@ def _req(self, msg, ret_function=None, full=True):
break
except:
response = response + received
pass
sock.close()
except:
pass
Expand Down
Loading

0 comments on commit 5a35351

Please sign in to comment.