;; 2010-06-07
;; ∑ http://xahlee.org/
(defun youtube-string (video-id)
"Return html code for embedding video of youtube's VIDEO-ID.
Example call:
(youtube-string \"bFSS826ETlk\")"
(let (url)
(setq url (concat "http://www.youtube.com/v/" video-id))
(concat
"")
) )
(defun youtube-linkify ()
"Make the current line into a embeded HTML video object.
The line can be a youtube ID or full url.
Examples of lines:
bFSS826ETlk
http://www.youtube.com/watch?v=bFSS826ETlk
url with more parameters usually will work too.
The current line is the line the cursor is on, that is enclosed by “\n”.
Here's a example result:
"
(interactive)
(let (p1 p2 tmp id)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq tmp (buffer-substring-no-properties p1 p2))
(setq tmp (replace-regexp-in-string "http://youtube\\.com/watch\\?v=" "" tmp))
(setq tmp (replace-regexp-in-string "http://www\\.youtube\\.com/v/" "" tmp))
(setq tmp (replace-regexp-in-string "&.+" "" tmp))
(setq tmp (replace-regexp-in-string
"^http://www\\.youtube\\.com/watch\\?v=" "" tmp))
(setq id tmp)
(delete-region p1 p2)
(insert (youtube-string id) ) ))
(defun google-video-string (video-id)
"Return html code for embedding video of Google Video's VIDEO-ID.
Example call:
(google-video-string \"2336889538700185341\")"
(let (url)
(setq url (concat "http://video\.google\.com/googleplayer\.swf\?docid=" video-id "&fs=true" ))
(concat
"")
))
(defun google-video-linkify ()
"Make the current line into a embeded google video HTML object.
The line can be a youtube ID such as 2336889538700185341”
or url such as
“http://video.google.com/videoplay?docid=3685846746009919856#”
Here's a example result:
"
(interactive)
(let (p1 p2 id url)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq id (buffer-substring-no-properties p1 p2))
(setq id (replace-regexp-in-string "^http://video\\.google\\.com/videoplay\\?docid=" "" id))
(setq id (replace-regexp-in-string "&.+" "" id))
(setq id (replace-regexp-in-string "#$" "" id))
(delete-region p1 p2)
(insert (google-video-string id)
) ))
(defun dailymotion-video-string (video-id)
"Return html code for embedding video of dailymotion.com's VIDEO-ID.
Example call:
(dailymotion-linkify \"x1af0v\")"
(concat
""
)
)
(defun dailymotion-video-linkify ()
"Make the current line into a embeded HTML video object.
Example, if the current line is:
http://www.dailymotion.com/video/xz3am_white-rabbit-jefferson-airplane-li_music
it becomes
"
(interactive)
(let (p1 p2 tmp id)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq tmp (buffer-substring-no-properties p1 p2))
(setq tmp (replace-regexp-in-string "http://www\\.dailymotion\\.com/video/" "" tmp))
(setq tmp (car (split-string tmp "_")))
(setq id tmp)
(delete-region p1 p2)
(insert (dailymotion-video-string id)
) ))
(defun tudou-video-string (video-id)
"Return html code for embedding video of tudou.com's VIDEO-ID.
Example call:
(tudou-video-string \"9OoINUl31dQ\")"
(let (url)
(setq url (concat "http://www.tudou.com/v/" video-id "/v.swf" ))
(concat "" )
) )
(defun tudou-video-linkify ()
"Make the current line into a embeded HTML video object.
Example, if the current line is:
http://www.tudou.com/programs/view/9OoINUl31dQ
it becomes
"
(interactive)
(let (p1 p2 tmp id)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq tmp (buffer-substring-no-properties p1 p2))
(setq tmp (replace-regexp-in-string "http://www\\.tudou\\.com/programs/view/" "" tmp))
(setq tmp (replace-regexp-in-string "/" "" tmp))
(setq id tmp)
(delete-region p1 p2)
(insert (tudou-video-string id)
) ))
(defun redtube-linkify ()
"Make the current line into a embeded HTML video object.
The line can be a youtube ID or full url.
Examples of input line syntax:
http://redtube.com/25635
25635
The current line is the line the cursor is on, that is enclosed by “\n”.
Here's a example result:
"
(interactive)
(let (p1 p2 tmp id fixedurl)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq tmp (buffer-substring-no-properties p1 p2))
(setq tmp (replace-regexp-in-string "http://redtube\\.com/" "" tmp))
(setq tmp (replace-regexp-in-string "http://www\\.redtube\\.com/" "" tmp))
(setq tmp (replace-regexp-in-string "http://embed\\.redtube\\.com/player/?id=" "" tmp))
(setq id tmp)
(setq fixedurl "http://embed.redtube.com/player/?id=")
(delete-region p1 p2)
(insert
(concat
""
)) ))
;; (defun get-current-line-or-region ()
;; "Return current line or text selection if there's one."
;; (interactive)
;; (let (p1 p2)
;; (save-excursion
;; (search-backward "\n" nil t) (forward-char)
;; (setq p1 (point))
;; (search-forward "\n" nil t) (backward-char)
;; (setq p2 (point)))
;; (buffer-substring-no-properties p1 p2)
;; )
;; )
(defun break-video-linkify ()
"Make the current line into a embeded HTML video object.
The current line must be a embeded video html code from break.com.
Example:
Hot Asian Chick Falls Off a Stripper Pole - Watch more Funny Videos
Becomes:
This is valid html.
See: URL `http://xahlee.org/js/html_embed_video.html'"
(interactive)
(let (p1 p2 tmp width height id classif hashcode)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq tmp (buffer-substring-no-properties p1 p2))
(setq tmp (replace-regexp-in-string "\"" "†" tmp)) ; change double quote to something else to avoid tooth pick syndrom in regex
(with-temp-buffer
(insert tmp)
(goto-char (point-min))
(search-forward-regexp "width=†\\([[:digit:]]+\\)†")
(setq width (match-string 1))
(search-forward-regexp "height=†\\([[:digit:]]+\\)†")
(setq height (match-string 1))
(search-forward-regexp "id=†\\([[:digit:]]+\\)†")
(setq id (match-string 1))
(search-forward-regexp "classid=†\\([^†]+\\)†")
(setq classid (match-string 1))
(search-forward-regexp "http://embed\\.break\\.com/\\([^†]+\\)†")
(setq hashcode (match-string 1))
)
(delete-region p1 p2)
(insert (concat "")
) ))