;; 2010-06-07
;; ∑ http://xahlee.org/
;; c:/Users/xah/web/xahlee_org/Periodic_dosage_dir/sanga_pemci/xx.html
(defun youtube-string (video-id)
"Return html code for embedding video of youtube's VIDEO-ID.
Example call:
(youtube-string \"bFSS826ETlk\")"
(concat "")
)
(defun youtube-string-old (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:
here's old version output
"
(interactive)
(let (p1 p2 inputStr vID)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq inputStr (buffer-substring-no-properties p1 p2))
(string-match "v=\\(.\\{11\\}\\)" inputStr) ; youtube id are 11 chars
(setq vID (match-string 1 inputStr) )
;; (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 vID tmp)
(message "%s" vID)
(delete-region p1 p2)
(insert "\n")
(insert (youtube-string vID) )
(insert "\n\n")
(insert "\n")
(insert "\n")
(search-backward "" )
(backward-char 1)
))
(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.
Example:
“http://video.google.com/videoplay?docid=3685846746009919856#”
⇒
"
(interactive)
(let (p1 p2 vID inputStr)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq inputStr (buffer-substring-no-properties p1 p2))
(string-match "docid=\\(.\\{19\\}\\)" inputStr)
(setq vID (match-string 1 inputStr) )
;; (setq vID (replace-regexp-in-string "^http://video\\.google\\.com/videoplay\\?docid=" "" vID))
;; (setq vID (replace-regexp-in-string "&.+" "" vID))
;; (setq vID (replace-regexp-in-string "#$" "" vID))
(delete-region p1 p2)
(insert (google-video-string vID)
) ))
(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 inputStr tmp vID)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq inputStr (buffer-substring-no-properties p1 p2))
(setq tmp (replace-regexp-in-string "http://www\\.dailymotion\\.com/video/" "" inputStr))
(setq tmp (car (split-string tmp "_")))
(setq vID tmp)
(delete-region p1 p2)
(insert (dailymotion-video-string vID)
) ))
(defun vimeo-linkify ()
"Make the current line into a embeded HTML video object.
Example, if the current line is:
http://vimeo.com/27206452
it becomes
"
(interactive)
(let (p1 p2 inputStr vID)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq inputStr (buffer-substring-no-properties p1 p2))
(string-match "http://vimeo.com/\\([0-9]\\{8\\}\\)" inputStr)
(setq vID (match-string 1 inputStr) )
(delete-region p1 p2)
(insert (concat
"\n"
"\n"
""
) )
(backward-char 24)
))
(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 inputStr tmp vID)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq inputStr (buffer-substring-no-properties p1 p2))
(setq tmp (replace-regexp-in-string "http://www\\.tudou\\.com/programs/view/" "" inputStr))
(setq tmp (replace-regexp-in-string "/" "" tmp))
(setq vID tmp)
(delete-region p1 p2)
(insert (tudou-video-string vID)
) ))
(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 inputStr tmp vID fixedurl)
(setq p1 (line-beginning-position) )
(setq p2 (line-end-position) )
(setq inputStr (buffer-substring-no-properties p1 p2))
(setq tmp (replace-regexp-in-string "http://redtube\\.com/" "" inputStr))
(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 vID 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 vID classid 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 vID (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 "")
) ))