Skip to content

Commit 6e204b3

Browse files
committed
- New stations will be integrated into user's stations file, after
confirmation is given - Fixing install.py
1 parent 3ffc090 commit 6e204b3

14 files changed

+235
-59
lines changed

Changelog

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
2021-03-30 s-n-g
1+
2021-04-02 s-n-g
22
* Implemented a simplified method to install, update, uninstall.
33
* PyRadio will detect its player abnormal termination.
44
* Player's connection timeout can now be disabled. Once a player is
55
started, it will be considered to be connected immediately.
6+
* stations.csv changes can now be integrated into user's stations.csv
67
* BUG FIX: Active players parameter list is always synchronized to saved.
78
* BUG FIX: Clicking on empty space (past last station) will not crash pyradio.
89

README.html

+12-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<title>PyRadio README</title>
88
<style>
99
html {margin: 2em;}
10+
body {width: 750px; margin: auto;}
1011
h2 {margin-top: 2.5em; border-bottom:1px solid SaddleBrown; color: SaddleBrown;}
1112
h3 {margin-top: 2em; color: SaddleBrown;}
1213
h4 {margin-top: 2em; color: SaddleBrown;}
@@ -33,16 +34,17 @@ <h1 style="color: SaddleBrown"id="pyradio">PyRadio</h1>
3334
<p>Command line internet radio player.</p>
3435
<p>Ben Dowling - <a target="_blank" href="https://github.com/coderholic">https://github.com/coderholic</a></p>
3536
<h2 id="table-of-contents">Table of Contents <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></style></h2>
37+
<h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></style></h2>
3638
<!-- vim-markdown-toc Marked -->
3739
<ul>
38-
<li><a href="#requirements">Requirements</a></li>
3940
<li><a href="#installation">Installation</a></li>
4041
<li><a href="#command-line-options">Command line options</a></li>
4142
<li><a href="#controls">Controls</a></li>
4243
<li><a href="#pyradio&#39;s-modes">PyRadio’s Modes</a></li>
4344
<li><a href="#config-file">Config file</a></li>
4445
<li><a href="#about-playlist-files">About Playlist files</a>
4546
<ul>
47+
<li><a href="#integrating-new-stations">Integrating new stations</a></li>
4648
<li><a href="#specifying-a-playlist-to-load-(command-line)">Specifying a playlist to load (command line)</a></li>
4749
<li><a href="#managing-playlists-(within-pyradio)">Managing playlists (within PyRadio)</a></li>
4850
<li><a href="#managing-%22foreign%22-playlists">Managing “foreign” playlists</a></li>
@@ -95,13 +97,12 @@ <h2 id="table-of-contents">Table of Contents <span style="padding-left: 10px;"><
9597
<li><a href="#acknowledgment">Acknowledgment</a></li>
9698
</ul>
9799
<!-- vim-markdown-toc -->
98-
<h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></style></h2>
99100
<ul>
100-
<li>python 2.7+/3.5+
101+
<li>python 2.7/3.5+
101102
<ul>
102103
<li>requests</li>
103104
</ul></li>
104-
<li>MPV, MPlayer or VLC installed and in your path.</li>
105+
<li>MPV, MPlayer or VLC installed and in your path</li>
105106
</ul>
106107
<h2 id="installation">Installation <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></style></h2>
107108
<p>The best way to install <strong>PyRadio</strong> is via a distribution package, if one exists (e.g. <em>Arch Linux</em> and derivatives can install <a target="_blank" href="https://aur.archlinux.org/packages/pyradio-git/">pyradio-git</a> from AUR).</p>
@@ -229,8 +230,12 @@ <h2 id="about-playlist-files">About Playlist files <span style="padding-left: 10
229230
<p><strong>PyRadio</strong> reads the stations to use from a CSV file, where each line contains two columns, the first being the station name and the second being the stream URL.</p>
230231
<p>Optionally, a third column can be inserted, stating the encoding used by the station (more on this at <a href="#specifying-stations-encoding">Specifying stations’ encoding</a>).</p>
231232
<p><strong>PyRadio</strong> will by default load the user’s stations file (e.g. <em>~/.config/pyradio/stations.csv</em>) to read the stations from. If this file is not found, it will be created and populated with a default set of stations.</p>
232-
<p style="margin: 1.5em 4em 0 4em; text-indent: -2em;"><strong>Tip:</strong> If you already have a custom <em>stations.csv</em> file, but want to update it with <strong>PyRadio</strong>’s default one, you just rename it, run <strong>PyRadio</strong> (so that the default one get created) and then merge the two files.</p>
233233
<p style="margin: 1.5em 4em 0 4em; text-indent: -2.5em;"><strong>Note:</strong> Older versions used to use <strong>~/.pyradio</strong> as default stations file. If this file is found, it will be copied to use’s config directory (e.g. <strong>~/.config/pyradio</strong>) and renamed to <strong>stations.csv</strong> or if this file exists, to <strong>pyradio.csv</strong>. In this case, this file will be the default one.</p>
234+
<h3 id="integrating-new-stations">Integrating new stations</h3>
235+
<p>When the package’s “<em>stations.csv</em>” files is updated, the changes it has will not automatically appear in the user’s stations file.</p>
236+
<p>What <strong>PyRadio</strong> will do is inform the user that these changes do exist and give him a chance to <strong>integrate</strong> these changes to his stations file, by appending the new stations to the file.</p>
237+
<p>When this is done, the first added station will be selected so that the user can inspect the changes and decide to keep or delete the new stations.</p>
238+
<p><strong>PyRadio</strong> will only add stations to the user’s stations file; no station will be deleted as a result of this procedure.</p>
234239
<h3 id="specifying-a-playlist-to-load-command-line">Specifying a playlist to load (command line)</h3>
235240
<p><strong>PyRadio</strong> will normally load its default playlist file, as described above, upon its execution. A different file can be loaded when the <strong>-s</strong> command line option is used.</p>
236241
<p>The <strong>-s</strong> option will accept:</p>
@@ -577,8 +582,8 @@ <h2 id="todo">TODO <span style="padding-left: 10px;"><sup style="font-size: 50%"
577582
Players extra parameters (<a target="_blank" href="https://github.com/coderholic/pyradio/issues/118">#118</a>) - v. 0.8.8.3</li>
578583
<li><input type="checkbox" disabled="" checked="" />
579584
New player selection configuration window (<a target="_blank" href="https://github.com/coderholic/pyradio/issues/118">#118</a>) - v. 0.8.8.3</li>
580-
<li><input type="checkbox" disabled="" />
581-
Notify the user that the package’s stations.csv has changed</li>
585+
<li><input type="checkbox" disabled="" checked="" />
586+
Notify the user that the package’s stations.csv has changed -v 0.8.9</li>
582587
<li><input type="checkbox" disabled="" checked="" />
583588
Update / uninstall using command line parameters (-U / -R) - v. 0.8.9</li>
584589
<li><input type="checkbox" disabled="" />

README.md

+15-9
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ Command line internet radio player.
55
Ben Dowling - [https://github.com/coderholic](https://github.com/coderholic)
66

77
## Table of Contents
8-
8+
## Requirements
99
<!-- vim-markdown-toc Marked -->
1010

11-
* [Requirements](#requirements)
1211
* [Installation](#installation)
1312
* [Command line options](#command-line-options)
1413
* [Controls](#controls)
1514
* [PyRadio's Modes](#pyradio's-modes)
1615
* [Config file](#config-file)
1716
* [About Playlist files](#about-playlist-files)
17+
* [Integrating new stations](#integrating-new-stations)
1818
* [Specifying a playlist to load (command line)](#specifying-a-playlist-to-load-(command-line))
1919
* [Managing playlists (within PyRadio)](#managing-playlists-(within-pyradio))
2020
* [Managing "foreign" playlists](#managing-"foreign"-playlists)
@@ -53,11 +53,9 @@ Ben Dowling - [https://github.com/coderholic](https://github.com/coderholic)
5353

5454
<!-- vim-markdown-toc -->
5555

56-
## Requirements
57-
58-
* python 2.7+/3.5+
56+
* python 2.7/3.5+
5957
- requests
60-
* MPV, MPlayer or VLC installed and in your path.
58+
* MPV, MPlayer or VLC installed and in your path
6159

6260
## Installation
6361

@@ -219,10 +217,18 @@ Optionally, a third column can be inserted, stating the encoding used by the sta
219217

220218
**PyRadio** will by default load the user's stations file (e.g. *~/.config/pyradio/stations.csv*) to read the stations from. If this file is not found, it will be created and populated with a default set of stations.
221219

222-
**Tip:** If you already have a custom *stations.csv* file, but want to update it with **PyRadio**'s default one, you just rename it, run **PyRadio** (so that the default one get created) and then merge the two files.
220+
**Note:** Older versions used to use **~/.pyradio** as default stations file. If this file is found, it will be copied to use's config directory (e.g. **~/.config/pyradio**) and renamed to **stations.csv** or if this file exists, to **pyradio.csv**. In this case, this file will be the default one.
221+
223222

223+
### Integrating new stations
224224

225-
**Note:** Older versions used to use **~/.pyradio** as default stations file. If this file is found, it will be copied to use's config directory (e.g. **~/.config/pyradio**) and renamed to **stations.csv** or if this file exists, to **pyradio.csv**. In this case, this file will be the default one.
225+
When the package's "*stations.csv*" files is updated, the changes it has will not automatically appear in the user's stations file.
226+
227+
What **PyRadio** will do is inform the user that these changes do exist and give him a chance to **integrate** these changes to his stations file, by appending the new stations to the file.
228+
229+
When this is done, the first added station will be selected so that the user can inspect the changes and decide to keep or delete the new stations.
230+
231+
**PyRadio** will only add stations to the user's stations file; no station will be deleted as a result of this procedure.
226232

227233
### Specifying a playlist to load (command line)
228234

@@ -750,7 +756,7 @@ Having said that, if you are not packaging for a specific distribution, please d
750756
- [x] Basic mouse support ([#119](https://github.com/coderholic/pyradio/issues/119)) - v. 0.8.8.3
751757
- [x] Players extra parameters ([#118](https://github.com/coderholic/pyradio/issues/118)) - v. 0.8.8.3
752758
- [x] New player selection configuration window ([#118](https://github.com/coderholic/pyradio/issues/118)) - v. 0.8.8.3
753-
- [ ] Notify the user that the package's stations.csv has changed
759+
- [x] Notify the user that the package's stations.csv has changed -v 0.8.9
754760
- [x] Update / uninstall using command line parameters (-U / -R) - v. 0.8.9
755761
- [ ] Use Radio Browser service ([#80](https://github.com/coderholic/pyradio/issues/80) [#93](https://github.com/coderholic/pyradio/issues/93) [#112](https://github.com/coderholic/pyradio/issues/112))
756762

build.html

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<title>PyRadio Build Instructions</title>
88
<style>
99
html {margin: 2em;}
10+
body {width: 750px; margin: auto;}
1011
h2 {margin-top: 2.5em; border-bottom:1px solid SaddleBrown; color: SaddleBrown;}
1112
h3 {margin-top: 2em; color: SaddleBrown;}
1213
h4 {margin-top: 2em; color: SaddleBrown;}

devel/pre-commit

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#!/bin/bash
2+
# update stations_updated in __init.py
3+
ST=$(git status | grep pyradio/stations.csv)
4+
if [ -z "$ST" ];then
5+
sed -i 's/stations_updated = .*/stations_updated = False/' pyradio/__init__.py
6+
else
7+
sed -i 's/stations_updated = .*/stations_updated = True/' pyradio/__init__.py
8+
fi
9+
10+
211
# convert TABs to SPACEs in Changelog
312
sed -i 's/\t/ /g' Changelog
13+
14+
415
# Create HTML file from md files
516
for afile in README.md build.md windows.md windows-mplayer.md
617
do
@@ -29,6 +40,7 @@ do
2940
sed -i '/<title>/a \
3041
<style> \
3142
html {margin: 2em;} \
43+
body {width: 750px; margin: auto;} \
3244
h2 {margin-top: 2.5em; border-bottom:1px solid SaddleBrown; color: SaddleBrown;} \
3345
h3 {margin-top: 2em; color: SaddleBrown;} \
3446
h4 {margin-top: 2em; color: SaddleBrown;} \

pyradio/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# Set it to True if new stations have been
1212
# added to the package's stations.csv
13-
stations_updated = True
13+
stations_updated = False
1414

1515

1616
__version__ = version = '.'.join(map(str, version_info))

pyradio/config

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ theme = dark
8080
# Transparency setting
8181
# If False, theme colors will be used.
8282
# If True and a compositor is running, the stations' window
83-
# background will be transparent. If True and a compositor is
83+
# background will be transparent. If True and a compositor is
8484
# not running, the terminal's background color will be used.
8585
# Valid values: True, true, False, false
8686
# Default value: False

pyradio/config.py

+87-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from shutil import copyfile, move
1313
import threading
1414
from copy import deepcopy
15-
from pyradio import version, app_state
15+
from pyradio import version, app_state, stations_updated
1616

1717
from .browser import PyRadioStationsBrowser, probeBrowsers
1818
HAS_REQUESTS = True
@@ -90,6 +90,9 @@ class PyRadioStations(object):
9090
''' set to True if a stations.csv is found in user's folder '''
9191
_user_csv_found = False
9292

93+
''' mark changed package stations.csv '''
94+
_integrate_stations = False
95+
9396
def __init__(self, stationFile=''):
9497
if platform.startswith('win'):
9598
self._open_string_id = 1
@@ -123,6 +126,22 @@ def __init__(self, stationFile=''):
123126
self._move_old_csv(self.stations_dir)
124127
self._check_stations_csv(self.stations_dir, self.root_path)
125128

129+
@property
130+
def integrate_stations(self):
131+
return self._integrate_stations
132+
133+
@integrate_stations.setter
134+
def user_has_stations_csv(self, val):
135+
raise ValueError('parameter is read only')
136+
137+
@property
138+
def user_has_stations_csv(self):
139+
return self._user_csv_found
140+
141+
@user_has_stations_csv.setter
142+
def user_has_stations_csv(self, val):
143+
raise ValueError('parameter is read only')
144+
126145
@property
127146
def is_register(self):
128147
return self._ps.is_register
@@ -380,6 +399,40 @@ def _get_playlist_abspath_from_data(self, stationFile=''):
380399
else:
381400
return '', -2
382401

402+
def _package_stations(self):
403+
''' read package stations.csv file '''
404+
with open(self.root_path, 'r') as cfgfile:
405+
for row in csv.reader(filter(lambda row: row[0]!='#', cfgfile), skipinitialspace=True):
406+
if not row:
407+
continue
408+
try:
409+
name, url = [s.strip() for s in row]
410+
yield [name, url, '', '']
411+
except:
412+
try:
413+
name, url, enc = [s.strip() for s in row]
414+
yield [name, url, enc, '']
415+
except:
416+
name, url, enc, onl = [s.strip() for s in row]
417+
yield [name, url, enc, onl]
418+
419+
def integrate_playlists(self):
420+
''''''
421+
422+
''' get user station urls '''
423+
self.added_stations = 0
424+
urls = []
425+
for n in self.stations:
426+
urls.append(n[1])
427+
if logger.isEnabledFor(logging.DEBUG):
428+
logger.debug('----==== Stations integration ====----')
429+
for a_pkg_station in self._package_stations():
430+
if a_pkg_station[1] not in urls:
431+
self.stations.append(a_pkg_station)
432+
self.added_stations += 1
433+
if logger.isEnabledFor(logging.DEBUG):
434+
logger.debug('Added: {0} - {1}'.format(self.added_stations, a_pkg_station))
435+
383436
def read_playlist_file(self, stationFile='', is_register=False):
384437
''' Read a csv file
385438
Returns: number
@@ -460,6 +513,37 @@ def read_playlist_file(self, stationFile='', is_register=False):
460513
if logger.isEnabledFor(logging.DEBUG):
461514
logger.debug('read_playlist_file: Playlist version: {}'.format(self._playlist_version_to_string[self._playlist_version]))
462515
self.jump_tag = -1
516+
517+
''' check for package's stations.csv change '''
518+
delete_ver_files = False
519+
if self._user_csv_found:
520+
if stationFile == path.join(self.stations_dir, 'stations.csv'):
521+
if self.current_pyradio_version is None:
522+
self.get_pyradio_version()
523+
ver_file = path.join(self.stations_dir, '.' + self.current_pyradio_version + '.ver')
524+
if stations_updated:
525+
if not path.exists(ver_file):
526+
import filecmp
527+
if not filecmp.cmp(stationFile, self.root_path):
528+
''' need to ask the user to integrate stations '''
529+
self._integrate_stations = True
530+
delete_ver_files = True
531+
if logger.isEnabledFor(logging.DEBUG):
532+
logger.debug('Stations integration is due!')
533+
else:
534+
''' delete all ver files and create current '''
535+
delete_ver_files = True
536+
if delete_ver_files:
537+
files = glob.glob(path.join(self.stations_dir, '.*.ver'))
538+
if files:
539+
for a_file in files:
540+
try:
541+
remove(a_file)
542+
except:
543+
pass
544+
with open(ver_file, 'a') as f:
545+
pass
546+
463547
return self.number_of_stations
464548

465549
def _recover_backed_up_playlist(self, stationFile):
@@ -1284,7 +1368,7 @@ def get_pyradio_version(self):
12841368
Retrurns
12851369
self.info
12861370
The string to display at left top corner of main window
1287-
self.current_pyradio_version
1371+
self.get_current_pyradio_version
12881372
The version to use when checking for updates
12891373
'''
12901374
ret = None
@@ -1312,7 +1396,7 @@ def get_pyradio_version(self):
13121396
ret = "RyRadio built from git: https://github.com/coderholic/pyradio/commit/{0} (rev. {1})".format(git_info[-1], git_info[1])
13131397
except:
13141398
pass
1315-
self.current_pyradio_version = self.info.replace(' PyRadio ', '')
1399+
self.current_pyradio_version = self.info.replace(' PyRadio ', '').replace(' ', '')
13161400
# if self._distro != 'None':
13171401
# self.info += '({})'.format(self._distro)
13181402
return ret

pyradio/install.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def isRunning():
4343
sleep(1)
4444
print('')
4545

46-
def version_string_to_tuple(this_version):
46+
def version_string_to_list(this_version):
4747
a_v = this_version.replace('-', '.').lower()
4848
a_l = a_v.split('.')
4949
while len(a_l) < 4:
@@ -413,9 +413,11 @@ def _do_it(self, mode='update'):
413413
epilog='When executed without an argument, it installs PyRario.')
414414
parser.add_argument('-U', '--update', action='store_true',
415415
help='Update PyRadio.')
416-
if platform.startswith('linux'):
416+
if platform.system().lower().startswith('linux'):
417417
parser.add_argument('--user', action='store_true',
418418
help='Install only for current user (linux only).')
419+
parser.add_argument('--python2', action='store_true',
420+
help='Install using python 2.')
419421
parser.add_argument('-R', '--uninstall', action='store_true',
420422
help='Uninstall PyRadio.')
421423

pyradio/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from .radio import PyRadio
1212
from .config import PyRadioConfig, SUPPORTED_PLAYERS
13-
from .install import PyRadioUpdate, PyRadioUpdateOnWindows, is_pyradio_user_installed, version_string_to_tuple, get_github_tag
13+
from .install import PyRadioUpdate, PyRadioUpdateOnWindows, is_pyradio_user_installed, version_string_to_list, get_github_tag
1414

1515
PATTERN = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
1616

@@ -152,7 +152,7 @@ def shell():
152152
if last_tag:
153153
print('Released version : {}'.format(last_tag))
154154
print('Installed version : {}'.format(pyradio_config.current_pyradio_version))
155-
if version_string_to_tuple(last_tag) <= version_string_to_tuple(pyradio_config.current_pyradio_version):
155+
if version_string_to_list(last_tag) <= version_string_to_list(pyradio_config.current_pyradio_version):
156156
print('Latest version already installed. Nothing to do....')
157157
sys.exit()
158158
else:

0 commit comments

Comments
 (0)