Added mdfind & graceful exit to ytview (#130)
This commit is contained in:
parent
f26fa4c327
commit
9b850bea9e
|
@ -111,8 +111,23 @@ getConfiguredPlayer()
|
|||
elif [[ -f $HOME/Applications/mpv.app/Contents/MacOS/mpv ]]; then
|
||||
player="$HOME/Applications/mpv.app/Contents/MacOS/mpv"
|
||||
else
|
||||
echo "Error: no supported video player installed (vlc or mpv)" >&2
|
||||
return 1
|
||||
if [[ $(mdutil -s / | grep "Indexing enabled." 2>/dev/null) != "" ]]; then
|
||||
vlc_md=$(mdfind kMDItemCFBundleIdentifier = "org.videolan.vlc" 2>/dev/null)
|
||||
if [[ $vlc_md != "" ]]; then
|
||||
player="$vlc_md/Contents/MacOS/VLC"
|
||||
else
|
||||
mpv_md=$(mdfind kMDItemCFBundleIdentifier = "io.mpv" 2>/dev/null)
|
||||
if [[ $mpv_md != "" ]]; then
|
||||
player="$mpv_md/Contents/MacOS/mpv"
|
||||
else
|
||||
echo "Error: no supported video player installed (VLC or mpv)" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "Error: no supported video player installed (VLC or mpv)" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -121,7 +136,7 @@ getConfiguredPlayer()
|
|||
channelview()
|
||||
{
|
||||
mkdir -p $HOME/.cache/ytview/channels/$channel || return 1
|
||||
httpGet "https://www.youtube.com/user/$channel/videos?hl=en" | grep "Duration" | awk '{print $10 " " $11 " " $12 " " $13 " " $14 " " $15 " " $16 " " $17 " " $18 " " $19 " " $20 " " $21 " " $22 " " $23 " " $24 " " $25 " " $26 " " $27 " " $29}' | sed 's/aria-describedby="description-id.*//' | sed s/title=// | sed 's/"//' | sed 's/"//' | awk '{printf "%s.\t%s\n",NR,$0}' | sed s/'''/"'"/g | sed s/'&'/'and'/g > $HOME/.cache/ytview/channels/$channel/titles.txt || return 1
|
||||
httpGet "https://www.youtube.com/user/$channel/videos?hl=en" | grep "Duration" | awk '{print $10 " " $11 " " $12 " " $13 " " $14 " " $15 " " $16 " " $17 " " $18 " " $19 " " $20 " " $21 " " $22 " " $23 " " $24 " " $25 " " $26 " " $27 " " $29}' | sed 's/aria-describedby="description-id.*//' | sed s/title=// | sed 's/"//' | sed 's/"//' | awk '{printf "%s.\t%s\n",NR,$0}' | sed s/'''/"'"/g | sed s/'&'/'and'/g | sed s/\"\;/\"/g > $HOME/.cache/ytview/channels/$channel/titles.txt || return 1
|
||||
|
||||
# Get the video urls
|
||||
httpGet "https://www.youtube.com/user/$channel/Videos?hl=en" | grep "watch?v=" | awk '{print $6}' | sed s/spf-link// | sed s/href=// | sed 's/"//' | sed 's/"//' | sed '/^\s*$/d' | sed 's/\//https:\/\/www.youtube.com\//' | awk '{printf "%s.\t%s\n",NR,$0}' > $HOME/.cache/ytview/channels/$channel/urls.txt || return 1
|
||||
|
@ -130,6 +145,10 @@ channelview()
|
|||
head -n 20 $HOME/.cache/ytview/channels/$channel/titles.txt || return 1
|
||||
# Prompt the user for video number
|
||||
read -p "Choose a video: " titlenumber
|
||||
if [[ -n ${titlenumber//[0-9]/} ]]; then
|
||||
echo "Canceled." >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Play the video with your player
|
||||
$player $(sed -n $(echo $titlenumber)p < $HOME/.cache/ytview/channels/$channel/urls.txt | awk '{print $2}') > /dev/null 2>&1 &
|
||||
|
@ -141,7 +160,7 @@ searchview()
|
|||
mkdir -p $HOME/.cache/ytview/searches/$search
|
||||
|
||||
#Get video titles
|
||||
httpGet "https://www.youtube.com/results?hl=en&search_query=$search" | grep "Duration" | grep "watch?v=" | awk '{print $13 " " $14 " " $15 " " $16 " " $17 " " $18 " " $19 " " $20 " " $21 " " $22 " " $23 " " $23}' | sed 's/aria-describedby="description-id.*//g' | sed s/title=// | sed 's/"//g' | sed s/spf-link// | sed 's/data-session-link=itct*.//' | sed s/spf-prefetch//g | sed 's/rel=//g' | sed 's/"//' | awk '{printf "%s.\t%s\n",NR,$0}' | sed s/'''/"'"/g | sed s/'&'/'and'/g > $HOME/.cache/ytview/searches/$search/titles.txt || return 1
|
||||
httpGet "https://www.youtube.com/results?hl=en&search_query=$search" | grep "Duration" | grep "watch?v=" | awk '{print $13 " " $14 " " $15 " " $16 " " $17 " " $18 " " $19 " " $20 " " $21 " " $22 " " $23 " " $23}' | sed 's/aria-describedby="description-id.*//g' | sed s/title=// | sed 's/"//g' | sed s/spf-link// | sed 's/data-session-link=itct*.//' | sed s/spf-prefetch//g | sed 's/rel=//g' | sed 's/"//' | awk '{printf "%s.\t%s\n",NR,$0}' | sed s/'''/"'"/g | sed s/'&'/'and'/g | sed s/\"\;/\"/g > $HOME/.cache/ytview/searches/$search/titles.txt || return 1
|
||||
|
||||
#Get video urls
|
||||
httpGet "https://www.youtube.com/results?hl=en&search_query=$search" | grep "watch?v=" | awk '{print $5}' | sed s/vve-check// | sed 's/href="/https:\/\/www.youtube.com/' | sed 's/"//' | sed s/class="yt-uix-tile-link"// | sed '/^\s*$/d' | awk '{printf "%s.\t%s\n",NR,$0}' > $HOME/.cache/ytview/searches/$search/urls.txt || return 1
|
||||
|
@ -150,6 +169,10 @@ searchview()
|
|||
|
||||
#Let the user choose the video number
|
||||
read -p "Choose a video: " titlenumber
|
||||
if [[ -n ${titlenumber//[0-9]/} ]]; then
|
||||
echo "Canceled." >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#Play the video with your favorite player
|
||||
$player $(sed -n $(echo $titlenumber)p < $HOME/.cache/ytview/searches/$search/urls.txt | awk '{print $2}') > /dev/null 2>&1 &
|
||||
|
|
Loading…
Reference in New Issue