Skip to content

Commit fa9ab98

Browse files
committed
socat is no longer needed to use mpv
1 parent 9ce8153 commit fa9ab98

File tree

8 files changed

+49
-31
lines changed

8 files changed

+49
-31
lines changed

Changelog

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2019-12-22 s-n-g
22
* Fixing volume issue with mpv
3+
* socat is no longer needed to use mpv
34

45
2019-12-14 s-n-g
56
* Version 0.8.6

README.html

-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ <h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style=
5454
<ul>
5555
<li>python 2.7+/3.5+</li>
5656
<li>MPV, MPlayer or VLC installed and in your path.</li>
57-
<li><a target="_blank" href="http://www.dest-unreach.org/socat/">socat</a> (if you wish to use MPV)</li>
5857
</ul>
5958
<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>
6059
<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>
@@ -246,7 +245,6 @@ <h3 id="finding-the-right-encoding">Finding the right encoding</h3>
246245
<h2 id="player-detection-selection">Player detection / selection <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></style></h2>
247246
<p><strong>PyRadio</strong> is basically built around the existence of a valid media player it can use. Thus, it will auto detect the existence of its supported players upon its execution.</p>
248247
<p>Currently, it supports MPV, MPlayer and VLC, and it will look for them in that order. If none of them is found, the program will terminate with an error.</p>
249-
<p>MPV will be used only when the <a target="_blank" href="http://www.dest-unreach.org/socat/">socat</a> multipurpose relay is also installed.</p>
250248
<p>Users can alter this default behavior by using the <strong><em>-u</em></strong> command line option. This option will permit the user either to specify the player to use, or change the detection order.</p>
251249
<p>Example:</p>
252250
<pre>pyradio -u vlc</pre>

README.md

