#!/bin/bash # Author: Linyos Torovoltos https://github.com/linyostorovovoltos # Modifications: Alexander Epstein https://github.com/alexanderepstein if [[ -d $HOME/.cache/ytview ]]{ rm -rf $HOME/.cache/ytview/ ;} global player := ''"" global configuredClient := ''"" global currentVersion := '"1.11.1'" global flag := ''"" ## This function determines which http get tool the system has installed and returns an error if there isnt one proc getConfiguredClient { if command -v curl &>/dev/null ; { global configuredClient := '"curl'" } elif command -v wget &>/dev/null ; { global configuredClient := '"wget'" } elif command -v fetch &>/dev/null ; { global configuredClient := '"fetch'" } else { echo "Error: This tool reqires either curl, wget, or fetch to be installed." > !2 return 1 } } proc checkInternet { echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null !2 > !1 # query google with a get request if test $Status -eq 0 { #check if the output is 0, if so no errors have occured and we have connected to google successfully return 0 } else { echo "Error: no active internet connection" > !2 #sent to stderr return 1 } } ## Allows to call the users configured client without if statements everywhere proc httpGet { matchstr $configuredClient { curl { curl -A curl -s @Argv} wget { wget -qO- @Argv} fetch { fetch -o "..."} } } proc update { # Author: Alexander Epstein https://github.com/alexanderepstein # Update utility version 1.2.0 # To test the tool enter in the defualt values that are in the examples for each variable global repositoryName := '"Bash-Snippets'" #Name of repostiory to be updated ex. Sandman-Lite global githubUserName := '"alexanderepstein'" #username that hosts the repostiory ex. alexanderepstein global nameOfInstallFile := '"install.sh'" # change this if the installer file has a different name be sure to include file extension if there is one global latestVersion := $[httpGet https://api.github.com/repos/$githubUserName/$repositoryName/tags | grep -Eo '"name":.*?[^\\]",'| head -1 | grep -Eo "[0-9.]+] #always grabs the tag without the v option if [[ $currentVersion == "" || $repositoryName == "" || $githubUserName == "" || $nameOfInstallFile == "" ]]{ echo "Error: update utility has not been configured correctly." > !2 exit 1 } elif [[ $latestVersion == "" ]]{ echo "Error: no active internet connection" > !2 exit 1 } else { if [[ "$latestVersion" != "$currentVersion" ]] { echo "Version $latestVersion available" echo -n "Do you wish to update $repositoryName [Y/n]: " read -r answer if [[ "$answer" == "Y" || "$answer" == "y" ]] { cd ~ || do { echo 'Update Failed' ; exit 1 ; } if [[ -d ~/$repositoryName ]] { rm -r -f $repositoryName || do { echo "Permissions Error: try running the update as sudo"; exit 1; } ; } git clone "https://github.com/$githubUserName/$repositoryName" || do { echo "Couldn't download latest version" ; exit 1; } cd $repositoryName || do { echo 'Update Failed' ; exit 1 ;} git checkout "v$latestVersion" !2 > /dev/null || git checkout $latestVersion !2 > /dev/null || echo "Couldn't git checkout to stable release, updating to latest commit." chmod a+x install.sh #this might be necessary in your case but wasnt in mine. ./$nameOfInstallFile "update" || exit 1 cd .. rm -r -f $repositoryName || do { echo "Permissions Error: update succesfull but cannot delete temp files located at ~/$repositoryName delete this directory with sudo"; exit 1; } } else { exit 1 } } else { echo "$repositoryName is already the latest version" } } } proc getConfiguredPlayer { if [[ "$OSTYPE" == "linux"* ]]{ if command -v vlc &>/dev/null;{ global player := '"vlc'" } elif command -v mpv &>/dev/null;{ global player := '"mpv'" } elif command -v mplayer &>/dev/null;{ global player := '"mplayer'" } else { echo "Error: no supported video player installed (vlc, mpv or mplayer)" > !2 return 1 } } elif [[ "$OSTYPE" == "darwin"* ]] { if [[ -f /Applications/VLC.app/Contents/MacOS/VLC ]]{ global player := '"/Applications/VLC.app/Contents/MacOS/VLC'" } else { echo "Error: vlc is not installed and it is required to play videos" > !2 return 1 } } } # Get the video titles proc channelview { mkdir -p $HOME/.cache/ytview/channels/$channel || return 1 httpGet https://www.youtube.com/user/$channel/videos | 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 # Get the video urls httpGet https://www.youtube.com/user/$channel/Videos | 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 # Print 20 first video titles for the user to choose from head -n 20 $HOME/.cache/ytview/channels/$channel/titles.txt || return 1 # Prompt the user for video number read -p "Choose a video: " titlenumber # 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 & } proc searchview { global search := $[echo $search | tr " " +] mkdir -p $HOME/.cache/ytview/searches/$search #Get video titles httpGet https://www.youtube.com/results'?'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 #Get video urls httpGet https://www.youtube.com/results'?'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 #Print 20 first video titles for the user to choose from cat $HOME/.cache/ytview/searches/$search/titles.txt || return 1 #Let the user choose the video number read -p "Choose a video: " titlenumber #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 & } proc usage { echo "Ytview" echo "Description: Search and play youtube videos right from the terminal." echo "Usage: ytview [flag] [string] or ytview [videoToSearch]" echo " -s Searches youtube" echo " -c Shows the latest videos of a channel" echo " -u Update Bash-Snippet Tools" echo " -h Show the help" echo " -v Get the tool version" echo "Examples:" echo " ytview -s Family Guy Chicken Fight" echo " ytview -c Numberphile" } getConfiguredClient || exit 1 getConfiguredPlayer || exit 1 checkInternet || exit 1 while getopts vuc:s:h*: option { matchstr $(option) { s { if [[ $flag != "channel" ]]{ global search := $[printf '%s ' @Argv] global flag := '"search'" } else { echo "Error: search and channel options are mutually exclusive" > !2 exit 1 } } c { if [[ $flag != "search" ]]{ global channel := $OPTARG global flag := '"channel'" } else { echo "Error: search and channel options are mutually exclusive" > !2 exit 1 } } h { usage && exit 0 } u { update && exit 0 } v { echo "Version $currentVersion" && exit 0 } * { usage && exit 0 } } } if [[ $# == "0" ]] { usage exit 0 } elif [[ $1 == "help" ]]{ usage exit 0 } elif [[ $1 == "update" ]] { update exit 0 } elif [[ $flag == "search" ]] { searchview || exit 1 } elif [[ $flag == "channel" ]] { channelview || exit 1 } else { global search := $[printf '%s ' @Argv] searchview || exit 1 } (CommandList children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_d child:{($ VSub_Name "$HOME") (/.cache/ytview)}) ) terminator: ) ] action: [ (Sentence child: (C {(rm)} {(-rf)} {($ VSub_Name "$HOME") (/.cache/ytview/)}) terminator: ) ] spids: [-1 21] ) ] spids: [-1 31] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:player) op:Equal rhs:{(DQ )} spids:[34])] spids: [34] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:configuredClient) op:Equal rhs:{(DQ )} spids:[38])] spids: [38] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:currentVersion) op:Equal rhs:{(DQ (1.11.1))} spids:[42])] spids: [42] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:flag) op:Equal rhs:{(DQ )} spids:[47])] spids: [47] ) (FuncDef name: getConfiguredClient body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(curl)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [71] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (curl))} spids: [79] ) ] spids: [79] ) ] spids: [-1 76] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(wget)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [94] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (wget))} spids: [102] ) ] spids: [102] ) ] spids: [85 99] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(fetch)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [117] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (fetch))} spids: [125] ) ] spids: [125] ) ] spids: [108 122] ) ] else_action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Error: This tool reqires either curl, wget, or fetch to be installed."))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[140])] ) (ControlFlow token: arg_word:{(1)}) ] spids: [131 149] ) ] spids: [59] ) spids: [55 58] ) (FuncDef name: checkInternet body: (BraceGroup children: [ (Pipeline children: [ (C {(echo)} {(-e)} { (DQ ("GET http://google.com HTTP/1.0") (EscapedLiteralPart token:) (EscapedLiteralPart token:) ) } ) (SimpleCommand words: [{(nc)} {(google.com)} {(80)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [179] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[183]) ] ) ] negated: False ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(0)} {(Lit_Other "]")}) terminator: ) ] action: [(ControlFlow token: arg_word:{(0)})] spids: [-1 203] ) ] else_action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: no active internet connection"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[223])] ) (ControlFlow token: arg_word:{(1)}) ] spids: [214 235] ) ] spids: [158] ) spids: [154 157] ) (FuncDef name: httpGet body: (BraceGroup children: [ (Case to_match: {(DQ ($ VSub_Name "$configuredClient"))} arms: [ (case_arm pat_list: [{(curl)}] action: [(C {(curl)} {(-A)} {(curl)} {(-s)} {(DQ ($ VSub_At "$@"))})] spids: [259 260 273 -1] ) (case_arm pat_list: [{(wget)}] action: [(C {(wget)} {(-qO-)} {(DQ ($ VSub_At "$@"))})] spids: [276 277 286 -1] ) (case_arm pat_list: [{(fetch)}] action: [(C {(fetch)} {(-o)} {(DQ (...))})] spids: [289 290 299 -1] ) ] spids: [250 256 302] ) ] spids: [247] ) spids: [243 246] ) (FuncDef name: update body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repositoryName) op: Equal rhs: {(DQ (Bash-Snippets))} spids: [326] ) ] spids: [326] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:githubUserName) op: Equal rhs: {(DQ (alexanderepstein))} spids: [335] ) ] spids: [335] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nameOfInstallFile) op: Equal rhs: {(DQ (install.sh))} spids: [344] ) ] spids: [344] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:latestVersion) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(httpGet)} {(https) (Lit_Other ":") (//api.github.com/repos/) ($ VSub_Name "$githubUserName") (/) ($ VSub_Name "$repositoryName") (/tags) } ) (C {(grep)} {(-Eo)} {(SQ <"\"name\":.*?[^\\\\]\",">)}) (C {(head)} {(-1)}) (C {(grep)} {(-Eo)} {(DQ ("[0-9.]+"))}) ] negated: False ) ] ) left_token: spids: [354 390] ) } spids: [353] ) ] spids: [353] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$currentVersion")} right: {(DQ )} ) right: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$repositoryName")} right: {(DQ )} ) right: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$githubUserName")} right: {(DQ )} ) right: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$nameOfInstallFile")} right: {(DQ )} ) ) ) ) ) terminator: ) ] action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Error: update utility has not been configured correctly."))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[446])] ) (C {(exit)} {(1)}) ] spids: [-1 437] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$latestVersion")} right: {(DQ )} ) ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: no active internet connection"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[477])] ) (C {(exit)} {(1)}) ] spids: [455 468] ) ] else_action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {(DQ ($ VSub_Name "$latestVersion"))} right: {(DQ ($ VSub_Name "$currentVersion"))} ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Version ") ($ VSub_Name "$latestVersion") (" available"))}) (C {(echo)} {(-n)} { (DQ ("Do you wish to update ") ($ VSub_Name "$repositoryName") (" [Y/n]: ")) } ) (C {(read)} {(-r)} {(answer)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$answer"))} right: {(DQ (Y))} ) right: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$answer"))} right: {(DQ (y))} ) ) ) terminator: ) ] action: [ (AndOr children: [ (C {(cd)} {(TildeSubPart prefix:"")}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(SQ <"Update Failed">)}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [574] ) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_d child: {(Lit_Tilde "~") (/) ($ VSub_Name "$repositoryName") } ) ) terminator: ) ] action: [ (Sentence child: (AndOr children: [ (C {(rm)} {(-r)} {(-f)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ( "Permissions Error: try running the update as sudo" ) ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [618] ) ] op_id: Op_DPipe ) terminator: ) ] spids: [-1 606] ) ] spids: [-1 636] ) (AndOr children: [ (C {(git)} {(clone)} { (DQ ("https://github.com/") ($ VSub_Name "$githubUserName") (/) ($ VSub_Name "$repositoryName") ) } ) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ ("Couldn't download latest version"))}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [652] ) ] op_id: Op_DPipe ) (AndOr children: [ (C {(cd)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(SQ <"Update Failed">)}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [676] ) ] op_id: Op_DPipe ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(checkout)} {(DQ (v) ($ VSub_Name "$latestVersion"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [703] ) ] ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(checkout)} {(DQ ($ VSub_Name "$latestVersion"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [717] ) ] ) (C {(echo)} { (DQ ( "Couldn't git checkout to stable release, updating to latest commit." ) ) } ) ] op_id: Op_DPipe ) ] op_id: Op_DPipe ) (C {(chmod)} {(a) (Lit_Other "+") (x)} {(install.sh)}) (AndOr children: [ (C {(./) ($ VSub_Name "$nameOfInstallFile")} {(DQ (update))}) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (C {(cd)} {(..)}) (AndOr children: [ (C {(rm)} {(-r)} {(-f)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ( "Permissions Error: update succesfull but cannot delete temp files located at ~/" ) ($ VSub_Name "$repositoryName") (" delete this directory with sudo") ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [771] ) ] op_id: Op_DPipe ) ] spids: [-1 565] ) ] else_action: [(C {(exit)} {(1)})] spids: [790 798] ) ] spids: [-1 506] ) ] else_action: [ (C {(echo)} {(DQ ($ VSub_Name "$repositoryName") (" is already the latest version"))} ) ] spids: [801 812] ) ] spids: [486 815] ) ] spids: [311] ) spids: [307 310] ) (FuncDef name: getConfiguredPlayer body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$OSTYPE"))} right: {(DQ (linux)) (Lit_Other "*")} ) ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(vlc)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [856] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:player) op: Equal rhs: {(DQ (vlc))} spids: [862] ) ] spids: [862] ) ] spids: [-1 859] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(mpv)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [877] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:player) op: Equal rhs: {(DQ (mpv))} spids: [883] ) ] spids: [883] ) ] spids: [868 880] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(mplayer)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [898] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:player) op: Equal rhs: {(DQ (mplayer))} spids: [904] ) ] spids: [904] ) ] spids: [889 901] ) ] else_action: [ (SimpleCommand words: [ {(echo)} { (DQ ( "Error: no supported video player installed (vlc, mpv or mplayer)" ) ) } ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[919])] ) (ControlFlow token: arg_word: {(1)} ) ] spids: [910 928] ) ] spids: [-1 844] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$OSTYPE"))} right: {(DQ (darwin)) (Lit_Other "*")} ) ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_f child: {(/Applications/VLC.app/Contents/MacOS/VLC)} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:player) op: Equal rhs: {(DQ (/Applications/VLC.app/Contents/MacOS/VLC))} spids: [965] ) ] spids: [965] ) ] spids: [-1 962] ) ] else_action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Error: vlc is not installed and it is required to play videos"))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[980])] ) (ControlFlow token: arg_word: {(1)} ) ] spids: [971 989] ) ] spids: [931 949] ) ] spids: [-1 992] ) ] spids: [824] ) spids: [820 823] ) (FuncDef name: channelview body: (BraceGroup children: [ (AndOr children: [ (C {(mkdir)} {(-p)} {($ VSub_Name "$HOME") (/.cache/ytview/channels/) ($ VSub_Name "$channel")} ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (AndOr children: [ (Pipeline children: [ (C {(httpGet)} {(https) (Lit_Other ":") (//www.youtube.com/user/) ($ VSub_Name "$channel") (/videos) } ) (C {(grep)} {(DQ (Duration))}) (C {(awk)} { (SQ < "{print $10 \" \" $11 \" \" $12 \" \" $13 \" \" $14 \" \" $15 \" \" $16 \" \" $17 \" \" $18 \" \" $19 \" \" $20 \" \" $21 \" \" $22 \" \" $23 \" \" $24 \" \" $25 \" \" $26 \" \" $27 \" \" $29}" > ) } ) (C {(sed)} {(SQ <"s/aria-describedby=\"description-id.*//">)}) (C {(sed)} {(s/title) (Lit_Other "=") (//)}) (C {(sed)} {(SQ <"s/\"//">)}) (C {(sed)} {(SQ <"s/\"//">)}) (C {(awk)} {(SQ <"{printf \"%s.\\t%s\\n\",NR,$0}">)}) (C {(sed)} {(s/) (SQ <"'">) (/) (DQ ("'")) (/g)}) (SimpleCommand words: [{(sed)} {(s/) (SQ <"&">) (/) (SQ ) (/g)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$HOME") (/.cache/ytview/channels/) ($ VSub_Name "$channel") (/titles.txt) } spids: [1116] ) ] ) ] negated: False ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (AndOr children: [ (Pipeline children: [ (C {(httpGet)} {(https) (Lit_Other ":") (//www.youtube.com/user/) ($ VSub_Name "$channel") (/Videos) } ) (C {(grep)} {(DQ ("watch?v="))}) (C {(awk)} {(SQ <"{print $6}">)}) (C {(sed)} {(s/spf-link//)}) (C {(sed)} {(s/href) (Lit_Other "=") (//)}) (C {(sed)} {(SQ <"s/\"//">)}) (C {(sed)} {(SQ <"s/\"//">)}) (C {(sed)} {(SQ <"/^\\s*$/d">)}) (C {(sed)} {(SQ <"s/\\//https:\\/\\/www.youtube.com\\//">)}) (SimpleCommand words: [{(awk)} {(SQ <"{printf \"%s.\\t%s\\n\",NR,$0}">)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$HOME") (/.cache/ytview/channels/) ($ VSub_Name "$channel") (/urls.txt) } spids: [1213] ) ] ) ] negated: False ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (AndOr children: [ (C {(head)} {(-n)} {(20)} {($ VSub_Name "$HOME") (/.cache/ytview/channels/) ($ VSub_Name "$channel") (/titles.txt) } ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (C {(read)} {(-p)} {(DQ ("Choose a video: "))} {(titlenumber)}) (Sentence child: (SimpleCommand words: [ {($ VSub_Name "$player")} { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (SimpleCommand words: [ {(sed)} {(-n)} { (CommandSubPart command_list: (CommandList children: [(C {(echo)} {($ VSub_Name "$titlenumber")})] ) left_token: spids: [1280 1284] ) (p) } ] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {($ VSub_Name "$HOME") (/.cache/ytview/channels/) ($ VSub_Name "$channel") (/urls.txt) } spids: [1287] ) ] ) (C {(awk)} {(SQ <"{print $2}">)}) ] negated: False ) ] ) left_token: spids: [1275 1301] ) } ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [1303] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[1307]) ] ) terminator: ) ] spids: [1005] ) spids: [1001 1004] ) (FuncDef name: searchview body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:search) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$search")}) (C {(tr)} {(DQ (" "))} {(Lit_Other "+")}) ] negated: False ) ] ) left_token: spids: [1324 1339] ) } spids: [1323] ) ] spids: [1323] ) (C {(mkdir)} {(-p)} {($ VSub_Name "$HOME") (/.cache/ytview/searches/) ($ VSub_Name "$search")} ) (AndOr children: [ (Pipeline children: [ (C {(httpGet)} {(https) (Lit_Other ":") (//www.youtube.com/results) (EscapedLiteralPart token:) (search_query) (EscapedLiteralPart token: ) } ) (C {(sed)} {(SQ <"s/aria-describedby=\"description-id.*//g">)}) (C {(sed)} {(s/title) (Lit_Other "=") (//)}) (C {(sed)} {(SQ <"s/\"//g">)}) (C {(sed)} {(s/spf-link//)}) (C {(sed)} {(SQ <"s/data-session-link=itct*.//">)}) (C {(sed)} {(s/spf-prefetch//g)}) (C {(sed)} {(SQ <"s/rel=//g">)}) (C {(sed)} {(SQ <"s/\"//">)}) (C {(awk)} {(SQ <"{printf \"%s.\\t%s\\n\",NR,$0}">)}) (C {(sed)} {(s/) (SQ <"'">) (/) (DQ ("'")) (/g)}) (SimpleCommand words: [{(sed)} {(s/) (SQ <"&">) (/) (SQ ) (/g)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$HOME") (/.cache/ytview/searches/) ($ VSub_Name "$search") (/titles.txt) } spids: [1485] ) ] ) ] negated: False ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (AndOr children: [ (Pipeline children: [ (C {(httpGet)} {(https) (Lit_Other ":") (//www.youtube.com/results) (EscapedLiteralPart token:) (search_query) (EscapedLiteralPart token:)}) (C {(sed)} {(s/vve-check//)}) (C {(sed)} {(SQ <"s/href=\"/https:\\/\\/www.youtube.com/">)}) (C {(sed)} {(SQ <"s/\"//">)}) (C {(sed)} {(s/class) (Lit_Other "=") (DQ (yt-uix-tile-link)) (//)}) (C {(sed)} {(SQ <"/^\\s*$/d">)}) (SimpleCommand words: [{(awk)} {(SQ <"{printf \"%s.\\t%s\\n\",NR,$0}">)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$HOME") (/.cache/ytview/searches/) ($ VSub_Name "$search") (/urls.txt) } spids: [1578] ) ] ) ] negated: False ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (AndOr children: [ (C {(cat)} {($ VSub_Name "$HOME") (/.cache/ytview/searches/) ($ VSub_Name "$search") (/titles.txt) } ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (C {(read)} {(-p)} {(DQ ("Choose a video: "))} {(titlenumber)}) (Sentence child: (SimpleCommand words: [ {($ VSub_Name "$player")} { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (SimpleCommand words: [ {(sed)} {(-n)} { (CommandSubPart command_list: (CommandList children: [(C {(echo)} {($ VSub_Name "$titlenumber")})] ) left_token: spids: [1638 1642] ) (p) } ] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {($ VSub_Name "$HOME") (/.cache/ytview/searches/) ($ VSub_Name "$search") (/urls.txt) } spids: [1645] ) ] ) (C {(awk)} {(SQ <"{print $2}">)}) ] negated: False ) ] ) left_token: spids: [1633 1659] ) } ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [1661] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[1665]) ] ) terminator: ) ] spids: [1319] ) spids: [1315 1318] ) (FuncDef name: usage body: (BraceGroup children: [ (C {(echo)} {(DQ (Ytview))}) (C {(echo)} {(DQ ("Description: Search and play youtube videos right from the terminal."))}) (C {(echo)} {(DQ ("Usage: ytview [flag] [string] or ytview [videoToSearch]"))}) (C {(echo)} {(DQ (" -s Searches youtube"))}) (C {(echo)} {(DQ (" -c Shows the latest videos of a channel"))}) (C {(echo)} {(DQ (" -u Update Bash-Snippet Tools"))}) (C {(echo)} {(DQ (" -h Show the help"))}) (C {(echo)} {(DQ (" -v Get the tool version"))}) (C {(echo)} {(DQ ("Examples:"))}) (C {(echo)} {(DQ (" ytview -s Family Guy Chicken Fight"))}) (C {(echo)} {(DQ (" ytview -c Numberphile"))}) ] spids: [1680] ) spids: [1676 1679] ) (AndOr children:[(C {(getConfiguredClient)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children:[(C {(getConfiguredPlayer)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children:[(C {(checkInternet)})(C {(exit)} {(1)})] op_id:Op_DPipe) (While cond: [ (C {(getopts)} {(vuc) (Lit_Other ":") (s) (Lit_Other ":") (h) (Lit_Other "*") (Lit_Other ":")} {(option)} ) ] body: (DoGroup children: [ (Case to_match: {(DQ (${ VSub_Name option))} arms: [ (case_arm pat_list: [{(s)}] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$flag")} right: {(DQ (channel))} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:search) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(printf)} {(SQ <"%s ">)} {(DQ ($ VSub_At "$@"))}) ] ) left_token: spids: [1837 1847] ) } spids: [1836] ) ] spids: [1836] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:flag) op: Equal rhs: {(DQ (search))} spids: [1850] ) ] spids: [1850] ) ] spids: [-1 1833] ) ] else_action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Error: search and channel options are mutually exclusive"))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1865])] ) (C {(exit)} {(1)}) ] spids: [1856 1874] ) ] spids: [1815 1816 1877 -1] ) (case_arm pat_list: [{(c)}] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$flag")} right: {(DQ (search))} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:channel) op: Equal rhs: {(DQ ($ VSub_Name "$OPTARG"))} spids: [1901] ) ] spids: [1901] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:flag) op: Equal rhs: {(DQ (channel))} spids: [1907] ) ] spids: [1907] ) ] spids: [-1 1898] ) ] else_action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Error: search and channel options are mutually exclusive"))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1922])] ) (C {(exit)} {(1)}) ] spids: [1913 1931] ) ] spids: [1880 1881 1934 -1] ) (case_arm pat_list: [{(h)}] action: [(AndOr children:[(C {(usage)})(C {(exit)} {(0)})] op_id:Op_DAmp)] spids: [1937 1938 1948 -1] ) (case_arm pat_list: [{(u)}] action: [(AndOr children:[(C {(update)})(C {(exit)} {(0)})] op_id:Op_DAmp)] spids: [1951 1952 1962 -1] ) (case_arm pat_list: [{(v)}] action: [ (AndOr children: [ (C {(echo)} {(DQ ("Version ") ($ VSub_Name "$currentVersion"))}) (C {(exit)} {(0)}) ] op_id: Op_DAmp ) ] spids: [1965 1966 1981 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [(AndOr children:[(C {(usage)})(C {(exit)} {(0)})] op_id:Op_DAmp)] spids: [1984 1985 1995 -1] ) ] spids: [1804 1812 1998] ) ] spids: [1801 2000] ) ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Pound "$#")} right: {(DQ (0))} ) ) terminator: ) ] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [-1 2018] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (help))} ) ) terminator: ) ] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [2028 2042] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (update))} ) ) terminator: ) ] action: [(C {(update)}) (C {(exit)} {(0)})] spids: [2052 2067] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$flag")} right: {(DQ (search))} ) ) terminator: ) ] action: [(AndOr children:[(C {(searchview)})(C {(exit)} {(1)})] op_id:Op_DPipe)] spids: [2077 2092] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$flag")} right: {(DQ (channel))} ) ) terminator: ) ] action: [(AndOr children:[(C {(channelview)})(C {(exit)} {(1)})] op_id:Op_DPipe)] spids: [2103 2118] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:search) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(printf)} {(SQ <"%s ">)} {(DQ ($ VSub_At "$@"))})] ) left_token: spids: [2133 2143] ) } spids: [2132] ) ] spids: [2132] ) (AndOr children:[(C {(searchview)})(C {(exit)} {(1)})] op_id:Op_DPipe) ] spids: [2129 2154] ) ] )