Advertisement
H0XH4

ytchannel.bash

Dec 28th, 2016
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.74 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #    ytchannel.bash - interactive cli program to choose play and YouTube videos from given channel with mpv
  4. #    Copyright (C) 2016  TWT:@0xUID
  5. #
  6. #    This program is free software: you can redistribute it and/or modify
  7. #    it under the terms of the GNU General Public License as published by
  8. #    the Free Software Foundation, either version 3 of the License, or
  9. #    (at your option) any later version.
  10. #
  11. #    This program is distributed in the hope that it will be useful,
  12. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #    GNU General Public License for more details.
  15. #
  16. #    You should have received a copy of the GNU General Public License
  17. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. # REQUIRED PACKAGES: lynx mpv
  20.  
  21. # USAGE: ytchannel [YouTube channel]
  22.  
  23. # EXAMPLE: "ytchannel druaga1" will give you a list of Druaga's newest videos to choose from
  24.  
  25. # Empty and recreate the cache directory
  26. rm -rf "~/.cache/ytchannel/"
  27. mkdir -p "~/.cache/ytchannel/channels/$1"
  28.  
  29. # Get the video titles
  30. lynx --dump "https://youtube.com/user/$1/videos" | grep "Duration" > "~/.cache/ytchannel/channels/$1/titles.txt"
  31.  
  32. # Get the video urls
  33. lynx --dump "https://youtube.com/user/$1/videos" | grep "https://www.youtube.com/watch?v=" > "~/.cache/ytchannel/channels/$1/urls.txt"
  34.  
  35. # Print 20 first video titles for the user to choose from
  36. head "~/.cache/ytchannel/channels/$1/titles.txt" -n 20 --quiet
  37.  
  38. # Prompt the user for video number
  39. read -p "Choose a video: " titlenumber
  40.  
  41. # Play the video with mpv
  42. mpv $(grep $titlenumber  "~/.cache/ytchannel/channels/$1/urls.txt" | awk '{print $2}') # grep is not needed here but I'm lazy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement