view-youtube 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. #
  3. # Now that Youtube has gone completely nonfree, we need some way to watch it
  4. # with a full FS stack, don't we?
  5. #
  6. # Tor is now optional (but recommended nonetheless), and yad is used instead of
  7. # zenity to provide the GUI. It's a small download (<100kB) and has much better
  8. # handling then zenity, although it doesn't always come by default.
  9. #
  10. # Note: requires mpv to work. Also, tor{socks} is crucial lest you not
  11. # want to anonymize yourself
  12. #
  13. # CREDITS:
  14. # Thanks goes to Jookia for pointing out how to do this in a neat one-liner:
  15. # mpv --keep-open=yes --ytdl-format "bestvideo[protocol!=http_dash_segments][height<=?480]+bestaudio/best[height<=?480]" "$1"
  16. #
  17. # Basically all I did was wrap a GUI around the whole thing.
  18. #
  19. # LICENSE:
  20. # Copyright 2016 Klaus Zimmermann - https://quitter.se/kzimmermann
  21. #
  22. # This program is free software: you can redistribute it and/or modify
  23. # it under the terms of the GNU General Public License as published by
  24. # the Free Software Foundation, either version 3 of the License, or
  25. # (at your option) any later version.
  26. #
  27. # This program is distributed in the hope that it will be useful,
  28. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. # GNU General Public License for more details.
  31. #
  32. # You should have received a copy of the GNU General Public License
  33. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  34. #
  35. # Privacy is your unalienable right, but you should always have a choice.
  36. # Change to 0 to stream directly without Tor (and give away your IP address):
  37. TOR=1
  38. YAD=0
  39. if [[ -z $(which yad) ]]
  40. then
  41. if [[ -z $(which zenity) ]]
  42. then
  43. echo "Warning: zenity is not installed in this system, cannot load the GUI"
  44. echo "You can still \"surf\" from the command-line, though."
  45. echo "Just run \`$(basename $0) [video url]\` to watch in private."
  46. exit 1
  47. else
  48. zenity --question --text="yad is not installed, which means that some features won't work.\nPlease install yad to get the full experience!" || exit 0
  49. fi
  50. else
  51. YAD=1
  52. fi
  53. if [[ -z $(which mpv) ]]
  54. then
  55. echo "This program requires mpv to work."
  56. echo "Please install it from your package manager and try again."
  57. exit 1
  58. fi
  59. while [[ true ]]
  60. do
  61. DATA=$(yad --title "view-youtube menu" --form \
  62. --text="Enter the URL from YouTube to stream directly in the desktop. You can choose to use Tor as well."\
  63. --field "URL to stream" \
  64. --field "Use Tor:CHK"
  65. ) || exit 0
  66. [[ -z "$DATA" ]] && continue
  67. URL=$(echo "$DATA" | cut -d "|" -f 1)
  68. TOR=$(echo "$DATA" | cut -d "|" -f 2)
  69. if [[ "$TOR" == "TRUE" ]]
  70. then
  71. torsocks \
  72. mpv --keep-open=yes "$URL" &> /dev/null ||
  73. zenity --error \
  74. --title "Video could not be streamed." \
  75. --text "Error: [libav] https: HTTP error 403 Forbidden.\nWell, thank YouTube for the shitty API they use."
  76. # --ytdl-format "bestvideo[protocol!=http_dash_segments][height<=?480]+bestaudio/best[height<=?480]" "$1"
  77. # for some reason this doesn't seem to work..
  78. else
  79. mpv --keep-open=yes "$URL"
  80. fi
  81. done