Skip to content

Commit

Permalink
- Version 0.8.8.1
Browse files Browse the repository at this point in the history
- Fixing vlc terminataion on Windows
  • Loading branch information
s-n-g committed Dec 14, 2020
1 parent fe41bfa commit 1b20bf8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyradio.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" Copyright (C) 2011 Ben Dowling <http://www.coderholic.com/pyradio>
.\" This manual is freely distributable under the terms of the GPL.
.\"
.TH PYRADIO 1 "November 2020"
.TH PYRADIO 1 "December 2020"

.SH NAME
.PP
Expand Down
2 changes: 1 addition & 1 deletion pyradio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" pyradio -- Console radio player. "

version_info = (0, 8, 8)
version_info = (0, 8, 8, 1)

# Application state:
# New stable version: ''
Expand Down
22 changes: 13 additions & 9 deletions pyradio/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,10 @@ def format_station_line(self, id_in_list, pad, width):

class PyRadioBrowserInfoBrowser(PyRadioStationsBrowser):

BASE_URL = 'www.radio-browser.info'
BASE_URL = 'api.radio-browser.info'
TITLE = 'Radio Browser'

_open_url = \
'http://www.radio-browser.info/webservice/json/stations/topvote/100'
_open_url = 'https://de1.api.radio-browser.info/json/stations/topvote/100'
_open_headers = {'user-agent': 'PyRadio/dev'}

_raw_stations = []
Expand Down Expand Up @@ -224,15 +223,15 @@ def url(self, id_in_list):
if id_in_list < len(self._raw_stations):
if self._raw_stations[id_in_list]['real_url']:
if logger.isEnabledFor(logging.DEBUG):
logger.debug('Using existing url: "{}"'.format(self._raw_stations[id_in_list]['url']))
return self._raw_stations[id_in_list]['url']
logger.debug('Using existing url: "{}"'.format(self._raw_stations[id_in_list]['url_resolved']))
return self._raw_stations[id_in_list]['url_resolved']
else:
stationid = self._raw_stations[id_in_list]['id']
stationid = self._raw_stations[id_in_list]['stationuuid']
url = self.real_url(stationid)
if url:
if logger.isEnabledFor(logging.DEBUG):
logger.debug('URL retrieved: "{0}" <- "{1}'.format(url, self._raw_stations[id_in_list]['url']))
self._raw_stations[id_in_list]['url'] = url
self._raw_stations[id_in_list]['url_resolved'] = url
self._raw_stations[id_in_list]['real_url'] = True
self._raw_stations[id_in_list]['played'] = True
else:
Expand Down Expand Up @@ -324,11 +323,14 @@ def search(self, data):
post_data['hidebroken'] = 'true'
self._last_search = post_data
url = 'http://www.radio-browser.info/webservice/json/stations/search'
url = self._open_url
try:
# r = requests.get(url=url)
r = requests.get(url=url, headers=self._open_headers, json=post_data, timeout=self._search_timeout)
r.raise_for_status()
logger.error(r.text)
self._raw_stations = self._extract_data(json.loads(r.text))
logger.error('DE {}'.format(self._raw_stations))
except requests.exceptions.RequestException as e:
if logger.isEnabledFor(logging.ERROR):
logger.error(e)
Expand Down Expand Up @@ -450,10 +452,12 @@ def _extract_data(self, a_search_result):
for n in a_search_result:
ret.append({'name': n['name'].replace(',', ' ')})
ret[-1]['url'] = n['url']
ret[-1]['real_url'] = False
ret[-1]['url_resolved'] = n['url_resolved']
ret[-1]['real_url'] = True if n['url_resolved'] else False
ret[-1]['played'] = False
ret[-1]['hls'] = n['hls']
ret[-1]['id'] = n['id']
ret[-1]['stationuuid'] = n['stationuuid']
ret[-1]['countrycode'] = n['countrycode']
ret[-1]['country'] = n['country']
if isinstance(n['clickcount'], int):
# old API
Expand Down
27 changes: 19 additions & 8 deletions pyradio/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,23 +721,24 @@ def updateWinVLCStatus(self, *args):
if stop():
break
subsystemOut = fp.readline()
subsystemOut = subsystemOut.strip()
subsystemOut = subsystemOut.strip().replace(u'\ufeff', '')
subsystemOut = subsystemOut.replace("\r", "").replace("\n", "")
if subsystemOut == '':
continue
logger.error('DE >>> "{}"'.format(subsystemOut))
# logger.error('DE >>> "{}"'.format(subsystemOut))
if not self._is_accepted_input(subsystemOut):
continue
logger.error('DE --- accepted')
# logger.error('DE --- accepted')
if self.oldUserInput['Input'] != subsystemOut:
if stop():
break
if (logger.isEnabledFor(logging.DEBUG)):
if version_info < (3, 0):
disp = subsystemOut.encode('utf-8', 'replace').strip()
logger.debug("User input: {}".format(disp))
# logger.debug("User input: {}".format(disp))
else:
logger.debug("User input: {}".format(subsystemOut))
# logger.debug("User input: {}".format(subsystemOut))
pass
self.oldUserInput['Input'] = subsystemOut
if self.volume_string in subsystemOut:
if stop():
Expand Down Expand Up @@ -1171,8 +1172,10 @@ def close(self):
if self.process is not None:
if platform.startswith('win'):
try:
subprocess.Call(['Taskkill', '/PID', '{}'.format(self.process.pid), '/F'])
subprocess.Call(['Taskkill', '/PID', '{}'.format(self.process.pid), '/F', '/T'])
logger.error('Taskkill killed PID {}'.format(self.process.pid))
self.process = None
logger.error('***** self.process = None')
except:
logger.error('Taskkill failed to kill PID {}'.format(self.process.pid))
else:
Expand Down Expand Up @@ -1848,8 +1851,9 @@ def _stop(self):
return
if self.WIN:
if self.process:
logger.error('>>>> Terminating process')
self._req('quit')
threading.Thread(target=self._remove_vlc_stdout_log_file, args=()).start()
threading.Thread(target=self._remove_vlc_stdout_log_file, args=()).start()
else:
self._sendCommand("shutdown\n")
self._icy_data = {}
Expand Down Expand Up @@ -1991,6 +1995,9 @@ def _req(self, msg, ret_function=None, full=True):
sock.close()
except:
pass
if msg == 'quit':
self.process.terminate()
self.process = None
if ret_function:
ret_function(response)
return response
Expand Down Expand Up @@ -2021,7 +2028,11 @@ def _get_volume_response(self, msg):
if ind > -1:
vol = vol[:ind]
break
self.actual_volume = int(vol)
try:
self.actual_volume = int(vol)
except ValueError:
logger.error('DE _get_volume_response: ValueError: vol = {}'.format(vol))
return
logger.error('DE _get_volume_response: vol = {}'.format(vol))
break
if self.actual_volume == 0:
Expand Down
6 changes: 4 additions & 2 deletions pyradio/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,9 @@ def setStation(self, number):

def playSelectionBrowser(self):
self.log.display_help_message = False
self.log.write(msg=player_start_stop_token[0] + self._last_played_station[0] + '"')

# self.log.write(msg=player_start_stop_token[0] + self._last_played_station[0] + '"')

#### self._cnf.browsing_station_service = True
# Add a history item to preserve browsing_station_service
# Need to add TITLE, if service found
Expand Down Expand Up @@ -2842,7 +2844,7 @@ def to_time(secs):
delta = (d1 - d2).days

# PROGRAM DEBUG: Uncomment this to force check
delta=check_days
# delta=check_days
if delta < check_days:
clean_date_files(files)
if logger.isEnabledFor(logging.INFO):
Expand Down

0 comments on commit 1b20bf8

Please sign in to comment.