1 ;;; evdl.el -- Emacs Video Downloader
2 ;;; A web video downloader script for Emacs
4 ;; Copyright (C) 2009 Martin Bealby
6 ;; Author: Martin Bealby <mbealby@gmail.com>
8 ;; This program is free software; you can redistribute it and/or
9 ;; modify it under the terms of the GNU General Public License as
10 ;; published by the Free Software Foundation; either version 3 of
11 ;; the License, or (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public
19 ;; License along with this program; if not, write to the Free
20 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 ;; MA 02111-1307, USA.
24 ;; This relies upon emacs-wget to do status feedback on downloads. It is
25 ;; available from: http://pop-club.hp.infoseek.co.jp/emacs/emacs-wget/
28 ;; 1. M-x evdl and supply the video page url (if you want the url only,
34 ;; 1. Different sites can probably be simplified to a list. Each entry
35 ;; being a list with the function to call and its arguments.
39 ;;----------------------------------------------------------------------------
41 ;;----------------------------------------------------------------------------
45 ;;----------------------------------------------------------------------------
47 ;;----------------------------------------------------------------------------
49 "Emacs Video Downloader."
54 ;;----------------------------------------------------------------------------
56 ;;----------------------------------------------------------------------------
60 ;;----------------------------------------------------------------------------
62 ;;----------------------------------------------------------------------------
63 (defun evdl (url &optional arg
)
64 "Downloads a flash video from the given url. If called with a
65 prefix, display direct video link and append to the kill ring."
66 (interactive "sURL: \nP")
73 ;; youtube (defaults to mp4)
74 ((string-match "youtube.[A-Za-z]+/watch" url
)
76 (evdl-extract-link-youtube
78 (progn (string-match "youtube.[A-Za-z]+/watch.v="
82 "youtube.[A-Za-z]+/watch.v=[-A-Z_a-z0-9]+"
86 ((string-match "vimeo.com/" url
)
88 (evdl-extract-link-vimeo (substring url
91 ((string-match "video.google" url
)
93 (evdl-extract-link-generic
95 "http://[A-Za-z0-9-_\.]+/videodownload"
96 "\">this link</a> and choose \"Save As\"")))
98 ((string-match "guba.com" url
)
102 (evdl-extract-link-generic url
103 "http://free.guba.com/uploaditem"
107 ((string-match "blip.tv" url
)
109 (evdl-extract-link-generic url
113 (t (message "Sorry, this url is not supported."))))
115 ;;;;----------------------------------------------------------------------------
116 ;;;; Support Functions
117 ;;;;----------------------------------------------------------------------------
118 (defun evdl-extract-link-generic (url start-regex end-regex
119 &optional appended-string
)
120 "Extracts the download link from the supplied url using the
121 regular expressions passed to it. Optionally also appends an
124 (call-process wget-command nil t t
128 (goto-char (point-min))
129 (concat (substring (substring (buffer-string)
130 (string-match start-regex
132 (string-match end-regex
134 (length start-regex
))
138 (defun evdl-extract-link-vimeo (clipid)
139 "Download a video from vimeo from the clipid."
141 (call-process wget-command nil t t
144 (concat "http://www.vimeo.com/moogaloop/load/clip:"
146 (goto-char (point-min))
147 ;; remove garbage at beginning
148 (delete-region (point-min)
149 (re-search-forward "<request_signature>"))
150 ;; build up url by prepending host and path
151 (move-beginning-of-line nil
)
152 (insert (concat "http://www.vimeo.com/moogaloop/play/clip:"
155 ;; tidy appended request_signature
156 (move-end-of-line nil
)
157 (backward-delete-char (length "</request_signature>"))
158 ;; append request_signature_expires
160 (delete-region (point)
161 (re-search-forward "<request_signature_expires"))
162 (delete-region (point)
163 (re-search-forward "1"))
165 (move-end-of-line nil
)
166 (backward-delete-char (length "</request_signature_expires>"))
167 ;; second line = value of request_signature_expires
168 (delete-region (point)
169 (goto-char (point-max)))
170 (goto-char (point-max))
175 (defun evdl-extract-link-youtube (videoid)
176 "Download a video from youtube when given a video id and
177 optionally an mp4 flag."
179 (call-process wget-command nil t t
182 (concat "http://www.youtube.com/watch?v="
185 (call-process wget-command nil t t
188 (concat "http://www.youtube.com/watch?v="
190 (goto-char (point-min))
191 ;; remove garbage at beginning
192 (delete-region (point-min)
193 (re-search-forward "\"t\": \""))
194 ;; remove trailing garbage
195 (delete-region (re-search-forward "\"")
197 (backward-delete-char 1)
198 ;; build up url by prepending host and path
199 (move-beginning-of-line nil
)
200 (insert (concat "http://www.youtube.com/get_video?video_id="
205 (move-end-of-line nil
)
210 ;;-----------------------------------------------------------------------------
212 ;;-----------------------------------------------------------------------------