Skip to content

Commit

Permalink
- Version 0.8.8-beta4
Browse files Browse the repository at this point in the history
- finalizing force http connections and updating docs
  • Loading branch information
s-n-g committed Nov 17, 2020
1 parent c888f13 commit bc210b0
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
2020-11-05
2020-11-17
* Versio 0.8.8-beta4
* Adding the "Force http connections" configuration
option (#113)
* Fixed a couple of bugs
* Installation script will use Python 3 by default

2020-10-30 s-n-g
Expand Down
10 changes: 10 additions & 0 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ <h2 id="table-of-contents">Table of contents <span style="padding-left: 10px;"><
<li><a href="#moving-stations-around">Moving stations around</a></li>
<li><a href="#specifying-stations-encoding">Specifying stations’ encoding</a></li>
<li><a href="#player-detection-selection">Player detection / selection</a></li>
<li><a href="#player-connection-protocol">Player connection protocol</a></li>
<li><a href="#player-default-volume-level">Player default volume level</a></li>
<li><a href="#displaying-station-info">Displaying Station Info</a></li>
<li><a href="#copying-and-pasting---registers">Copying and pasting - Registers</a></li>
Expand Down Expand Up @@ -124,6 +125,7 @@ <h2 id="controls">Controls <span style="padding-left: 10px;"><sup style="font-si
&lt;n&gt;^U &lt;n&gt;^D Move station up / down. - -
&#39; \ y Get into Registers, Extra Commands y (yank) is not applicable -
and Yank modes, respectively
z Toggle &quot;Force http connections&quot; - -
? Show keys help [Valid] [Valid]
# Redraw window [Valid] [Valid]
Esc/q Quit - -
Expand Down Expand Up @@ -275,6 +277,14 @@ <h2 id="player-detection-selection">Player detection / selection <span style="pa
<pre>pyradio -u vlc,mplayer,mpv</pre>
<p>will instruct <strong>PyRadio</strong> to look for VLC, then MPlayer and finaly for MPV and use whichever it finds first; if none is found, the program will terminate with an error.</p>
<p style="margin: 1.5em 4em 0 4em; text-indent: -2.5em;"><strong>Note:</strong> The default player to use can also be set in <strong>PyRadio</strong>’s <a href="#config-file">configuration file</a>, parameter <strong>player</strong> (default value is <strong>mpv, mplayer, vlc</strong>).</p>
<h2 id="player-connection-protocol">Player connection protocol <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></style></h2>
<p>Most radio stations use plain old http protocol to broadcast, but some of them use https.</p>
<p>Experience has shown that playing a <strong>https</strong> radio station depends on the combination of the station’s configuration and the player used.</p>
<p>If such a station fails to play, one might as well try to use <strong>http</strong> protocol to connect to it.</p>
<p><strong>PyRadio</strong> provides a way to instruct the player used to do so; the “<em>Force http connections</em>” configuration parameter. If it is <em>False</em> (the default), the player will use whatever protocol the station proposes (either <strong>http</strong> or <strong>https</strong>). When changed to <strong>True</strong>, all connections will use the <strong>http</strong> protocol.</p>
<p>When the selected player is initialized (at program startup), it reads this configuration parameter and acts accordingly.</p>
<p>If the parameter has to be changed mid-session (without restarting the program), one would press “<em>z</em>” to display the “<em>Connection Type</em>” window, where the parameter’s value can be set as desired.</p>
<p style="margin: 1.5em 4em 0 4em; text-indent: -2.5em;"><strong>Note:</strong> Changes made using the “<em>Connection Type</em>” window are not stored; next time the program is executed, it will use whatever value the configuration parameter holds.</p>
<h2 id="player-default-volume-level">Player default volume level <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></style></h2>
<p>MPV and MPlayer, when started, use their saved (or default) volume level to play any multimedia content. Fortunately, this is not the case with VLC.</p>
<p>This introduces a problem to <strong>PyRadio</strong>: every time a user plays a station (i.e restarts playback), even though he may have already set the volume to a desired level, the playback starts at the player’s default level.</p>
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Ben Dowling - [https://github.com/coderholic](https://github.com/coderholic)
* [Moving stations around](#moving-stations-around)
* [Specifying stations' encoding](#specifying-stations-encoding)
* [Player detection / selection](#player-detection-selection)
* [Player connection protocol](#player-connection-protocol)
* [Player default volume level](#player-default-volume-level)
* [Displaying Station Info](#displaying-station-info)
* [Copying and pasting - Registers](#copying-and-pasting---registers)
Expand Down Expand Up @@ -112,6 +113,7 @@ J Create a jump tag
<n>^U <n>^D Move station up / down. - -
' \ y Get into Registers, Extra Commands y (yank) is not applicable -
and Yank modes, respectively
z Toggle "Force http connections" - -
? Show keys help [Valid] [Valid]
# Redraw window [Valid] [Valid]
Esc/q Quit - -
Expand Down Expand Up @@ -393,6 +395,22 @@ will instruct **PyRadio** to look for VLC, then MPlayer and finaly for MPV and u
**Note:** The default player to use can also be set in **PyRadio**'s [configuration file](#config-file), parameter **player** (default value is **mpv, mplayer, vlc**).


## Player connection protocol

Most radio stations use plain old http protocol to broadcast, but some of them use https.

Experience has shown that playing a **https** radio station depends on the combination of the station's configuration and the player used.

If such a station fails to play, one might as well try to use **http** protocol to connect to it.

**PyRadio** provides a way to instruct the player used to do so; the "*Force http connections*" configuration parameter. If it is *False* (the default), the player will use whatever protocol the station proposes (either **http** or **https**). When changed to **True**, all connections will use the **http** protocol.

When the selected player is initialized (at program startup), it reads this configuration parameter and acts accordingly.

If the parameter has to be changed mid-session (without restarting the program), one would press "*z*" to display the "*Connection Type*" window, where the parameter's value can be set as desired.

**Note:** Changes made using the "*Connection Type*" window are not stored; next time the program is executed, it will use whatever value the configuration parameter holds.

## Player default volume level

MPV and MPlayer, when started, use their saved (or default) volume level to play any multimedia content. Fortunately, this is not the case with VLC.
Expand Down
23 changes: 22 additions & 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 "October 2020"
.TH PYRADIO 1 "November 2020"

.SH NAME
.PP
Expand Down Expand Up @@ -459,6 +459,24 @@ will instruct \fBpyradio\fR to look for VLC, then MPlayer and finaly for MPV and
.IP \fBNote\fR
The default player to use can also be set in \fBpyradio\fR’s configuration file, parameter \fIplayer\fR (default value is \fImpv, mplayer, vlc\fR).


.SH PLAYER CONNECTION PROTOCOL

Most radio stations use plain old http protocol to broadcast, but some of them use https.

Experience has shown that playing a \fBhttps\fR radio station depends on the combination of the station's configuration and the player used.

If such a station fails to play, one might as well try to use \fBhttp\fR protocol to connect to it.

\fBpyradio\fR provides a way to instruct the player used to do so; the "\fIForce http connections\fR" configuration parameter. If it is \fIFalse\fR (the default), the player will use whatever protocol the station proposes (either \fBhttp\fR or \fBhttps\fR). When changed to \fBTrue\fR, all connections will use the \fBhttp\fR protocol.

When the selected player is initialized (at program startup), it reads this configuration parameter and acts accordingly.

If the parameter has to be changed mid-session (without restarting the program), one would press "\fIz\fR" to display the "\fIConnection Type\fR" window, where the parameter's value can be set as desired.

.IP \fBNote\fR
Changes made using the "\fIConnection Type\fR" window are not stored; next time the program is executed, it will use whatever value the configuration parameter holds.

.SH PLAYER DEFAULT VOLUME LEVEL
.PP
\fIMPV\fR and \fIMPlayer\fR, when started, use their saved (or default) volume level to play any multimedia content. Fortunately, this is not the case with \fIVLC\fR.
Expand Down Expand Up @@ -766,4 +784,7 @@ On \fBMac OS\fR, these file may be installed in \fI/usr/local/share/doc/pyradio\
\fBPeter Stevenson (2E0PGS)\fR\ \<\fIhttps://github.com/2E0PGS\fR\>,\ (2018)
.PP
\fBSpiros Georgaras\fR\ \<\fIhttps://github.com/s-n-g\fR\>,\ (2018-2020)
.PP
You can see a complete list of contributors at
https://github.com/coderholic/pyradio/graphs/contributors

2 changes: 1 addition & 1 deletion pyradio/config_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class PyRadioConfigWindow(object):
_help_text.append(['PyRadio will wait for this number of seconds to get a station/server message indicating that playback has actually started.', '|',
'If this does not happen within this number of seconds after the connection is initiated, PyRadio will consider the station unreachable, and display the "Failed to connect to: station" message.', '|', 'Press "h"/Left or "l"/Right to change value.',
'|', 'Valid values: 5 - 60', 'Default value: 10'])
_help_text.append(['Most radio stations use plain old http protocol to broadcast, but some of them use https.', '|', 'If this is enabled, all connections will use http; results depend on the combination of station/player.', '|', 'This value is read at program startup, use Ctrl-S to change its effect while mid-session.',
_help_text.append(['Most radio stations use plain old http protocol to broadcast, but some of them use https.', '|', 'If this parameter is enabled, all connections will use http; results depend on the combination of station/player.', '|', 'This value is read at program startup, use "z" to change its effect while mid-session.',
'|', 'Default value: False'])
_help_text.append(None)
_help_text.append(['The theme to be used by default.', '|',
Expand Down
69 changes: 69 additions & 0 deletions pyradio/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,4 +1049,73 @@ def keypress(self, char):
#self.show()
return self._get_result(ret)

class PyRadioConnectionType(object):

_title = ' Connection Type '
_text = 'Force http connections: '
_help_text = ' Help '

def __init__(self, parent, connection_type):
self._parent = parent
self.connection_type = connection_type

def show(self, parent=None):
if parent:
self._parent = parent
y, x = self._parent.getmaxyx()
new_y = int(y/2) - 2
new_x = int( (x - len(self._text) - 9 - 4) /2 )
self.MaxX = len(self._text) + 9 + 4
self._win = None
self._win = curses.newwin(10, self.MaxX, new_y, new_x)
self._win.bkgdset(' ', curses.color_pair(3))
self._win.erase()
self._win.box()

# show title
x = int((self.MaxX - len(self._title)) / 2)
self._win.addstr(0, x, self._title, curses.color_pair(4))

# show content
self._win.addstr(2, 4, self._text, curses.color_pair(5))
self._win.addstr('{}'.format(self.connection_type), curses.color_pair(4))

# show help
try:
self._win.addstr(4, 2, '─' * (self.MaxX - 4), curses.color_pair(3))
except:
self._win.addstr(4, 2, '─'.encode('utf-8') * (self.maxX - 6), curses.color_pair(3))
self._win.addstr(4, int((self.MaxX - len(self._help_text))/2), self._help_text, curses.color_pair(3))
self._win.addstr(5, 2, 'j k l SPACE', curses.color_pair(4))
self._win.addstr(6, 2, 'RIGHT UP DOWN', curses.color_pair(4))
self._win.addstr(' Toggle parameter', curses.color_pair(5))
self._win.addstr(7, 2, 'ENTER s', curses.color_pair(4))
self._win.addstr(' Accept parameter', curses.color_pair(5))
self._win.addstr(8, 2, 'Esc q h RIGHT', curses.color_pair(4))
self._win.addstr(' Cancel operation', curses.color_pair(5))


self._win.refresh()

def keypress(self, char):
""" Returns:
-1: Cancel
0: go on
1: Ok
"""
if char in (curses.KEY_ENTER, ord('\n'), ord('\r'), ord('s')):
return 1

elif char in (curses.KEY_EXIT, 27, ord('q'), ord('h'), curses.KEY_LEFT):
return -1

elif char in (ord('j'), ord('k'), ord('l'), ord(' '),
curses.KEY_RIGHT, curses.KEY_UP, curses.KEY_DOWN):
self.connection_type = not self.connection_type
self._win.addstr(2, len(self._text) + 3, '{}'.format(self.connection_type), curses.color_pair(3))
self._win.refresh()

return 0



44 changes: 41 additions & 3 deletions pyradio/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .window_stack import Window_Stack
from .config_window import *
from .log import Log
from .edit import PyRadioSearch, PyRadioEditor, PyRadioRenameFile
from .edit import PyRadioSearch, PyRadioEditor, PyRadioRenameFile, PyRadioConnectionType
from .themes import *
from .cjkwrap import cjklen
from . import player
Expand Down Expand Up @@ -269,6 +269,7 @@ def __init__(self, pyradio_config, play=False, req_player='', theme=''):
self.ws.PLAYLIST_COPY_ERROR: self._print_playlist_copy_error,
self.ws.PLAYLIST_RENAME_ERROR: self._print_playlist_rename_error,
self.ws.PLAYLIST_NOT_SAVED_ERROR_MODE: self._print_playlist_not_saved_error,
self.ws.CONNECTION_MODE: self._show_http_connection,
}

""" list of help functions """
Expand All @@ -286,6 +287,9 @@ def __init__(self, pyradio_config, play=False, req_player='', theme=''):
self.ws.SELECT_ENCODING_MODE: self._show_config_encoding_help,
self.ws.EDIT_STATION_ENCODING_MODE: self._show_config_encoding_help,
self.ws.LINE_EDITOR_HELP_MODE: self._show_line_editor_help,
self.ws.REGISTER_HELP_MODE: self._show_register_help,
self.ws.EXTRA_COMMANDS_HELP_MODE: self._show_extra_commands_help,
self.ws.YANK_HELP_MODE: self._show_yank_help,
}

""" search classes
Expand Down Expand Up @@ -1405,7 +1409,9 @@ def _show_main_help_page_3(self):
a-z| / |0-9 |Copy station to named register.
!Registe mode (')
' |Open registers list.
a-z| / |0-9 |Open named register."""
a-z| / |0-9 |Open named register.
!Connection type
z |Toggle "Force http connections" """
self._show_help(txt, mode_to_set=self.ws.MAIN_HELP_MODE_PAGE_3, reset_metrics=False)

def _show_playlist_help(self):
Expand Down Expand Up @@ -1654,7 +1660,6 @@ def _show_extra_commands_help(self):
self._show_help(txt, mode_to_set=self.ws.EXTRA_COMMANDS_HELP_MODE, caption=' Extra Commands Help ')

def _show_yank_help(self):
pass
txt = """ENTER |Copy station to unnamed register.
a-z| / |0-9 |Copy station to named register.
Expand Down Expand Up @@ -4088,6 +4093,7 @@ def keypress(self, char):

elif self.ws.operation_mode == self.ws.ASK_TO_SAVE_PLAYLIST_WHEN_EXITING_MODE:
if char in (ord('y'), ord('Y')):
self.ws.close_window()
if not self._cnf.locked and char == ord('Y'):
self._cnf.auto_save_playlist = True
ret = self.saveCurrentPlaylist()
Expand Down Expand Up @@ -4238,6 +4244,21 @@ def keypress(self, char):
self.refreshBody()
return

elif self.ws.operation_mode == self.ws.CONNECTION_MODE:
ret = self._connection_type_edit.keypress(char)
if ret == -1:
# Cancel
self.ws.close_window()
self._connection_type_edit = None
pass
elif ret == 1:
# changed
self.ws.close_window()
self.player.force_http = self._connection_type_edit.connection_type
self._connection_type_edit = None
self.refreshBody()
return

elif self.ws.operation_mode in self.ws.PASSIVE_WINDOWS:
if self.ws.operation_mode in (self.ws.MAIN_HELP_MODE,
self.ws.MAIN_HELP_MODE_PAGE_2,
Expand Down Expand Up @@ -4581,7 +4602,19 @@ def keypress(self, char):
curses.ungetch('y')
return

elif char in (ord('z'), ):
# change force http
self._random_requested = False
self.jumpnr = ''
self._cnf.jump_tag = -1
self._update_status_bar_right(status_suffix='')
self.ws.operation_mode = self.ws.CONNECTION_MODE
self._connection_type_edit = PyRadioConnectionType(parent=self.bodyWin,connection_type=self.player.force_http)
self._connection_type_edit.show()
return

elif char == ord('J'):
self._random_requested = False
self.jumpnr = ''
# tag for jump
self._cnf.jump_tag = self.selection
Expand All @@ -4590,6 +4623,7 @@ def keypress(self, char):

elif char in (curses.ascii.NAK, 21):
# ^U, move station Up
self._random_requested = False
if self.jumpnr:
self._cnf.jump_tag = int(self.jumpnr) - 1
self._move_station(-1)
Expand All @@ -4600,6 +4634,7 @@ def keypress(self, char):

elif char in (curses.ascii.EOT, 4):
# ^D, move station Down
self._random_requested = False
if self.jumpnr:
self._cnf.jump_tag = int(self.jumpnr) - 1
self._move_station(1)
Expand Down Expand Up @@ -5201,6 +5236,9 @@ def _search_sublist(self, a_list, ind, a_search):
except ValueError as e:
return -1

def _show_http_connection(self):
self._connection_type_edit.show(parent=self.bodyWin)

"""''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Windows only section
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''"""
Expand Down
2 changes: 2 additions & 0 deletions pyradio/window_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Window_Stack_Constants(object):
STATION_INFO_MODE = 58
NEW_PLAYLIST_MODE = 59
RENAME_PLAYLIST_MODE = 60
CONNECTION_MODE = 61
MAIN_HELP_MODE = 100
MAIN_HELP_MODE_PAGE_2 = 101
MAIN_HELP_MODE_PAGE_3 = 102
Expand Down Expand Up @@ -164,6 +165,7 @@ class Window_Stack_Constants(object):
PLAYLIST_COPY_ERROR: 'PLAYLIST_COPY_ERROR',
PLAYLIST_RENAME_ERROR: 'PLAYLIST_RENAME_ERROR',
PLAYLIST_NOT_SAVED_ERROR_MODE: 'PLAYLIST_NOT_SAVED_ERROR_MODE',
CONNECTION_MODE: 'CONNECTION_MODE',
}

''' When PASSIVE_WINDOWS target is one of them,
Expand Down

0 comments on commit bc210b0

Please sign in to comment.