diff options
Diffstat (limited to 'src/backend/tau/api')
-rw-r--r-- | src/backend/tau/api/channel.clj | 52 | ||||
-rw-r--r-- | src/backend/tau/api/comment.clj | 47 | ||||
-rw-r--r-- | src/backend/tau/api/kiosk.clj | 47 | ||||
-rw-r--r-- | src/backend/tau/api/playlist.clj | 51 | ||||
-rw-r--r-- | src/backend/tau/api/search.clj | 49 | ||||
-rw-r--r-- | src/backend/tau/api/service.clj | 24 | ||||
-rw-r--r-- | src/backend/tau/api/stream.clj | 66 |
7 files changed, 336 insertions, 0 deletions
diff --git a/src/backend/tau/api/channel.clj b/src/backend/tau/api/channel.clj new file mode 100644 index 0000000..26d3b34 --- /dev/null +++ b/src/backend/tau/api/channel.clj @@ -0,0 +1,52 @@ +(ns tau.api.channel + (:require + [tau.api.stream :as stream] + [clojure.java.data :as j] + [ring.util.codec :refer [url-decode]]) + (:import + org.schabi.newpipe.extractor.channel.ChannelInfo + org.schabi.newpipe.extractor.NewPipe + org.schabi.newpipe.extractor.Page)) + +(defrecord Channel + [id name description verified? banner avatar + subscriber-count donation-links next-page + related-streams]) + +(defrecord ChannelResult + [name description verified? thumbnail-url url + subscriber-count stream-count]) + +(defrecord ChannelPage + [next-page related-streams]) + +(defn get-channel-result + [channel] + (map->ChannelResult + {:name (.getName channel) + :thumbnail-url (.getThumbnailUrl channel) + :url (.getUrl channel) + :description (.getDescription channel) + :subscriber-count (.getSubscriberCount channel) + :stream-count (.getStreamCount channel) + :verified? (.isVerified channel)})) + +(defn get-channel-info + ([url] + (let [info (ChannelInfo/getInfo (url-decode url))] + (map->Channel + {:id (.getId info) + :name (.getName info) + :verified? (.isVerified info) + :banner (.getBannerUrl info) + :avatar (.getAvatarUrl info) + :subscriber-count (.getSubscriberCount info) + :donation-links (.getDonationLinks info) + :next-page (j/from-java (.getNextPage info)) + :related-streams (map #(stream/get-stream-result %) (.getRelatedItems info))}))) + ([url page-url] + (let [service (NewPipe/getServiceByUrl (url-decode url)) + info (ChannelInfo/getMoreItems service url (Page. (url-decode page-url)))] + (map->ChannelPage + {:related-streams (map #(stream/get-stream-result %) (.getItems info)) + :next-page (j/from-java (.getNextPage info))})))) diff --git a/src/backend/tau/api/comment.clj b/src/backend/tau/api/comment.clj new file mode 100644 index 0000000..18881cb --- /dev/null +++ b/src/backend/tau/api/comment.clj @@ -0,0 +1,47 @@ +(ns tau.api.comment + (:require + [clojure.java.data :as j] + [ring.util.codec :refer [url-decode]]) + (:import + org.schabi.newpipe.extractor.NewPipe + org.schabi.newpipe.extractor.Page + org.schabi.newpipe.extractor.comments.CommentsInfoItem + org.schabi.newpipe.extractor.comments.CommentsInfo)) + +(defrecord CommentsPage + [next-page disabled? comments]) + +(defrecord Comment + [id text upload-name upload-avatar upload-date upload-url + upload-verified? like-count hearted-by-upload? pinned? replies]) + +(defn get-comment-result + [comment] + (map->Comment + {:id (.getCommentId comment) + :text (.getCommentText comment) + :upload-name (.getUploaderName comment) + :upload-avatar (.getUploaderAvatarUrl comment) + :upload-date (.getTextualUploadDate comment) + :upload-url (.getUploaderUrl comment) + :upload-verified? (.isUploaderVerified comment) + :like-count (.getLikeCount comment) + :hearted-by-upload? (.isHeartedByUploader comment) + :pinned? (.isPinned comment) + :replies (when (.getReplies comment) + (j/from-java (.getReplies comment)))})) + +(defn get-comments-info + ([url] + (let [info (CommentsInfo/getInfo (url-decode url))] + (map->CommentsPage + {:comments (map #(get-comment-result %) (.getRelatedItems info)) + :next-page (j/from-java (.getNextPage info)) + :disabled? (.isCommentsDisabled info)}))) + ([url page-url] + (let [service (NewPipe/getServiceByUrl (url-decode url)) + info (CommentsInfo/getMoreItems service url (Page. (url-decode page-url)))] + (map->CommentsPage + {:comments (map #(get-comment-result %) (.getItems info)) + :next-page (j/from-java (.getNextPage info)) + :disabled? false})))) diff --git a/src/backend/tau/api/kiosk.clj b/src/backend/tau/api/kiosk.clj new file mode 100644 index 0000000..81e0030 --- /dev/null +++ b/src/backend/tau/api/kiosk.clj @@ -0,0 +1,47 @@ +(ns tau.api.kiosk + (:require + [clojure.java.data :as j] + [tau.api.stream :as stream] + [ring.util.codec :refer [url-decode]]) + (:import + org.schabi.newpipe.extractor.StreamingService + org.schabi.newpipe.extractor.Page + org.schabi.newpipe.extractor.kiosk.KioskInfo + org.schabi.newpipe.extractor.NewPipe)) + +(defrecord KioskList + [default-kiosk available-kiosks]) + +(defrecord Kiosk + [id url next-page related-streams]) + +(defrecord KioskPage + [next-page related-streams]) + +(defn get-kiosk-info + ([kiosk-id service-id] + (let [service (NewPipe/getService service-id) + extractor (.getExtractorById (.getKioskList service) kiosk-id nil) + info (KioskInfo/getInfo extractor)] + (map->Kiosk + {:id (.getId info) + :url (.getUrl info) + :next-page (j/from-java (.getNextPage info)) + :related-streams (map #(stream/get-stream-result %) (.getRelatedItems info))}))) + ([kiosk-id service-id page-url] + (let [service (NewPipe/getService service-id) + extractor (.getExtractorById (.getKioskList service) kiosk-id nil) + url (url-decode page-url) + kiosk-info (KioskInfo/getInfo extractor) + info (KioskInfo/getMoreItems service (.getUrl kiosk-info) (Page. url))] + (map->KioskPage + {:next-page (j/from-java (.getNextPage info)) + :related-streams (map #(stream/get-stream-result %) (.getItems info))})))) + +(defn get-kiosk-list-info + [service-id] + (let [service (NewPipe/getService service-id) + kiosks (.getKioskList service)] + (map->KioskList + {:default-kiosk (.getDefaultKioskId kiosks) + :available-kiosks (.getAvailableKiosks kiosks)}))) diff --git a/src/backend/tau/api/playlist.clj b/src/backend/tau/api/playlist.clj new file mode 100644 index 0000000..ccc0d6a --- /dev/null +++ b/src/backend/tau/api/playlist.clj @@ -0,0 +1,51 @@ +(ns tau.api.playlist + (:require + [clojure.java.data :as j] + [tau.api.stream :as stream] + [ring.util.codec :refer [url-decode]]) + (:import + org.schabi.newpipe.extractor.playlist.PlaylistInfo + org.schabi.newpipe.extractor.Page + org.schabi.newpipe.extractor.NewPipe)) + +(defrecord Playlist + [id name playlist-type thumbnail-url uploader-name uploader-url + uploader-avatar banner-url next-page stream-count related-streams]) + +(defrecord PlaylistResult + [name thumbnail-url url upload-author stream-count]) + +(defrecord PlaylistPage + [next-page related-streams]) + +(defn get-playlist-result + [playlist] + (map->PlaylistResult + {:name (.getName playlist) + :thumbnail-url (.getThumbnailUrl playlist) + :url (.getUrl playlist) + :upload-author (.getUploaderName playlist) + :stream-count (.getStreamCount playlist)})) + +(defn get-playlist-info + ([url] + (let [service (NewPipe/getServiceByUrl (url-decode url)) + info (PlaylistInfo/getInfo service (url-decode url))] + (map->Playlist + {:id (.getId info) + :name (.getName info) + :playlist-type (j/from-java (.getPlaylistType info)) + :thumbnail-url (.getThumbnailUrl info) + :banner-url (.getBannerUrl info) + :uploader-name (.getUploaderName info) + :uploader-url (.getUploaderUrl info) + :uploader-avatar (.getUploaderAvatarUrl info) + :stream-count (.getStreamCount info) + :next-page (j/from-java (.getNextPage info)) + :related-streams (map #(stream/get-stream-result %) (.getRelatedItems info))}))) + ([url page-url] + (let [service (NewPipe/getServiceByUrl (url-decode url)) + info (PlaylistInfo/getMoreItems service url (Page. (url-decode page-url)))] + (map->PlaylistPage + {:next-page (j/from-java (.getNextPage info)) + :related-streams (map #(stream/get-stream-result %) (.getItems info))})))) diff --git a/src/backend/tau/api/search.clj b/src/backend/tau/api/search.clj new file mode 100644 index 0000000..4969f10 --- /dev/null +++ b/src/backend/tau/api/search.clj @@ -0,0 +1,49 @@ +(ns tau.api.search + (:require + [tau.api.stream :as stream] + [tau.api.channel :as channel] + [tau.api.playlist :as playlist] + [clojure.java.data :as j] + [ring.util.codec :refer [url-encode url-decode]]) + (:import + org.schabi.newpipe.extractor.search.SearchInfo + org.schabi.newpipe.extractor.InfoItem + org.schabi.newpipe.extractor.NewPipe + org.schabi.newpipe.extractor.Page)) + +(defrecord SearchResult + [items next-page search-suggestion corrected-search?]) + +(defrecord SearchResultPage + [items next-page]) + +(defn get-search-results + [items] + (map #(case (.name (.getInfoType %)) + "STREAM" (stream/get-stream-result %) + "CHANNEL" (channel/get-channel-result %) + "PLAYLIST" (playlist/get-playlist-result %)) + items)) + +(defn get-search-info + ([service-id query content-filters sort-filter] + (let [service (NewPipe/getService service-id) + query-handler (.. service + (getSearchQHFactory) + (fromQuery query (or content-filters '()) (or sort-filter ""))) + info (SearchInfo/getInfo service query-handler)] + (map->SearchResult + {:items (get-search-results (.getRelatedItems info)) + :next-page (j/from-java (.getNextPage info)) + :search-suggestion (.getSearchSuggestion info) + :corrected-search? (.isCorrectedSearch info)}))) + ([service-id query content-filters sort-filter page-url] + (let [service (NewPipe/getService service-id) + url (url-decode page-url) + query-handler (.. service + (getSearchQHFactory) + (fromQuery query (or content-filters '()) (or sort-filter ""))) + info (SearchInfo/getMoreItems service query-handler (Page. url))] + (map->SearchResultPage + {:items (get-search-results (.getItems info)) + :next-page (j/from-java (.getNextPage info))})))) diff --git a/src/backend/tau/api/service.clj b/src/backend/tau/api/service.clj new file mode 100644 index 0000000..de2e994 --- /dev/null +++ b/src/backend/tau/api/service.clj @@ -0,0 +1,24 @@ +(ns tau.api.service + (:require + [clojure.java.data :as j] + [tau.api.kiosk :as kiosk]) + (:import + org.schabi.newpipe.extractor.NewPipe + org.schabi.newpipe.extractor.kiosk.KioskList + org.schabi.newpipe.extractor.StreamingService)) + +(defrecord Service + [id info base-url kiosk-list]) + +(defn get-service-info + [service] + (map->Service + {:id (.getServiceId service) + :info (j/from-java (.getServiceInfo service)) + :base-url (.getBaseUrl service) + :kiosk-list (map #(kiosk/get-kiosk-info % (.getServiceId service)) + (.getAvailableKiosks (.getKioskList service)))})) + +(defn get-service-list-info + [] + (map #(get-service-info %) (NewPipe/getServices))) diff --git a/src/backend/tau/api/stream.clj b/src/backend/tau/api/stream.clj new file mode 100644 index 0000000..d0a7c81 --- /dev/null +++ b/src/backend/tau/api/stream.clj @@ -0,0 +1,66 @@ +(ns tau.api.stream + (:require + [clojure.java.data :as j] + [ring.util.codec :refer [url-decode]]) + (:import + org.schabi.newpipe.extractor.stream.StreamInfo + org.schabi.newpipe.extractor.NewPipe + org.schabi.newpipe.extractor.localization.DateWrapper + java.time.Instant)) + +(defrecord Stream + [name description upload-date + upload-author upload-url upload-avatar + thumbnail-url service-id duration view-count like-count + dislike-count subscriber-count upload-verified? hls-url + dash-mpd-url category tags audio-streams video-streams + related-streams]) + +(defrecord StreamResult + [name url thumbnail-url upload-author upload-url + upload-avatar upload-date short-description + duration view-count uploaded verified?]) + +(defn get-stream-result + [stream] + (map->StreamResult + {:url (.getUrl stream) + :name (.getName stream) + :thumbnail-url (.getThumbnailUrl stream) + :upload-author (.getUploaderName stream) + :upload-url (.getUploaderUrl stream) + :upload-avatar (.getUploaderAvatarUrl stream) + :upload-date (.getTextualUploadDate stream) + :short-description (.getShortDescription stream) + :duration (.getDuration stream) + :view-count (.getViewCount stream) + :uploaded (if (.getUploadDate stream) + (.. stream (getUploadDate) (offsetDateTime) (toInstant) (toEpochMilli)) + -1) + :verified? (.isUploaderVerified stream)})) + +(defn get-stream-info + [url] + (let [info (StreamInfo/getInfo (url-decode url))] + (map->Stream + {:name (.getName info) + :description (.. info (getDescription) (getContent)) + :upload-date (.getTextualUploadDate info) + :upload-author (.getUploaderName info) + :upload-url (.getUploaderUrl info) + :upload-avatar (.getUploaderAvatarUrl info) + :upload-verified? (.isUploaderVerified info) + :service-id (.getServiceId info) + :thumbnail-url (.getThumbnailUrl info) + :duration (.getDuration info) + :tags (.getTags info) + :category (.getCategory info) + :view-count (.getViewCount info) + :like-count (.getLikeCount info) + :dislike-count (.getDislikeCount info) + :subscriber-count (.getUploaderSubscriberCount info) + :audio-streams (j/from-java (.getAudioStreams info)) + :video-streams (j/from-java (.getVideoStreams info)) + :hls-url (.getHlsUrl info) + :dash-mpd-url (.getDashMpdUrl info) + :related-streams (map #(get-stream-result %) (.getRelatedStreams info))}))) |