Skip to content

Instantly share code, notes, and snippets.

@ordros
Created May 11, 2014 19:02
Show Gist options
  • Save ordros/6c193b6588dfbbf979e2 to your computer and use it in GitHub Desktop.
Save ordros/6c193b6588dfbbf979e2 to your computer and use it in GitHub Desktop.
(ns libnico.core
(:gen-class)
(:require [net.cgrand.enlive-html :as html]
[clojure.java.io :as io])
(:import java.io.ByteArrayInputStream)
)
(def elements [
:video_id
:title
:description
:thumbnail_url
:first_reserve
:length
:size_high
:size_low
:view_counter
:comment_num
:mylist_counter
:last_res_body
:watch_url
:thumb_type
:embeddable
:no_live_play
:tags
:user_id
:user_nickname])
(def n-elements (count elements))
(defn get-data [sm]
(io/reader (apply str "http://ext.nicovideo.jp/api/getthumbinfo/" sm)))
(defn get-content [c sm]
(let [rdr ((memoize get-data) sm)]
(assoc {} c (first (:content (first (html/select (html/html-resource rdr) [c])))))
))
(defn get-contents [sm]
(map get-content elements (replicate n-elements sm))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment