Published on

Parse youtube information to an org file

(defun org-youtube-info (url)
  "Fetch the title of a YouTube page from its URL and return it as an Org property along with the URL+Date."
  (interactive "Enter the YouTube URL: ")
  (let ((buffer (url-retrieve-synchronously url))
        title)
    (save-excursion
      (set-buffer buffer)
      (goto-char (point-min))
      (if (re-search-forward "<title>\\(.*?\\)</title>" nil t)
          (setq title (match-string 1)))
      (kill-buffer buffer))
    (if title
        (progn
          (org-set-property "TITLE" title)
          (org-set-property "URL" url)
	      (org-set-property "DATE" (format-time-string "%Y-%m-%d"))
	      (org-edit-headline title)
          (message "Title: %s, URL: %s" title url))
      (message "Title not found on the page."))))

This code uses the url-retrieve-synchronously function to download the HTML content of the page and then extracts the title using regular expressions.

It sets the title as the text of the current outline heading, replacing the existing text.