buch_des_monats/src/buchdesmonats/sources/lovelybooks.clj
Aaron Fischer 08f504f303 Generalize codebase and add more datasources.
Fixes #9
Relates #8

* Support mojoreads as a new data source
* Change image file names to hashsums to be more generic
* Clean up the source code by separate relates stuff in own files
* Fix the Chaos Monkeys book
2020-11-10 20:43:04 +01:00

22 lines
784 B
Clojure

(ns buchdesmonats.sources.lovelybooks
(:require [net.cgrand.enlive-html :as html]
[clojure.string :as str]))
(defn encode-url-part [part]
(java.net.URLEncoder/encode part "UTF-8"))
(defn encode-url [url]
(let [parts (map encode-url-part (re-find #"\/autor\/([^/]+)\/([^/]+)\/?" url))
author (nth parts 1)
book-title (nth parts 2)]
(str "https://lovelybooks.de/autor/" author "/" book-title)))
(defn find-cover-image [url]
(let [encoded-url (encode-url url)
src (-> (html/html-resource (java.net.URL. encoded-url))
(html/select [:img.ResponsiveImage.BookCover])
first
(get-in [:attrs :srcset])
(str/split #" "))]
(last (filter #(re-matches #"http.+\.jpg" %) src))))