Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
trueChazza committed Mar 16, 2022
2 parents 4e6f175 + d8f4016 commit 8d382ad
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lib/media_server_web/components/poster_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule MediaServerWeb.Components.PosterComponent do
<div class="group relative">
<div class="w-full bg-gray-200 aspect-[4/6] rounded-md overflow-hidden group-hover:opacity-75 lg:aspect-none">
<img class="h-full object-cover" src={assigns.img_src}>
<img class="h-full object-cover" src={assigns.img_src}>
</div>
<div class="mt-2 flex">
Expand Down
18 changes: 18 additions & 0 deletions lib/media_server_web/live/seasons_live/show.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule MediaServerWeb.SeasonsLive.Show do
use MediaServerWeb, :live_view

alias MediaServerWeb.Repositories.Series
alias MediaServerWeb.Repositories.Episodes

@impl true
def handle_params(%{"serie" => id, "season" => number}, _url, socket) do
serie = Series.get_serie(id)

{
:noreply,
socket
|> assign(:page_title, "#{serie["title"]}: Season #{number}")
|> assign(:episodes, Episodes.get_all(id, number))
}
end
end
34 changes: 34 additions & 0 deletions lib/media_server_web/live/seasons_live/show.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="max-w-4xl mx-auto py-6 px-4">
<ul role="list" class="-my-5 divide-y divide-gray-200">

<%= for item <- @episodes do %>

<li class="py-4">
<div class="sm:flex">
<div class="mb-4 flex-shrink-0 sm:mb-0 sm:mr-4">

<%= if List.first(item["images"]) do %>
<img class="h-48 w-full sm:w-72 object-cover" src={MediaServerWeb.Repositories.Episodes.get_screenshot(item)}>
<% else %>
<svg class="h-48 w-full sm:w-72 border border-gray-300 bg-white text-gray-300" preserveAspectRatio="none" stroke="currentColor" fill="none" viewBox="0 0 200 200" aria-hidden="true">
<path vector-effect="non-scaling-stroke" stroke-width="1" d="M0 0l200 200M0 200L200 0" />
</svg>
<% end %>
</div>
<div>
<h4 class="text-md font-bold"><%= "Season #{item["seasonNumber"]} - Episode #{item["episodeNumber"]}" %></h4>
<p class="mt-1">
<%= item["title"] %>
</p>
<p class="mt-2">
<%= item["overview"] %>
</p>

<%= live_redirect "Play", id: "play-#{ item["id"] }", to: Routes.watch_episode_show_path(@socket, :show, item["id"]), class: "mt-4 inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-slate-600 hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-slate-500" %>
</div>
</div>
</li>

<% end %>
</ul>
</div>
2 changes: 0 additions & 2 deletions lib/media_server_web/live/series_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ defmodule MediaServerWeb.SeriesLive.Show do
use MediaServerWeb, :live_view

alias MediaServerWeb.Repositories.Series
alias MediaServerWeb.Repositories.Episodes

@impl true
def handle_params(%{"serie" => id}, _url, socket) do
Expand All @@ -13,7 +12,6 @@ defmodule MediaServerWeb.SeriesLive.Show do
socket
|> assign(:page_title, serie["title"])
|> assign(:serie, serie)
|> assign(:episodes, Episodes.get_all(id))
}
end
end
42 changes: 8 additions & 34 deletions lib/media_server_web/live/series_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,23 @@


<div class="mt-10">
<div class="pb-5 border-b border-gray-200">
<h3 class="text-lg leading-6 font-medium text-gray-900">
Episodes
</h3>
</div>

<div class="flow-root mt-6">
<ul role="list" class="-my-5 divide-y divide-gray-200">

<%= for item <- @episodes do %>
<div class="mt-3 grid grid-cols-2 gap-y-10 gap-x-6 sm:grid-cols-2 lg:grid-cols-6 xl:gap-x-8">

