-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomxplayer_playlist_play
121 lines (93 loc) · 3.02 KB
/
omxplayer_playlist_play
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bash
#
# Plays files and STRM files from a playlist
#
# Copyright © 2013 Janne Enberg http://lietu.net/
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
#
set -o nounset
set -o errexit
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
verbose=0
# If you want to switch omxplayer to something else, or add parameters, use these
PLAYER="omxplayer"
PLAYER_OPTIONS=""
# Where is the playlist
PLAYLIST_FILE="/var/omxplayer_playlist_play/playlist"
while getopts "h?vf" opt; do
case "$opt" in
h|\?) show_help
exit 0
;;
v) verbose=1
;;
esac
done
shift $((OPTIND-1))
[ ! -z ${var+x} ] && [ "$1" = "--" ] && shift
if [ ! -z "$@" ]; then
PLAYLIST_FILE="$@"
fi
if [ "$verbose" = "1" ]; then
echo -e "verbose=$verbose\nplaylist file=$PLAYLIST_FILE"
fi
# Process playlist contents
while [ true ]; do
# Sleep a bit so its possible to kill this
sleep 1
# Do nothing if the playlist doesnt exist
if [ ! -f "${PLAYLIST_FILE}" ]; then
echo "Playlist file ${PLAYLIST_FILE} not found"
continue
fi
# Get the top of the playlist
file=$(cat "${PLAYLIST_FILE}" | head -n1)
# Skip if this is empty
if [ -z "${file}" ]; then
echo "Playlist empty or bumped into an empty entry for some reason"
cat "${PLAYLIST_FILE}" | tail -n+2 > "${PLAYLIST_FILE}.new"
echo "$file" >> "${PLAYLIST_FILE}.new"
mv "${PLAYLIST_FILE}.new" "${PLAYLIST_FILE}"
continue
fi
# Check that the file exists
if [ ! -f "${file}" ]; then
echo "Playlist entry ${file} not found"
continue
fi
echo
echo "Playing ${file} ..."
echo
stream=$(cat "$file")
echo
echo "Stream ${stream} ..."
echo
filename=$(basename "$file")
extension="${filename##*.}"
filename=${filename%.*}
echo
echo "ext ${extension} ..."
echo
if [ `echo $extension | tr [:upper:] [:lower:]` = `echo strm | tr [:upper:] [:lower:]` ]; then
play=$(cat "$file")
else
play=$file
fi
echo
echo "Hi ${file} ..."
echo
googletts "Now playing ${filename}"
"${PLAYER}" ${PLAYER_OPTIONS} "${play}" || true
echo
echo "Playback complete, continuing to next item on playlist."
echo
# Sleep a bit so its possible to kill this
sleep 1
# And strip it off the playlist file
cat "${PLAYLIST_FILE}" | tail -n+2 > "${PLAYLIST_FILE}.new"
echo "$file" >> "${PLAYLIST_FILE}.new"
mv "${PLAYLIST_FILE}.new" "${PLAYLIST_FILE}"
done