Skip to content

Commit 7c2ce58

Browse files
committed
install 7-Zip on Windows
1 parent 90cc319 commit 7c2ce58

File tree

7 files changed

+169
-67
lines changed

7 files changed

+169
-67
lines changed

Changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2022-08-14 s-n-g
2+
* version 0.8.9.26 (0.9-beta23)
3+
* Windows installation will try to install 7-Zip, if not
4+
already installed
5+
16
2022-08-14 s-n-g
27
* version 0.8.9.25 (0.9-beta22)
38
* fixing global shorcuts inside RadioBrowser search window

README.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ <h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style=
174174
<h2 id="changelog">Changelog <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h2>
175175
<pre style="height: 200px;">
176176

177+
2022-08-14 s-n-g
178+
* version 0.8.9.26 (0.9-beta23)
179+
* Windows installation will try to install 7-Zip, if not
180+
already installed
181+
177182
2022-08-14 s-n-g
178183
* version 0.8.9.25 (0.9-beta22)
179184
* fixing global shorcuts inside RadioBrowser search window

pyradio/player.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ def _access_check(fn, mode):
113113

114114
def find_vlc_on_windows(config_dir=None):
115115
PLAYER_CMD = ''
116-
for path in ('C:\\Program Files\\VideoLAN\\VLC\\vlc.exe',
117-
'C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe'
118-
):
116+
for path in (
117+
os.path.join(os.getenv('PROGRAMFILES'), 'VideoLAN', 'VLC', 'vlc.exe'),
118+
os.path.join(os.getenv('PROGRAMFILES') + ' (x86)', 'VideoLAN', 'VLC', 'vlc.exe'),
119+
):
119120
if os.path.exists(path):
120121
PLAYER_CMD = path
121122
break

pyradio/radio.py

Lines changed: 111 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4112,7 +4112,7 @@ def _set_active_stations(self):
41124112
self.active_stations = [
41134113
['', self.selection],
41144114
['', -1]]
4115-
# logger.error('DE active_stations = \n\n{}\n\n'.format(self.active_stations))
4115+
logger.error('DE active_stations = \n\n{}\n\n'.format(self.active_stations))
41164116

41174117
def _set_rename_stations(self):
41184118
if self.stations:
@@ -4130,7 +4130,7 @@ def _set_rename_stations(self):
41304130
self.rename_stations = [
41314131
['', self.selection],
41324132
['', -1]]
4133-
# logger.error('DE rename_stations = \n\n{}\n\n'.format(self.rename_stations))
4133+
logger.error('DE rename_stations = \n\n{}\n\n'.format(self.rename_stations))
41344134

41354135
def get_active_encoding(self, an_encoding):
41364136
if an_encoding:
@@ -7085,6 +7085,7 @@ def keypress(self, char):
70857085

70867086
if self.ws.operation_mode == self.ws.NORMAL_MODE:
70877087
if char == ord('<'):
7088+
self._update_status_bar_right(status_suffix='')
70887089
if int(self._cnf.connection_timeout_int) == 0:
70897090
self._show_stations_history_notification(0)
70907091
else:
@@ -7094,6 +7095,7 @@ def keypress(self, char):
70947095
self._cnf.play_from_history = True
70957096
self._cnf.stations_history.play_previous()
70967097
elif char == ord('>'):
7098+
self._update_status_bar_right(status_suffix='')
70977099
if int(self._cnf.connection_timeout_int) == 0:
70987100
self._show_stations_history_notification(0)
70997101
else:
@@ -7266,6 +7268,7 @@ def keypress(self, char):
72667268
return
72677269

72687270
elif char in (ord('o'), ):
7271+
self._update_status_bar_right(status_suffix='')
72697272
self._reset_status_bar_right()
72707273
self._set_rename_stations()
72717274
self._cnf.open_register_list = False
@@ -7422,6 +7425,7 @@ def keypress(self, char):
74227425
if logger.isEnabledFor(logging.DEBUG):
74237426
logger.debug('Loading playlist: "{}"'.format(self.stations[self.selection][-1]))
74247427
playlist_to_try_to_open = self.stations[self.selection][-1]
7428+
logger.error('\n\nplaylist_to_try_to_open = "{}"\n\n'.format(playlist_to_try_to_open))
74257429
ret = self._cnf.read_playlist_file(stationFile=playlist_to_try_to_open)
74267430
logger.error('DE playlist_selections = {}'.format(playlist_to_try_to_open))
74277431