-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Ben Dowling - [https://github.com/coderholic](https://github.com/coderholic)
3030

3131
* python 2.7+/3.5+
3232
* MPV, MPlayer or VLC installed and in your path.
33-
* [socat](http://www.dest-unreach.org/socat/) (if you wish to use MPV)
3433

3534
## Installation
3635

@@ -338,8 +337,6 @@ replacing **2.7** with specific version: **3.0** up to current python version.
338337

339338
Currently, it supports MPV, MPlayer and VLC, and it will look for them in that order. If none of them is found, the program will terminate with an error.
340339

341-
MPV will be used only when the [socat](http://www.dest-unreach.org/socat/) multipurpose relay is also installed.
342-
343340
Users can alter this default behavior by using the ***-u*** command line option. This option will permit the user either to specify the player to use, or change the detection order.
344341

345342
Example:

build.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ <h3 id="macos">macOS</h3>
7171
<pre>brew install gnu-sed --default-names</pre>
7272
<p>Now it’s time to install a media player. You are free to install any one of them or even more than one…</p>
7373
<p>1. <strong><em>MPV</em></strong></p>
74-
<pre>brew install mpv socat</pre>
74+
<pre>brew install mpv</pre>
7575
<p>2. <strong><em>MPlayer</em></strong></p>
7676
<pre>brew install mplayer</pre>
7777
<p>3. <strong><em>VLC</em></strong></p>

build.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Now it's time to install a media player. You are free to install any one of them
7171
1\. ***MPV***
7272

7373
```
74-
brew install mpv socat
74+
brew install mpv
7575
```
7676

7777
2\. ***MPlayer***

pyradio.1

-2
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,6 @@ A valid encoding list can be found at:
392392
.PP
393393
Currently, it supports \fIMPV\fR, \fIMPlayer\fR and \fIVLC\fR, and it will look for them in that order. If none of them is found, the program will terminate with an error.
394394
.PP
395-
MPV will be used only when the \fIsocat\fR multipurpose relay is also installed.
396-
.PP
397395
Users can alter this default behavior by using the \fB-u\fR command line option. This option will permit the user either to specify the player to use, or change the detection order.
398396
.PP
399397
Example:

pyradio/player.py

+45-18
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def _do_save_volume(self, config_string):
109109
with open(config_file, "w") as c_file:
110110
c_file.write(config_string)
111111
self.volume = -1
112+
self.PROFILE_FROM_USER = True
112113
except:
113114
if (logger.isEnabledFor(logging.DEBUG)):
114115
logger.debug(log_strings[2].format(config_file))
@@ -504,6 +505,14 @@ class MpvPlayer(Player):
504505
if os.path.exists(mpvsocket):
505506
os.system("rm " + mpvsocket + " 2>/dev/null");
506507

508+
commands = {
509+
'volume_up': b'{ "command": ["cycle", "volume", "up"] }\n',
510+
'volume_down': b'{ "command": ["cycle", "volume", "down"] }\n',
511+
'mute': b'{ "command": ["cycle", "mute"] }\n',
512+
'pause': b'{ "command": ["pause"] }\n',
513+
'quit': b'{ "command": ["quit"]}\n',
514+
}
515+
507516
def save_volume(self):
508517
""" Saving Volume in Windows does not work;
509518
Profiles not supported... """
@@ -567,26 +576,28 @@ def _buildStartOpts(self, streamUrl, playList=False):
567576

568577
def _mute(self):
569578
""" mute mpv """
570-
os.system("echo 'cycle mute' | socat - " + self.mpvsocket + " 2>/dev/null");
579+
ret = self._send_mpv_command('mute')
580+
while not ret:
581+
ret = self._send_mpv_command('mute')
571582

572583
def pause(self):
573584
""" pause streaming (if possible) """
574-
os.system("echo 'cycle pause' | socat - " + self.mpvsocket + " 2>/dev/null");
585+
self._send_mpv_command('pause')
575586

576587
def _stop(self):
577588
""" exit pyradio (and kill mpv instance) """
578-
os.system("echo 'quit' | socat - " + self.mpvsocket + " 2>/dev/null");
589+
self._send_mpv_command('quit')
579590
os.system("rm " + self.mpvsocket + " 2>/dev/null");
580591

581592
def _volume_up(self):
582593
""" increase mpv's volume """
583-
os.system("echo 'cycle volume' | socat - " + self.mpvsocket + " 2>/dev/null");
584-
self._diaplay_mpv_volume_value()
594+
self._send_mpv_command('volume_up')
595+
self._display_mpv_volume_value()
585596

586597
def _volume_down(self):
587598
""" decrease mpv's volume """
588-
os.system("echo 'cycle volume down' | socat - " + self.mpvsocket + " 2>/dev/null");
589-
self._diaplay_mpv_volume_value()
599+
self._send_mpv_command('volume_down')
600+
self._display_mpv_volume_value()
590601

591602
def _format_title_string(self, title_string):
592603
""" format mpv's title """
@@ -605,7 +616,33 @@ def _connect_to_socket(self, server_address):
605616
sock.close()
606617
return None
607618

608-
def _diaplay_mpv_volume_value(self):
619+
def _send_mpv_command(self, a_command):
620+
""" Send a command to MPV
621+
622+
"""
623+
624+
if a_command in self.commands.keys():
625+
#while True:
626+
# sock = self._connect_to_socket(self.mpvsocket)
627+
# if sock:
628+
# break
629+
# sleep(.25)
630+
sock = self._connect_to_socket(self.mpvsocket)
631+
if sock is None:
632+
return False
633+
634+
# Send data
635+
sock.sendall(self.commands[a_command])
636+
# read the responce
637+
if version_info < (3, 0):
638+
data = sock.recv(4096)
639+
else:
640+
data = sock.recvmsg(4096)
641+
#logger.error('DE data = "{}"'.format(data))
642+
sock.close()
643+
return True
644+
645+
def _display_mpv_volume_value(self):
609646
""" Display volume for MPV
610647
611648
Currently working with python 2 and 3
@@ -955,16 +992,6 @@ def check_player(a_player):
955992
shell=False)
956993
p.terminate()
957994

958-
# for mpv to work, socat is required...
959-
if a_player.PLAYER_CMD == 'mpv':
960-
if logger.isEnabledFor(logging.DEBUG):
961-
logger.debug("mpv found... Checking for socat...")
962-
p = subprocess.Popen(['socat', "-h"],
963-
stdout=subprocess.PIPE,
964-
stdin=subprocess.PIPE,
965-
shell=False)
966-
p.terminate()
967-
968995
if logger.isEnabledFor(logging.INFO):
969996
logger.info("{} supported.".format(str(a_player)))
970997
return a_player

pyradio/radio.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,7 @@ def initBody(self):
436436
PyRadio currently supports three players: mpv, mplayer and vlc,
437437
automatically detected in this order.
438438
439-
Please install any one of them and try again.
440-
441-
Please keep in mind that if mpv is installed, socat must be
442-
installed as well."""
439+
Please install any one of them and try again."""
443440
self.refreshNoPlayerBody(txt)
444441
else:
445442
#if self.ws.operation_mode == self.ws.MAIN_HELP_MODE:

0 commit comments

Comments
 (0)