A variety of simple automation scripts and enhancements to Sway and i3.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

111 satır
2.6KB

  1. #!/bin/bash
  2. # Required settings
  3. host=10.10.0.66
  4. port=8080
  5. # Optional login for Kodi
  6. #user=
  7. #pass=
  8. # Settings for netcat (local file)
  9. local_hostname=$(hostname)
  10. local_port=12345
  11. show_help()
  12. {
  13. cat<<EOF
  14. Sends a video URL to Kodi
  15. Usage: send-to-kodi.sh [URL]
  16. If no URL is given, a dialog window is shown (requires zenity).
  17. Supports:
  18. Common file formats (mp4,flv,mp3,jpg and more)
  19. Youtube (requires the Youtube plugin in Kodi)
  20. Local media streaming (via netcat)
  21. Manny more sites (requires youtube-dl)
  22. Configuration is done in the head of the script.
  23. EOF
  24. }
  25. error()
  26. {
  27. if type zenity &>/dev/null; then
  28. zenity --error --ellipsize --text "$*"
  29. else
  30. echo "$*" 1>&2
  31. fi
  32. exit 1
  33. }
  34. send_json()
  35. {
  36. curl \
  37. ${user:+--user "$user:$pass"} \
  38. -X POST \
  39. -H "Content-Type: application/json" \
  40. -d '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"'"$1"'"}},"id":1}' \
  41. http://$host:$port/jsonrpc \
  42. || error "Failed to send link - is Kodi running?"
  43. }
  44. ytplugin='plugin://plugin.video.youtube/?action=play_video&videoid='
  45. [[ $host && $port ]] || error "Please set host and port in configuration"
  46. [[ "$1" = --help ]] && show_help
  47. # Dialog box?
  48. input=$1
  49. until [[ $input ]]; do
  50. input="$(zenity --entry --title "Send to Kodi" --text \
  51. "Paste a video link here")" || exit
  52. done
  53. if [[ $input =~ ^file:// ]]; then
  54. # Remove file:// and carrige return (\r) at the end
  55. input="$(sed 's%^file://%%;s/\r$//' <<< "$input")"
  56. fi
  57. # Get URL for...
  58. # Local media
  59. if [[ -e $input ]]; then
  60. type nc &>/dev/null || error "netcat required"
  61. [[ $local_hostname && $local_port ]] || \
  62. error "Please set local hostname and port in configuration"
  63. # Start netcat in background and kill it when we exit
  64. nc -lp $local_port < "$input" &
  65. trap "kill $!" EXIT
  66. url="tcp://$local_hostname:$local_port"
  67. # youtube.com / youtu.be
  68. elif [[ $input =~ ^https?://(www\.)?youtu(\.be/|be\.com/watch\?v=) ]]; then
  69. url="$ytplugin$(\
  70. sed 's/.*\(youtu\.be\/\|[&?]v=\)\([a-zA-Z0-9_-]\+\).*/\2/'\
  71. <<< "$input"\
  72. )"
  73. # Playable formats
  74. elif [[ $input =~ \.(mp4|mkv|mov|avi|flv|wmv|asf|mp3|flac|mka|m4a|aac|ogg|pls|jpg|png|gif|jpeg|tiff)(\?.*)?$ ]]; then
  75. url="$input"
  76. # Youtube-dl
  77. else
  78. type youtube-dl &>/dev/null || error "youtube-dl required"
  79. url="$(youtube-dl -gf best "$input")" || \
  80. error "No videos found, or site not supported by youtube-dl"
  81. fi
  82. [[ $url ]] && send_json "$url"
  83. # Wait for netcat to exit
  84. wait
  85. # Don't kill netcat
  86. trap - EXIT