@@ -7441,6 +7445,8 @@ def keypress(self, char):
74417445
self._playlist_in_editor = playlist_to_try_to_open
74427446
self._playlist_error_message = ''
74437447
self.number_of_items = ret
7448+
logger.error('self._playlist_in_editor = {0}\nself.number_of_items = {1}'.format(self._playlist_in_editor, self.number_of_items))
7449+
logger.error('self.selcctions\n{0}\nself.playlist_selections\n{1}'.format(self.selections, self.playlist_selections))
74447450
if self._cnf.open_register_list:
74457451
self.selections[self.ws.REGISTER_MODE] = [self.selection, self.startPos, self.playing, self._cnf.playlists]
74467452
self.playlist_selections[self.ws.REGISTER_MODE] = self.selections[self.ws.REGISTER_MODE][:-1][:]
@@ -7460,6 +7466,8 @@ def keypress(self, char):
74607466
self._put_selection_in_the_middle(force=True)
74617467
self.refreshBody()
74627468
self._do_display_notify()
7469+
logger.error('\n\n')
7470+
logger.error('self.selcctions\n{0}\nself.playlist_selections\n{1}'.format(self.selections, self.playlist_selections))
74637471

74647472
# if self._cnf.open_last_playlist:
74657473
# self._cnf.save_last_playlist()
@@ -8356,6 +8364,7 @@ def _load_playlist_and_station_from_station_history(self, h_item, func):
83568364
if logger.isEnabledFor(logging.DEBUG):
83578365
logger.debug('Activating history item: {}'.format(h_item))
83588366

8367+
num = -1
83598368
current_playlist = self._cnf.station_file_name[:-4]
83608369
if current_playlist == h_item[0]:
83618370
''' I am moving within the loaded playlist '''
@@ -8364,39 +8373,7 @@ def _load_playlist_and_station_from_station_history(self, h_item, func):
83648373
num = h_item[-1]
83658374
else:
83668375
''' I have to scan the playlist'''
8367-
if logger.isEnabledFor(logging.DEBUG):
8368-
logger.error('Scanning playlist...')
8369-
up = down = 0
8370-
num = -1
8371-
for i in range(h_item[-1], -1, -1):
8372-
up = i + 1
8373-
down = i - 1
8374-
if down > -1 :
8375-
if self.stations[down][0] == h_item[1]:
8376-
num = down
8377-
break
8378-
if up < self._cnf.number_of_stations:
8379-
if self.stations[up][0] == h_item[1]:
8380-
num = up
8381-
break
8382-
up += 1
8383-
down -= 1
8384-
if num == -1 and down > -1:
8385-
if logger.isEnabledFor(logging.DEBUG):
8386-
logger.debug('Station not found... Scanning to top...')
8387-
for i in range(down, -1, -1):
8388-
if self.stations[i][0] == h_item[1]:
8389-
num = i
8390-
break
8391-
8392-
if num == -1 and up < self._cnf.number_of_stations:
8393-
if logger.isEnabledFor(logging.DEBUG):
8394-
logger.debug('Station not found... Scanning to bottom...')
8395-
for i in range(up, self._cnf.number_of_stations - 1):
8396-
if self.stations[i][0] == h_item[1]:
8397-
num = i
8398-
break
8399-
8376+
num = self._scan_playlist_for_station(self.stations, h_item[-1], h_item[1])
84008377
if num == -1:
84018378
''' station not found '''
84028379
if logger.isEnabledFor(logging.DEBUG):
@@ -8405,20 +8382,6 @@ def _load_playlist_and_station_from_station_history(self, h_item, func):
84058382
func()
84068383
return
84078384

8408-
if logger.isEnabledFor(logging.DEBUG):
8409-
logger.debug('Station "{0}" found at {1}'.format(h_item[1], num))
8410-
self.setStation(num)
8411-
if self.number_of_items > 0:
8412-
self.playSelection()
8413-
#self._goto_playing_station(changing_playlist=False)
8414-
self._align_stations_and_refresh(self.ws.PLAYLIST_MODE)
8415-
self.refreshBody()
8416-
self.selections[self.ws.NORMAL_MODE] = [
8417-
self.selection,
8418-
self.startPos,
8419-
self.playing,
8420-
self.stations
8421-
]
84228385
else:
84238386
''' I have to load a new playlist '''
84248387
if self._cnf.dirty_playlist:
@@ -8432,10 +8395,10 @@ def _load_playlist_and_station_from_station_history(self, h_item, func):
84328395
ret = 0
84338396
if self._register_to_open:
84348397
logger.error('register_to_open = {}'.format(self._register_to_open))
8435-
stationFile, ret = self._get_register_filename_from_register()
8398+
stationFile, ret = self._cnf._get_register_filename_from_register()
84368399
self._is_register = True
84378400
else:
8438-
stationFile, ret = self._get_playlist_abspath_from_data(stationFile=h_item[0])
8401+
stationFile, ret = self._cnf._get_playlist_abspath_from_data(stationFile=h_item[0])
84398402
logger.error('stationFile = {}'.format(stationFile))
84408403
self._is_register = False
84418404
if ret > 0:
@@ -8444,5 +8407,102 @@ def _load_playlist_and_station_from_station_history(self, h_item, func):
84448407
return
84458408

84468409
''' playlist loaded and validated '''
8410+
num = self._open_and_check_station_in_playlist(stationFile, h_item[-1], h_item[1])
8411+
if num == -1:
8412+
''' Continue going through history items '''
8413+
func()
8414+
return
8415+
self._set_rename_stations()
8416+
self._cnf.stations = list(self._reading_stations)
8417+
self._reading_stations = []
8418+
self.stations = self._cnf.stations
8419+
self._playlist_in_editor = stationFile
8420+
self.number_of_items = len(self.stations)
8421+
self.selection = num
8422+
logger.error('num = {}'.format(num))
8423+
return
8424+
8425+
if logger.isEnabledFor(logging.DEBUG):
8426+
logger.debug('Station "{0}" found at {1}'.format(h_item[1], num))
8427+
self.setStation(num)
8428+
if self.number_of_items > 0:
8429+
self.playSelection()
8430+
#self._goto_playing_station(changing_playlist=False)
8431+
self._align_stations_and_refresh(self.ws.PLAYLIST_MODE)
8432+
self.refreshBody()
8433+
self.selections[self.ws.NORMAL_MODE] = [
8434+
self.selection,
8435+
self.startPos,
8436+
self.playing,
8437+
self.stations
8438+
]
8439+
8440+
def _scan_playlist_for_station(self, stations, start, station_to_find):
8441+
if logger.isEnabledFor(logging.DEBUG):
8442+
logger.error('Scanning playlist...')
8443+
up = down = 0
8444+
num = -1
8445+
for i in range(start, -1, -1):
8446+
up = i + 1
8447+
down = i - 1
8448+
if down > -1 :
8449+
if stations[down][0] == station_to_find:
8450+
num = down
8451+
break
8452+
if up < self._cnf.number_of_stations:
8453+
if stations[up][0] == station_to_find:
8454+
num = up
8455+
break
8456+
up += 1
8457+
down -= 1
8458+
if num == -1 and down > -1:
8459+
if logger.isEnabledFor(logging.DEBUG):
8460+
logger.debug('Station not found... Scanning to top...')
8461+
for i in range(down, -1, -1):
8462+
if stations[i][0] == station_to_find:
8463+
num = i
8464+
break
8465+
8466+
if num == -1 and up < self._cnf.number_of_stations:
8467+
if logger.isEnabledFor(logging.DEBUG):
8468+
logger.debug('Station not found... Scanning to bottom...')
8469+
for i in range(up, self._cnf.number_of_stations - 1):
8470+
if stations[i][0] == station_to_find:
8471+
num = i
8472+
break
8473+
8474+
return num
8475+
8476+
def _open_and_check_station_in_playlist(self, playlist_file, start, station_to_find):
8477+
''' read a _playlist and check if a station is in it
8478+
8479+
return num = index of file in stations' list
8480+
or -1 if it fails
8481+
8482+
stations are returned in self._reading_stations
8483+
'''
8484+
num = -1
8485+
self._reading_stations = []
8486+
with open(playlist_file, 'r') as cfgfile:
8487+
try:
8488+
for row in csv.reader(filter(lambda row: row[0]!='#', cfgfile), skipinitialspace=True):
8489+
if not row:
8490+
continue
8491+
try:
8492+
name, url = [s.strip() for s in row]
8493+
self._reading_stations.append([name, url, '', ''])
8494+
except:
8495+
try:
8496+
name, url, enc = [s.strip() for s in row]
8497+
self._reading_stations.append([name, url, enc, ''])
8498+
except:
8499+
name, url, enc, onl = [s.strip() for s in row]
8500+
self._reading_stations.append([name, url, enc, onl])
8501+
except:
8502+
self._reading_stations = []
8503+
return num
8504+
8505+
8506+
return self._scan_playlist_for_station(reading_stations, start, station_to_find)
84478507

84488508
# pymode:lint_ignore=W901

pyradio/win.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import requests
33
import subprocess
44
from os.path import join, exists, isdir
5-
from os import environ, makedirs, listdir, replace, remove, sep
5+
from os import environ, makedirs, listdir, replace, remove, sep, getenv
66
from time import sleep
77
import site
88
from shutil import rmtree
99
from msvcrt import getwch
1010
from msvcrt import getwch
1111
from os import sep
1212
import subprocess
13-
13+
from urllib.request import urlretrieve
1414

1515
HAVE_PYUNPACK = True
1616
try:
@@ -19,10 +19,10 @@
1919
HAVE_PYUNPACK = False
2020

