mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
jellyfin music :)
This commit is contained in:
@@ -27,21 +27,43 @@ class MusicController extends Controller
|
||||
// Get search parameters
|
||||
$search = trim($queryParams['search'] ?? '');
|
||||
|
||||
// Get filter parameters
|
||||
$genres = $queryParams['genres'] ?? [];
|
||||
if (!is_array($genres)) {
|
||||
$genres = [$genres];
|
||||
}
|
||||
$genres = array_filter($genres);
|
||||
|
||||
$artists = $queryParams['artists'] ?? [];
|
||||
if (!is_array($artists)) {
|
||||
$artists = [$artists];
|
||||
}
|
||||
$artists = array_filter($artists);
|
||||
|
||||
// Get view mode
|
||||
$viewMode = $queryParams['view'] ?? 'grid'; // grid, list, covers
|
||||
|
||||
// For now, return empty arrays since Music isn't implemented yet
|
||||
$music = [];
|
||||
$totalCount = 0;
|
||||
// Get sort parameter
|
||||
$sort = $queryParams['sort'] ?? 'title_asc';
|
||||
|
||||
// Get albums with pagination, filters, and sorting
|
||||
$albums = \App\Models\MusicAlbum::getAllWithPagination($this->pdo, $page, $perPage, $search, $genres, $artists, $sort);
|
||||
|
||||
// Get total count for pagination
|
||||
$totalCount = \App\Models\MusicAlbum::getTotalCount($this->pdo, $search, $genres, $artists);
|
||||
|
||||
// Get available filter options
|
||||
$availableGenres = \App\Models\MusicAlbum::getAvailableGenres($this->pdo);
|
||||
$availableArtists = \App\Models\MusicAlbum::getAvailableArtists($this->pdo);
|
||||
|
||||
// Calculate pagination info
|
||||
$totalPages = 0;
|
||||
$hasNextPage = false;
|
||||
$hasPrevPage = false;
|
||||
$totalPages = ceil($totalCount / $perPage);
|
||||
$hasNextPage = $page < $totalPages;
|
||||
$hasPrevPage = $page > 1;
|
||||
|
||||
return $this->view->render($response, 'music/index.twig', [
|
||||
'title' => 'Music',
|
||||
'music' => $music,
|
||||
'albums' => $albums,
|
||||
'pagination' => [
|
||||
'current_page' => $page,
|
||||
'per_page' => $perPage,
|
||||
@@ -54,19 +76,79 @@ class MusicController extends Controller
|
||||
],
|
||||
'search' => $search,
|
||||
'view_mode' => $viewMode,
|
||||
'view_modes' => ['grid', 'list', 'covers']
|
||||
'view_modes' => ['grid', 'list', 'covers'],
|
||||
'filters' => [
|
||||
'genres' => $genres,
|
||||
'artists' => $artists
|
||||
],
|
||||
'available_filters' => [
|
||||
'genres' => $availableGenres,
|
||||
'artists' => $availableArtists
|
||||
],
|
||||
'sort' => $sort,
|
||||
'sort_options' => [
|
||||
'title_asc' => 'Title (A-Z)',
|
||||
'title_desc' => 'Title (Z-A)',
|
||||
'artist_asc' => 'Artist (A-Z)',
|
||||
'artist_desc' => 'Artist (Z-A)',
|
||||
'release_desc' => 'Release Date (Newest First)',
|
||||
'release_asc' => 'Release Date (Oldest First)',
|
||||
'added_desc' => 'Recently Added',
|
||||
'added_asc' => 'Oldest Added'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request, Response $response, $args)
|
||||
{
|
||||
$musicId = (int) $args['id'];
|
||||
$albumId = (int) $args['id'];
|
||||
|
||||
// Get album details
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT ma.*, s.display_name as source_name
|
||||
FROM music_albums ma
|
||||
JOIN sources s ON ma.source_id = s.id
|
||||
WHERE ma.id = :id
|
||||
");
|
||||
$stmt->execute(['id' => $albumId]);
|
||||
$album = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$album) {
|
||||
return $response->withStatus(404);
|
||||
}
|
||||
|
||||
// Decode metadata for display
|
||||
$metadata = json_decode($album['metadata'], true);
|
||||
|
||||
// Get tracks for this album
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT mt.*
|
||||
FROM music_tracks mt
|
||||
WHERE mt.album_id = :album_id
|
||||
ORDER BY mt.track_number ASC, mt.title ASC
|
||||
");
|
||||
$stmt->execute(['album_id' => $albumId]);
|
||||
$tracks = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
// Get artist information
|
||||
$artist = null;
|
||||
if ($album['artist_id']) {
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT ma.*, s.display_name as source_name
|
||||
FROM music_artists ma
|
||||
JOIN sources s ON ma.source_id = s.id
|
||||
WHERE ma.id = :artist_id
|
||||
");
|
||||
$stmt->execute(['artist_id' => $album['artist_id']]);
|
||||
$artist = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// For now, return a placeholder since Music isn't implemented yet
|
||||
return $this->view->render($response, 'music/show.twig', [
|
||||
'title' => 'Music Details',
|
||||
'music' => ['id' => $musicId, 'title' => 'Coming Soon'],
|
||||
'message' => 'Music details page is not yet implemented.'
|
||||
'title' => $album['title'],
|
||||
'album' => $album,
|
||||
'tracks' => $tracks,
|
||||
'artist' => $artist,
|
||||
'metadata' => $metadata
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user