multiple improvements + license

- use RANDOM to generate port number
- support macOS
- check that all required binaries are in $PATH
- support wget if curl is not available
- added license
This commit is contained in:
Evgeny Zinoviev 2019-12-23 00:25:40 +03:00
parent f39fa95749
commit bdc3aceb92
3 changed files with 73 additions and 13 deletions

7
LICENSE Normal file
View File

@ -0,0 +1,7 @@
Copyright (C) 2019 Evgeny Zinoviev <me@ch1p.io>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,16 +1,22 @@
# peerflix-deadbeef # peerflix-deadbeef
**peerflix-deadbeef** is a wrapper script to use (peerflix)[https://github.com/mafintosh/peerflix] to listen to music from torrents in (DeaDBeeF)[https://github.com/DeaDBeeF-Player/deadbeef].
### Usage ### Usage
``` ```
peerflix-deadbeef <magnet link or torrent file> peerflix-deadbeef <magnet link or torrent file>
``` ```
### Requirements ## Requirements
Make sure that `peerflix` and `deadbeef` are in your `$PATH`. Make sure that `peerflix` and `curl` or `wget` are in your `$PATH`.
### Install On Linux, `deadbeef` is expected to be in your `$PATH`.
On macOS, script assumes that `DeaDBeeF.app` is installed to `/Applications`.
## Install
``` ```
git clone https://github.com/gch1p/peerflix-deadbeef git clone https://github.com/gch1p/peerflix-deadbeef
@ -18,8 +24,12 @@ cd peerflix-deadbeef
sudo make install sudo make install
``` ```
### Uninstall ## Uninstall
``` ```
sudo make uninstall sudo make uninstall
``` ```
## License
MIT

View File

@ -1,27 +1,70 @@
#!/bin/bash #!/bin/bash
[ -z "$1" ] && { error() {
echo "usage: peerflix-deadbeef <magnet or torrent>" echo "error: $@"
exit 1 exit 1
} }
installed() {
command -v "$1" > /dev/null
return $?
}
get_deadbeef() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "/Applications/DeaDBeeF.app/Contents/MacOS/DeaDBeeF"
else
echo deadbeef
fi
}
download() {
local source="$1"
local target="$2"
if installed curl; then
curl -o "$target" "$source"
elif installed wget; then
wget -O "$target" "$source"
fi
}
usage() {
echo "$NAME v$VERSION"
echo
echo "usage: $NAME <magnet or torrent>"
exit
}
mktemp_m3u() {
echo $(mktemp $TMPDIR/$(uuidgen).m3u)
}
VERSION="0.2"
NAME="peerflix-deadbeef"
DEADBEEF="$(get_deadbeef)"
[ -z "$1" ] && usage
installed "$DEADBEEF" || error "$DEADBEEF is not found"
installed peerflix || error "peerflix is not found in PATH"
installed curl || installed wget || error "curl or wget is required"
if [[ "$1" == "--ready" ]]; then if [[ "$1" == "--ready" ]]; then
host="$2" host="$2"
port="$3" port="$3"
file=$(mktemp_m3u)
file=$(mktemp --suffix=".m3u")
url="http://$host:$port/.m3u" url="http://$host:$port/.m3u"
usleep 100000
curl "$url" > "$file" usleep 100000
deadbeef "$file" & download "$url" "$file"
$DEADBEEF "$file" &
sleep 3 sleep 3
rm "$file" rm "$file"
else else
host="127.0.0.1" host="127.0.0.1"
port=$(shuf -i 10000-20000 -n1) port=$(( ( RANDOM % 10000 ) + 10000 ))
peerflix "$1" -ardh $host -p $port --on-listening "$0 --ready $host $port" peerflix "$1" -ardh $host -p $port --on-listening "$0 --ready $host $port"
fi fi