This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtubeplayer.sh
65 lines (49 loc) · 1.7 KB
/
youtubeplayer.sh
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
#!/bin/bash
# Play and download the youtube video simultaneously
# Author: Samunddra
# Update Date: 2016-12-14 16:29:14 PM
#
# Use `screen` to play it in the background, fork screen process and exit, enjoy
#
# DEPENDENCIES
# - sudo apt install -y jq mplayer youtube-dl
#
# Usage: ./videoplayer.sh 'youtube-playlist-link'
#
# TODO
# 1. Show the title of the currently playing video
#
set -e
APPLICATION_HOME="/home/$USER/ytplayer"
# Create Application home if it do not exists
[ ! -d "$APPLICATION_HOME" ] && mkdir -p $APPLICATION_HOME
FILENAME="$APPLICATION_HOME/video-list.txt"
VIDEOLOG="$APPLICATION_HOME/video-log.txt"
SUFFIX=`date | cut -d " " -f4|sed 's/:/_/g'`
echo >> $FILENAME;
echo "Requested URL: $1" >> $VIDEOLOG;
# https://zhimingwang.org/blog/2014-11-05-list-youtube-playlist-with-youtube-dl.html
youtube-dl -j --flat-playlist "$1"| jq -r '.id' | \
sed 's_^_https://youtube.com/v/_' > $FILENAME
TOTAL_VIDEOS=`cat $FILENAME|nl|sort -rn|xargs|cut -f1 -d " "`
TOTAL_VIDEOS=$TOTAL_VIDEOS|awk '{print $0}'
echo "TOTAL VIDEOS FOUND: $TOTAL_VIDEOS" >> $VIDEOLOG
URLS=`cat $FILENAME|xargs`
i=1
while [[ $i -le $TOTAL_VIDEOS ]]
do
url=`cat $FILENAME|xargs|cut -f$i -d " "`;
echo "Currently Playing: $url" >> $VIDEOLOG
notify-send "Youtube Player" \
"Playing index : $i, $url" \
-i /usr/share/pixmaps/linssid-start.png \
-t 10000
youtube-dl -o - "$url"| tee "$APPLICATION_HOME/video_${SUFFIX}_$i.webm"| \
mplayer -vo xv -noborder -ontop -vf scale=320:240 \
-geometry 2%:98% -screenw 240 -screenh 320 -quiet -
(( i = i + 1))
done
notify-send "Playlist Completed" \
"End of the playlist reached." \
-i /usr/share/pixmaps/linssid-start.png \
-t 0