I made this code to play random vids read from a playlist file (simple text file, with different link in each line). This is my second attempt. Please don't laugh at me, because the first attempt was working! So the effect of the script is an empty chrome window, just like a new tab. I've no clue why is this not working.
#!/bin/bash
#initializing the file and current time in millis
file="youtube.songs"
ct=`date +%s`
#counting the lines in the list file
num=`wc -l $file | cut -f1 -d' '`
rem=$(( $ct % ( $num - 1 ) ))
ln=$(( $rem + 1 ))
#geting the url by line number
url=`cat $file | head -n $ln | tail -n 1 `
google-chrome --incognito $url
My first attempt (which was working, but I was looking forward to challenge myself) looked sg. like this:
ct=`date +%s`
rem=$(( $ct % 22 ))
case $rem in
1)
url="https://www.youtube.com"
;;
*)
;;
I've tried both of @shellter's advice:
#initializing the file and current time in millis
file="youtube.songs"
+ file=youtube.songs
ct=$( date +%s )
date +%s )
date +%s
++ date +%s
+ ct=1409239606
#counting the lines in the list file
num=$( wc -l $file | cut -f1 -d' ' )
wc -l $file | cut -f1 -d' ' )
wc -l $file | cut -f1 -d' '
++ wc -l youtube.songs
++ cut -f1 '-d '
+ num=25
num=$(( $num - 1 ))
+ num=24
rem=$(( $ct % $num ))
+ rem=22
ln=$(( $rem + 1 ))
+ ln=23
#geting the url by line number
url=$( cat $file | head -n $ln | tail -n 1 )
cat $file | head -n $ln | tail -n 1 )
cat $file | head -n $ln | tail -n 1
++ head -n 23
++ cat youtube.songs
++ tail -n 1
+ url='https://www.youtube.com/watch?v=DmeUuoxyt_E'
google-chrome --incognito $url
+ google-chrome --incognito 'https://www.youtube.com/watch?v=DmeUuoxyt_E'
So there is an issue with the variable substitution. I've tried $(echo $url)
instead of $url
, but got the same results. So I am clueless.