blob: 26714b092f0c8ece6a860995556c498cbcb6256c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/bin/bash
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
}
tempdir() {
for TMPDIR in "$TMPDIR" "$TMP" /var/tmp /tmp; do
test -d "$TMPDIR" && echo "$TMPDIR" && break
done
}
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
}
tempname() {
echo $(tempdir)/$(uuidgen).m3u
}
VERSION="0.3"
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=$(tempname)
url="http://$host:$port/.m3u"
usleep 100000
download "$url" "$file"
$DEADBEEF "$file" &
sleep 3
rm "$file"
else
host="127.0.0.1"
port=$(( ( RANDOM % 10000 ) + 10000 ))
peerflix "$1" -ardh $host -p $port --on-listening "$0 --ready $host $port"
fi
|