Kashire's Youtube Query
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3KB

  1. #!/bin/bash
  2. package="kyq"
  3. youtubeURI="https://www.youtube.com/results?search_query="
  4. if [ -z "$1" ]; then
  5. echo 'You must specify flag. (e.g. -h)'
  6. fi
  7. while test $# -gt 0; do
  8. case "$1" in
  9. -h|--help)
  10. echo "$package - For returning a list of youtube videos."
  11. echo " "
  12. echo "$package [option] [argument]"
  13. echo " "
  14. echo "options:"
  15. echo "-h, --help Shows this"
  16. echo "-q, --query Search for specific query on youtube"
  17. exit 0
  18. ;;
  19. -q|--query)
  20. query=$(echo ${@:2} | sed 's/ /%20/g' )
  21. html=$(wget -qO- $youtubeURI$query)
  22. echo $html >> tmp.html
  23. title=$(xmllint --html --xpath '//h3/a[@href]/span' tmp.html)
  24. url=$(xmllint --html --xpath '//h3/a/@href' tmp.html)
  25. echo $title | sed 's/<\/span>/\n/g' | sed 's/^.*>//' >> A_TITLE.txt
  26. echo $url | sed 's/href="/\n/g' | sed 's/&.*//' | sed 's/"//' | sed "/googleadservices/d" | sed 's/^/https:\/\/www.youtube.com/' | tail -n +2 | sed '/user/d' | sed '/channel/d' >> A_URL.txt
  27. # Removes duplicate URL
  28. $(awk '!x[$1]++' A_URL.txt >> A_URL_SORTED.txt)
  29. ## Loop through both files and post them side by side.
  30. # lol...
  31. $(paste A_URL_SORTED.txt A_TITLE.txt > A_FINISHED.txt)
  32. cat A_FINISHED.txt
  33. $(rm A_FINISHED.txt A_TITLE.txt A_URL_SORTED.txt A_URL.txt tmp.html)
  34. break
  35. ;;
  36. esac
  37. done