-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbhbuff
More file actions
executable file
·70 lines (65 loc) · 1.61 KB
/
bhbuff
File metadata and controls
executable file
·70 lines (65 loc) · 1.61 KB
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
#!/bin/bash
PERCENT=100
RUN=0
function USAGE {
echo -e "
Usage: $0 [FLAGS]... [BITHORDE LINK FILE]\n
-h, --help Shows this help.
-p, --percent Load asset [NUM] percent before evetual xdg-open, (DEFAULT: 100)
-r, --run Open asset with xdg-open after preload. (DEFAULT: No)\n
Example: $0 -p 20 -r MyBithordeLink.avi\n"
}
LOCKFILE=$(tempfile)
function wait_for_buff() {
dd of=/dev/null bs=512 count=$PIECETOLOAD
rm "$LOCKFILE"
if [ ! "$PERCENT" = "100" ]; then dd of=/dev/null bs=512 count=$DDSTAT; fi
}
if [ "$1" = "" ]; then
echo "bhbuff needs a bithorde link to handle..."
USAGE
exit 1
fi
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
USAGE
exit 0
;;
-r|--run)
RUN=1
;;
-p|--percent)
PERCENT="$2"
if [[ "$PERCENT" =~ ^[0-9]+$ ]]; then
if [ "$PERCENT" -gt 100 ]; then
PERCENT=100
fi
else
echo "Procent needs to be a number between 1 - 100..."
USAGE
exit 1
fi
;;
*)
FILE=${!#}
if ! [[ $(readlink "$FILE") == *magnet* ]]; then
echo "File not a bithorde symlink..."
USAGE
exit 1
fi
;;
esac
shift
done
STAT=$(stat -L -c%s "$FILE")
PIECETOLOAD="$(($(($STAT/512/100))*$PERCENT))"
DDSTAT="$(($STAT/512))"
bhget -sy -py "$FILE" | wait_for_buff &
trap "echo -e '\nKilling script and buffering functions...'; kill $(pidof bhget) $(pidof dd); exit 130" SIGINT SIGTERM
while [ -f "$LOCKFILE" ]; do
sleep 0.1
done
if [ "$RUN" = 1 ]; then
xdg-open "$FILE" > /dev/null 2> /dev/null
fi