2121
''' This is also to be able to execute it manually'''
22-
try:
23-
from .player import find_mpv_on_windows, find_mplayer_on_windows, find_vlc_on_windows
24-
except ImportError:
25-
from player import find_mpv_on_windows, find_mplayer_on_windows, find_vlc_on_windows
22+
#try:
23+
# from .player import find_mpv_on_windows, find_mplayer_on_windows, find_vlc_on_windows
24+
#except ImportError:
25+
# from player import find_mpv_on_windows, find_mplayer_on_windows, find_vlc_on_windows
2626

2727
def win_press_any_key_to_unintall():
2828
the_path = __file__.split(sep)
@@ -134,7 +134,6 @@ def _is_player_in_path(a_player):
134134
return in_path
135135

136136
def _get_output_folder(package, output_folder=None, do_not_exit=False):
137-
138137
if output_folder is None:
139138
a_path = _is_player_in_path(package)
140139
if a_path:
@@ -163,6 +162,35 @@ def _get_out_file(output_folder):
163162
break
164163
return join(output_folder, out_file)
165164

165+
def download_seven_zip(output_folder):
166+
PR = (
167+
join(getenv('PROGRAMFILES'), '7-Zip', '7z.exe'),
168+
join(getenv('PROGRAMFILES') + ' (x86)', '7-Zip', '7z.exe')
169+
)
170+
if exists(PR[0]) or exists(PR[1]):
171+
return
172+
173+
url = 'https://sourceforge.net/projects/sevenzip/files/latest/download'
174+
175+
out_file = join(output_folder, '7-Zip_latest.exe')
176+
177+
print('7-Zip not found...\nDownloading...')
178+
try:
179+
urlretrieve(url, filename=out_file)
180+
except:
181+
print('Failed to download 7-Zip...')
182+
print('Please check your internet connection and try again...')
183+
print('\nIn case you want to install 7-Zip manually,')
184+
print('go to https://www.7-zip.org/ to get it...')
185+
sys.exit(1)
186+
187+
subprocess.call(
188+
out_file,
189+
shell=True,
190+
stdout=subprocess.DEVNULL,
191+
stderr=subprocess.DEVNULL
192+
)
193+
166194
def download_player(output_folder=None, package=1, do_not_exit=False):
167195
# Parameters
168196
# output_folder : where to save files
@@ -211,6 +239,9 @@ def download_player(output_folder=None, package=1, do_not_exit=False):
211239
sys.exit(1)
212240

213241
print('Extracting archive...')
242+
if package == 0:
243+
download_seven_zip()
244+
214245
if not HAVE_PYUNPACK:
215246
for a_module in ('pyunpack', 'patool'):
216247
install_module(a_module, print_msg=False)

windows.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ <h2 id="table-of-contents">Table of Contents <span style="padding-left: 10px;"><
5252
<li><a href="#installing-python">Installing Python</a></li>
5353
<li><a href="#verifying-the-installation">Verifying the installation</a></li>
5454
</ul></li>
55-
<li><a href="#7zip-installation">7zip installation</a></li>
55+
<li><a href="#7-zip-installation">7-Zip installation</a></li>
5656
<li><a href="#player-installation">Player installation</a>
5757
<ul>
5858
<li><a href="#mpv-or-mplayer-installation">MPV or MPlayer installation</a></li>
@@ -117,8 +117,8 @@ <h4 id="verifying-the-installation">Verifying the installation</h4>
117117
<a href="https://members.hellug.gr/sng/pyradio/python2.jpg" target="_blank"><img src="https://members.hellug.gr/sng/pyradio/python2.jpg" alt="Python Installation Modification" /></a>
118118

119119
<p style="margin: 1.5em 4em 0 4em; text-indent: -2.5em;"><strong>Note:</strong> If you don’t have the setup file of the original <strong>Python</strong> installation, you will have to <strong>download</strong> it from <a target="_blank" href="https://www.python.org/downloads/windows/">Python’s Windows Downloads</a>. In case you want to upgrade to the latest version, you <strong>must uninstall</strong> the one currently installed, beforehand.</p>
120-
<h3 id="zip-installation">7zip installation <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h3>
121-
<p>Go to <a target="_blank" href="https://www.7-zip.org/">7zip web site</a> and download and install the latest release that’s compatible with your Windows installation. Unless you are still on a 32-bit Windows 7 environment, you just go grub the first link provided.</p>
120+
<h3 id="zip-installation">7-Zip installation <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h3>
121+
<p><a target="_blank" href="https://www.7-zip.org/">7-Zip</a> Windows archiver is needed for MPV’s installation. <strong>PyRadio</strong> will try to download and run the installation, if <a target="_blank" href="https://www.7-zip.org/">7-Zip</a> is not already installed.</p>
122122
<h3 id="player-installation">Player installation <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h3>
123123
<p>As already stated <a target="_blank" href="https://mpv.io">MPV</a> will be automatically installed on a fresh installation.</p>
124124
<p>If the user decides to install a different player, he should have the following in mind:</p>

0 commit comments

Comments
 (0)