al-url.el 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ;;; al-url.el --- Code for searching and downloading various stuff
  2. ;; Copyright © 2015-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (require 'wget)
  15. (defvar al/url-mp3-re
  16. (rx "http" (? ?s) "://" (1+ any) ".mp3")
  17. "Regexp for mp3 file.")
  18. ;;;###autoload
  19. (defun al/url-wget-mp3 (url)
  20. "Download the first mp3 file from URL with `wget'."
  21. (interactive
  22. (list (read-string "Download mp3 from URL: "
  23. (thing-at-point 'url))))
  24. (let* ((buf (url-retrieve-synchronously url))
  25. (mp3 (with-current-buffer buf
  26. (re-search-forward al/url-mp3-re)
  27. (match-string 0))))
  28. (when (y-or-n-p (format "Download '%s'? " mp3))
  29. (wget mp3))))
  30. (provide 'al-url)
  31. ;;; al-url.el ends here