<li class="py-4">
<div class="sm:flex">
<div class="mb-4 flex-shrink-0 sm:mb-0 sm:mr-4">

<%= if List.first(item["images"]) do %>
<img class="h-48 w-full sm:w-72 object-cover" src={MediaServerWeb.Repositories.Episodes.get_screenshot(item)}>
<% else %>
<svg class="h-48 w-full sm:w-72 border border-gray-300 bg-white text-gray-300" preserveAspectRatio="none" stroke="currentColor" fill="none" viewBox="0 0 200 200" aria-hidden="true">
<path vector-effect="non-scaling-stroke" stroke-width="1" d="M0 0l200 200M0 200L200 0" />
</svg>
<% end %>
</div>
<div>
<h4 class="text-md font-bold"><%= "Season #{item["seasonNumber"]} - Episode #{item["episodeNumber"]}" %></h4>
<p class="mt-1">
<%= item["title"] %>
</p>
<p class="mt-2">
<%= item["overview"] %>
</p>
<%= for item <- @serie["seasons"] |> Enum.filter(fn x -> x["statistics"]["episodeFileCount"] > 0 end) do %>

<%= live_redirect "Play", id: "play-#{ item["id"] }", to: Routes.watch_episode_show_path(@socket, :show, item["id"]), class: "mt-4 inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-slate-600 hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-slate-500" %>
<%= MediaServerWeb.Components.PosterComponent.render(%{
img_src: "",
title: "Season #{ item["seasonNumber"] }",
link: Routes.seasons_show_path(@socket, :show, @serie["id"], item["seasonNumber"])
}) %>
<% end %>
</div>
</div>
</li>

<% end %>
</ul>
</div>

</div>

</div>
</div>
</div>
8 changes: 6 additions & 2 deletions lib/media_server_web/repositories/episodes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ defmodule MediaServerWeb.Repositories.Episodes do
"#{Application.get_env(:media_server, :series_base_url)}/api/v3/#{url}?apikey=#{Application.get_env(:media_server, :series_api_key)}"
end

def get_all(series_id) do
def get_all(series_id, season_number) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} =
HTTPoison.get("#{get_url("episode")}&seriesId=#{series_id}")

Enum.filter(Jason.decode!(body), fn x -> x["hasFile"] end) |> add_images_to_episodes()
Enum.filter(Jason.decode!(body), fn x ->
x["seasonNumber"] === String.to_integer season_number
end)
|> Enum.filter(fn x -> x["hasFile"] end)
|> add_images_to_episodes()
end

def get_episode(id) do
Expand Down
1 change: 1 addition & 0 deletions lib/media_server_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule MediaServerWeb.Router do

live "/series", SeriesLive.Index, :index
live "/series/:serie", SeriesLive.Show, :show
live "/series/:serie/seasons/:season", SeasonsLive.Show, :show

get "/episodes/:episode/stream", StreamEpisodeController, :show

Expand Down
4 changes: 2 additions & 2 deletions test/media_server_web/live/series_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule MediaServerWeb.SeriesLiveTest do

EpisodesFixtures.get_episodes(serie["id"])
|> Enum.each(fn episode ->
{:ok, show_live, _html} = live(conn, Routes.series_show_path(conn, :show, serie["id"]))
{:ok, show_live, _html} = live(conn, Routes.seasons_show_path(conn, :show, serie["id"], episode["seasonNumber"]))

assert show_live |> element("#play-#{episode["id"]}", "Play") |> render_click()
end)
Expand All @@ -50,7 +50,7 @@ defmodule MediaServerWeb.SeriesLiveTest do
test "it should merge episode images with serie episode", %{conn: _conn} do
serie = SeriesFixtures.get_serie()

episodes = Episodes.get_all(serie["id"])
episodes = Episodes.get_all(serie["id"], "1")

assert episodes === [
%{
Expand Down

0 comments on commit 8d382ad

Please sign in to comment.