From bdc3aceb927c3596132c2492416b775155ed055a Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Mon, 23 Dec 2019 00:25:40 +0300 Subject: 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 --- LICENSE | 7 +++++++ README.md | 18 ++++++++++++---- peerflix-deadbeef | 61 +++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a5dacea --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright (C) 2019 Evgeny Zinoviev + +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. diff --git a/README.md b/README.md index cf58e13..f635337 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,22 @@ # 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 ``` peerflix-deadbeef ``` -### Requirements +## Requirements + +Make sure that `peerflix` and `curl` or `wget` are in your `$PATH`. + +On Linux, `deadbeef` is expected to be in your `$PATH`. -Make sure that `peerflix` and `deadbeef` are in your `$PATH`. +On macOS, script assumes that `DeaDBeeF.app` is installed to `/Applications`. -### Install +## Install ``` git clone https://github.com/gch1p/peerflix-deadbeef @@ -18,8 +24,12 @@ cd peerflix-deadbeef sudo make install ``` -### Uninstall +## Uninstall ``` sudo make uninstall ``` + +## License + +MIT diff --git a/peerflix-deadbeef b/peerflix-deadbeef index abe32da..35d0b69 100755 --- a/peerflix-deadbeef +++ b/peerflix-deadbeef @@ -1,27 +1,70 @@ #!/bin/bash -[ -z "$1" ] && { - echo "usage: peerflix-deadbeef " +error() { + echo "error: $@" 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 " + 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 host="$2" port="$3" - - file=$(mktemp --suffix=".m3u") - + file=$(mktemp_m3u) url="http://$host:$port/.m3u" - usleep 100000 - curl "$url" > "$file" - deadbeef "$file" & + usleep 100000 + download "$url" "$file" + $DEADBEEF "$file" & sleep 3 rm "$file" else 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" fi -- cgit v1.2.3