-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.bash_functions.mpv
150 lines (141 loc) · 4.73 KB
/
.bash_functions.mpv
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# vim: ft=bash noet:
! declare 2>&1 | grep -wq ^colors= && [ $BASH_VERSINFO -ge 4 ] && source $initDir/.colors
test "$debug" -gt 0 && echo "=> Running $bold${colors[blue]}$(basename ${BASH_SOURCE[0]})$normal ..."
test "$debug" -gt 0 && Echo "\n=> \${BASH_SOURCE[*]} = ${BASH_SOURCE[*]}\n"
[ $osFamily = Linux ] && [ -c /dev/fb0 ] && tty | egrep -q "/dev/tty[0-9]+" && mpvDefaultOptions="--vo=drm" && mplayerDefaultOptions="--vo=fbdev2"
export mpv_Output_Perl_Script="'\$| = 1;s/\n/\r/g if \$_ =~ /AV: /;s/Saving state/\nSaving state/'" # On l'exporte pour qu'elle soit accessible du processus fils
export HOSTNAME # for mpv auto-profiles conditions
mpv="command mpv"
# alias mpv="LANG=en_US.utf8 $mpv $mpvDefaultOptions"
mpvnoconfig="mpv --no-config"
alias mpvnoconfig="$mpvnoconfig"
mplayer="command mplayer"
alias mplayer="LANG=en_US.utf8 $mplayer $mplayerDefaultOptions"
mplayernoconfig="mplayer --noconfig=user"
function cleanMPVStatusLine {
perl -pe $mpv_Output_Perl_Script
}
function moveAudio2FirstConnectedBluetoothDevice {
bluezSinkOutput=$(pactl list sinks short | awk '/bluez_sink.*SUSPENDED/{printf$1;exit}')
if [ -n "$bluezSinkOutput" ];then # If connected to a bluetooth audio device and the sink is SUSPENDED
pactl list sink-inputs short | awk '/protocol-native.c/{print$1}' | while read sink_input;do
echo "=> pactl move-sink-input $sink_input $bluezSinkOutput ..."
pactl move-sink-input $sink_input $bluezSinkOutput
done
fi
}
function mpv {
local mpv="command mpv"
local mpvOptions="$mpvDefaultOptions"
local DISPLAY=$DISPLAY
# moveAudio2FirstConnectedBluetoothDevice
test "$SSH_CONNECTION" && hostname | \egrep -qi "b206$|eb1501p$" && export DISPLAY=:0
LANG=en_US.utf8 $mpv $mpvOptions "$@"
}
function mpv2 {
local mpv="command mpv"
local mpvOptions="$mpvDefaultOptions"
local ytdl_format
for url
do
domain=$(echo "$url" | sed "s/https?:..//" | awk -F. '{print$(NF-1)}')
case $domain in
dailymotion)
ytdl_format=$(ytdlpnoconfig -F="$url" | awk '/^hls/{last=$1}END{print last}')
mpvOptions="--ytdl-format=$ytdl_format $mpvOptions"
;;
*) ;;
esac
LANG=en_US.utf8 $mpv "$mpvOptions" "$url"
done
}
function mpvFORMAT {
local firstArg="$1"
shift
test -f nohup.out && \rm -v nohup.out
touch nohup.out
mpvNoHup --ytdl-format="$firstArg" "$@" &
tail -f nohup.out | egrep -v "AV: "
}
function mpvInit {
if [ -c /dev/fb0 ]; then
if [ ! -w /dev/fb0 ]
then
\sudo chmod g+w /dev/fb0
if ! groups | \grep -wq video
then
echo "=> INFO: Adding $USER in the video group and logging in to the new <video> group." 1>&2
\sudo adduser $USER video
\sudo newgrp - video
fi
fi
else
echo "=> Function $FUNCNAME - ERROR: Framebuffer is not supported in this configuration." 1>&2
return 1
fi
}
function mpvOld {
$mpv $(youtube-dl -g "$@")
}
function mpvRSSPodCastPlayList {
test $# = 1 && {
local url="$1"
# mpv $(youtube-dl -g "$url")
mpv $(curl -s "$url" | egrep -o "https?:[^ <>]*(mp4|webm)" | grep -v .google.com/ | uniq)
}
}
function mpvalt {
test $1 && $mpv --no-ytdl $(youtube-dl -g -f=best $@ | uniq)
}
function mpvdirectly {
test -f nohup.out && \rm -v nohup.out
touch nohup.out
mpvNoHup --no-ytdl "$@" &
tail -f nohup.out | egrep -v "AV: "
}
function mpvlive {
test -f nohup.out && \rm -v nohup.out
touch nohup.out
mpvNoHup --no-resume-playback "$@" &
tail -f nohup.out | egrep -v "AV: "
}
function mpvlocal {
mpvdirectly "$@"
}
function mpvPlaylistFile {
test -f nohup.out && \rm -v nohup.out
touch nohup.out
local playListFile="$1" playlistStartIndex="" index=1
local format="mp4[height<=480]/mp4/best"
test $# = 1 && shift
test $# = 2 && playlistStartIndex="--playlist-start=$1" && playListFile="$2" && index=$(($1+1)) && shift 2
local playListType=${playListFile/*./}
if [ $playListType = url ] || [ $playListType = urls ]
then
\sed -n "${index}s/^[^#]*//;${index}p" "$playListFile"
awk '{print$1}' "$playListFile" > "${playListFile/.*/__no-title.urls}"
$mpv --ytdl-format="$format" $playlistStartIndex --playlist="${playListFile/.*/__no-title.urls}" -- "$@"
\rm "${playListFile/.*/__no-title.urls}"
else
$mpv --ytdl-format="$format" $playlistStartIndex --playlist="$playListFile" -- "$@"
fi
tail -f nohup.out | egrep -v "AV: "
}
function mpvPlaylistFileFORMAT {
test -f nohup.out && \rm -v nohup.out
touch nohup.out
local format
local playlist firstArg="$1"
echo -- $1 | \grep -q -- "--" && format="$1" && playlist="$2" && shift || playlist="$1"
shift
mpvNoHup "$firstArg" --ytdl-format="$format" --playlist="$playlist" "$@" &
tail -f nohup.out | egrep -v "AV: "
}
function mpvNoHup {
nohup mpv --profile=background "$@"
}
function urlplayer {
$mpv $(youtube-dl -gf best "$1")
}
set +x
test "$debug" -gt 0 && echo "=> END of $bold${colors[blue]}$(basename ${BASH_SOURCE[0]})$normal"