diff options
author | Miguel Ángel Moreno <mail@migalmoreno.com> | 2024-04-19 15:45:04 +0200 |
---|---|---|
committer | Miguel Ángel Moreno <mail@migalmoreno.com> | 2024-04-19 16:35:54 +0200 |
commit | 19797607941a3229c5dae54a3b457e08c89ae207 (patch) | |
tree | 832a6e6de932e0e42f7243351f9b2a571c15f33e /src | |
parent | 390678f88e77082cefe339ce92876a027ad25fb7 (diff) |
feat: add stream radio feature
Diffstat (limited to 'src')
-rw-r--r-- | src/frontend/tubo/components/audio_player.cljs | 7 | ||||
-rw-r--r-- | src/frontend/tubo/components/items.cljs | 7 | ||||
-rw-r--r-- | src/frontend/tubo/events.cljs | 49 | ||||
-rw-r--r-- | src/frontend/tubo/views/stream.cljs | 3 |
4 files changed, 54 insertions, 12 deletions
diff --git a/src/frontend/tubo/components/audio_player.cljs b/src/frontend/tubo/components/audio_player.cljs index 5569a2a..149c963 100644 --- a/src/frontend/tubo/components/audio_player.cljs +++ b/src/frontend/tubo/components/audio_player.cljs @@ -125,10 +125,11 @@ :extra-classes "pl-4 pr-3"] [layout/popover-menu !menu-active? [{:label (if liked? "Remove favorite" "Favorite") - :icon (if liked? - [:i.fa-solid.fa-heart {:style {:color service-color}}] - [:i.fa-solid.fa-heart]) + :icon [:i.fa-solid.fa-heart (when liked? {:style {:color service-color}})] :on-click #(rf/dispatch [(if liked? ::events/remove-from-likes ::events/add-to-likes) current-stream])} + {:label "Play radio" + :icon [:i.fa-solid.fa-tower-cell] + :on-click #(rf/dispatch [::events/start-stream-radio current-stream])} {:label "Add to playlist" :icon [:i.fa-solid.fa-plus] :on-click #(rf/dispatch [::events/add-bookmark-list-modal diff --git a/src/frontend/tubo/components/items.cljs b/src/frontend/tubo/components/items.cljs index cf34911..cdc062d 100644 --- a/src/frontend/tubo/components/items.cljs +++ b/src/frontend/tubo/components/items.cljs @@ -22,10 +22,11 @@ [{:label "Add to queue" :icon [:i.fa-solid.fa-headphones] :on-click #(rf/dispatch [::events/switch-to-audio-player item])} + {:label "Play radio" + :icon [:i.fa-solid.fa-tower-cell] + :on-click #(rf/dispatch [::events/start-stream-radio item])} {:label (if liked? "Remove favorite" "Favorite") - :icon (if liked? - [:i.fa-solid.fa-heart {:style {:color (utils/get-service-color service-id)}}] - [:i.fa-solid.fa-heart]) + :icon [:i.fa-solid.fa-heart (when liked? {:style {:color (utils/get-service-color service-id)}})] :on-click #(rf/dispatch [(if liked? ::events/remove-from-likes ::events/add-to-likes) item])} (if (some #(= (:url %) url) (:items (first (filter #(= (:id %) bookmark-id) bookmarks)))) {:label "Remove from playlist" diff --git a/src/frontend/tubo/events.cljs b/src/frontend/tubo/events.cljs index 5b06707..a48a001 100644 --- a/src/frontend/tubo/events.cljs +++ b/src/frontend/tubo/events.cljs @@ -393,15 +393,25 @@ :fx [[:dispatch [::fetch-audio-player-stream (:url stream) idx (= (count (:media-queue db)) 0)]]]}))) (rf/reg-event-fx + ::start-stream-radio + (fn [{:keys [db]} [_ stream]] + {:fx [[:dispatch [::switch-to-audio-player stream]] + (when (not= (count (:media-queue db)) 0) + [:dispatch [::change-media-queue-pos (count (:media-queue db))]]) + [:dispatch [::fetch-audio-player-related-streams (:url stream)]]]})) + +(rf/reg-event-fx ::enqueue-related-streams [(rf/inject-cofx :store)] (fn [{:keys [db store]} [_ streams]] {:db (assoc db :show-audio-player true) :store (assoc store :show-audio-player true) :fx (into [] (conj - (map #(identity [:dispatch [::add-to-media-queue %]]) streams) - [:dispatch [::fetch-audio-player-stream (:url (first streams)) - (count (:media-queue db)) (= (count (:media-queue db)) 0)]]))})) + (map #(when (= (:type %) "stream") + (identity [:dispatch [::add-to-media-queue %]])) streams) + (when (= (:type (first streams)) "stream") + [:dispatch [::fetch-audio-player-stream (first streams) + (count (:media-queue db)) (= (count (:media-queue db)) 0)]])))})) (rf/reg-event-db ::modal @@ -657,6 +667,12 @@ (api/get-request "/services" [::load-homepage] [::bad-response]))) (rf/reg-event-fx + ::load-audio-player-related-streams + (fn [{:keys [db]} [_ res]] + (let [stream-res (js->clj res :keywordize-keys true)] + {:fx [[:dispatch [::enqueue-related-streams (:related-streams stream-res)]]]}))) + +(rf/reg-event-fx ::load-audio-player-stream [(rf/inject-cofx ::inject/sub [:player])] (fn [{:keys [db player]} [_ idx play? res]] @@ -692,11 +708,32 @@ [::load-stream-page] [::bad-response]))) (rf/reg-event-fx - ::fetch-audio-player-stream - (fn [{:keys [db]} [_ uri idx play?]] + ::audio-player-stream-failure + (fn [{:keys [db]} [_ play? res]] + {:db (assoc db + :show-audio-player-loading false + :player-ready true) + :fx [[:dispatch [::bad-response res]] + (when play? + (if (> (-> db :media-queue count) 1) + [:dispatch [::change-media-queue-pos (-> db :media-queue-pos inc)]] + [:dispatch [::dispose-audio-player]]))]})) + +(rf/reg-event-fx + ::fetch-audio-player-related-streams + (fn [{:keys [db]} [_ uri]] (assoc (api/get-request (str "/streams/" (js/encodeURIComponent uri)) - [::load-audio-player-stream idx play?] [::bad-response]) + [::load-audio-player-related-streams] [::bad-response]) + :db (assoc db :show-audio-player-loading true)))) + +(rf/reg-event-fx + ::fetch-audio-player-stream + (fn [{:keys [db]} [_ stream idx play?]] + (assoc + (api/get-request (str "/streams/" (js/encodeURIComponent (:url stream))) + [::load-audio-player-stream idx play?] + [::audio-player-stream-failure play?]) :db (assoc db :show-audio-player-loading true)))) (rf/reg-event-fx diff --git a/src/frontend/tubo/views/stream.cljs b/src/frontend/tubo/views/stream.cljs index 77ed51a..bc0fd5e 100644 --- a/src/frontend/tubo/views/stream.cljs +++ b/src/frontend/tubo/views/stream.cljs @@ -66,6 +66,9 @@ [{:label "Add to queue" :icon [:i.fa-solid.fa-headphones] :on-click #(rf/dispatch [::events/switch-to-audio-player stream])} + {:label "Play radio" + :icon [:i.fa-solid.fa-tower-cell] + :on-click #(rf/dispatch [::events/start-stream-radio stream])} {:label (if liked? "Remove favorite" "Favorite") :icon (if liked? [:i.fa-solid.fa-heart {:style {:color (utils/get-service-color service-id)}}] |