I’m writing code to generate the rss feed of my selfhost podcast and I need a function that would return a type depending on the file extension of podcast item.
For example, if the podcast file (item) has the extension mp4
, I need to return the string video/mp4
. This is needed to generate the tag <enclosure>
as described in A Podcaster’s Guide to RSS.
This problem could be solved through a function to condition enumeration. For example,
(defun podcast-return-type (ext)
"return type string for item file extension"
(cond
((string= ext "m4a") (identity "audio/x-m4a"))
((string= ext "mp4") (identity "video/mp4"))
((string= ext "mp3") (identity "audio/mpeg"))
((string= ext "mov") (identity "video/quicktime"))
((string= ext "m4v") (identity "video/x-m4v"))
((string= ext "pdf") (identity "application/pdf"))
(t (identity "not applyed"))))
But I wanted to solve it through a property list. I ran into a problem: I can’t get the value if the key is stored in a variable.
(setq podcast-list '(mp4 "video/mp4" mp3 "audio/mpeg" pdf "application/pdf")) ;; key value
(setq ext (file-name-extension "~/podcast/podcast-item.mp4")) ---> "mp4"
(plist-get podcast-list ext) ----> nil
(plist-get podcast-list 'mp4) ----> "video/x-m4v"
How can I get the value of a plist if the key is in a variable? Or is there a more elegant way to solve this problem? I feel like the solution is somewhere on the surface, but I’m stuck.