jellyfin music :)

This commit is contained in:
Lars Behrends
2025-11-10 05:06:26 +01:00
parent 0530f00cbf
commit aed9d87c5c
10 changed files with 1994 additions and 94 deletions

View File

@@ -472,7 +472,7 @@ class AdminController extends AdminBaseController
// Validate sync type based on source type // Validate sync type based on source type
if ($source['name'] === 'jellyfin') { if ($source['name'] === 'jellyfin') {
$validSyncTypes = ['full', 'incremental', 'all', 'movies', 'tvshows', 'cleanup']; $validSyncTypes = ['full', 'incremental', 'all', 'movies', 'tvshows', 'music', 'cleanup'];
if (!in_array($syncType, $validSyncTypes)) { if (!in_array($syncType, $validSyncTypes)) {
return $this->json($response, [ return $this->json($response, [
'success' => false, 'success' => false,

View File

@@ -27,21 +27,43 @@ class MusicController extends Controller
// Get search parameters // Get search parameters
$search = trim($queryParams['search'] ?? ''); $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 // Get view mode
$viewMode = $queryParams['view'] ?? 'grid'; // grid, list, covers $viewMode = $queryParams['view'] ?? 'grid'; // grid, list, covers
// For now, return empty arrays since Music isn't implemented yet // Get sort parameter
$music = []; $sort = $queryParams['sort'] ?? 'title_asc';
$totalCount = 0;
// 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 // Calculate pagination info
$totalPages = 0; $totalPages = ceil($totalCount / $perPage);
$hasNextPage = false; $hasNextPage = $page < $totalPages;
$hasPrevPage = false; $hasPrevPage = $page > 1;
return $this->view->render($response, 'music/index.twig', [ return $this->view->render($response, 'music/index.twig', [
'title' => 'Music', 'title' => 'Music',
'music' => $music, 'albums' => $albums,
'pagination' => [ 'pagination' => [
'current_page' => $page, 'current_page' => $page,
'per_page' => $perPage, 'per_page' => $perPage,
@@ -54,19 +76,79 @@ class MusicController extends Controller
], ],
'search' => $search, 'search' => $search,
'view_mode' => $viewMode, '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) 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', [ return $this->view->render($response, 'music/show.twig', [
'title' => 'Music Details', 'title' => $album['title'],
'music' => ['id' => $musicId, 'title' => 'Coming Soon'], 'album' => $album,
'message' => 'Music details page is not yet implemented.' 'tracks' => $tracks,
'artist' => $artist,
'metadata' => $metadata
]); ]);
} }
} }

235
app/Models/MusicAlbum.php Normal file
View File

@@ -0,0 +1,235 @@
<?php
namespace App\Models;
class MusicAlbum extends Model
{
protected string $table = 'music_albums';
protected array $fillable = [
'title',
'artist_name',
'release_date',
'genre',
'track_count',
'total_duration_seconds',
'cover_url',
'spotify_id',
'musicbrainz_id',
'is_favorite',
'metadata',
'artist_id',
'source_id'
];
protected array $casts = [
'release_date' => 'date',
'track_count' => 'int',
'total_duration_seconds' => 'int',
'is_favorite' => 'bool'
];
public function source()
{
$stmt = $this->pdo->prepare("SELECT * FROM sources WHERE id = :source_id");
$stmt->execute(['source_id' => $this->source_id]);
$sourceData = $stmt->fetch(\PDO::FETCH_ASSOC);
return $sourceData ? new Source($this->pdo, $sourceData) : null;
}
/**
* Get the artist for this album
*/
public function artist()
{
$stmt = $this->pdo->prepare("SELECT * FROM music_artists WHERE id = :artist_id");
$stmt->execute(['artist_id' => $this->artist_id]);
$artistData = $stmt->fetch(\PDO::FETCH_ASSOC);
return $artistData ? new MusicArtist($this->pdo, $artistData) : null;
}
/**
* Get all tracks for this album
*/
public function tracks()
{
$stmt = $this->pdo->prepare("
SELECT * FROM music_tracks
WHERE album_id = :album_id
ORDER BY track_number ASC, title ASC
");
$stmt->execute(['album_id' => $this->id]);
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
/**
* Toggle favorite status
*/
public function toggleFavorite(): bool
{
return $this->update($this->id, [
'is_favorite' => !$this->is_favorite
]);
}
/**
* Get total count of albums with optional filters
*/
public static function getTotalCount(\PDO $pdo, string $search = '', array $genres = [], array $artists = []): int
{
$where = [];
$params = [];
$sql = "SELECT COUNT(*) as count FROM music_albums ma JOIN sources s ON ma.source_id = s.id";
if (!empty($search)) {
$where[] = "(ma.title LIKE :search OR ma.artist_name LIKE :search)";
$params[':search'] = "%$search%";
}
if (!empty($genres)) {
$genreConditions = [];
foreach ($genres as $i => $genre) {
$param = ":genre_$i";
$genreConditions[] = "ma.genre LIKE $param";
$params[$param] = "%$genre%";
}
$where[] = "(" . implode(' OR ', $genreConditions) . ")";
}
if (!empty($artists)) {
$artistConditions = [];
foreach ($artists as $i => $artist) {
$param = ":artist_$i";
$artistConditions[] = "ma.artist_name LIKE $param";
$params[$param] = "%$artist%";
}
$where[] = "(" . implode(' OR ', $artistConditions) . ")";
}
if (!empty($where)) {
$sql .= " WHERE " . implode(' AND ', $where);
}
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
return (int)$stmt->fetchColumn();
}
/**
* Get paginated albums with optional filters
*/
public static function getAllWithPagination(
\PDO $pdo,
int $page = 1,
int $perPage = 20,
string $search = '',
array $genres = [],
array $artists = [],
string $sort = 'title_asc'
): array {
$offset = ($page - 1) * $perPage;
$where = [];
$params = [];
if (!empty($search)) {
$where[] = "(title LIKE :search OR artist_name LIKE :search)";
$params[':search'] = "%$search%";
}
if (!empty($genres)) {
$genreConditions = [];
foreach ($genres as $i => $genre) {
$param = ":genre$i";
$genreConditions[] = "genre LIKE $param";
$params[$param] = "%$genre%";
}
$where[] = "(" . implode(' OR ', $genreConditions) . ")";
}
if (!empty($artists)) {
$artistConditions = [];
foreach ($artists as $i => $artist) {
$param = ":artist$i";
$artistConditions[] = "artist_name LIKE $param";
$params[$param] = "%$artist%";
}
$where[] = "(" . implode(' OR ', $artistConditions) . ")";
}
// Determine sort order
$orderBy = 'title ASC';
switch ($sort) {
case 'title_desc':
$orderBy = 'title DESC';
break;
case 'artist_asc':
$orderBy = 'artist_name ASC';
break;
case 'artist_desc':
$orderBy = 'artist_name DESC';
break;
case 'release_asc':
$orderBy = 'release_date ASC';
break;
case 'release_desc':
$orderBy = 'release_date DESC';
break;
}
$sql = "SELECT ma.*, s.display_name as source_name FROM music_albums ma JOIN sources s ON ma.source_id = s.id";
if (!empty($where)) {
$sql .= " WHERE " . implode(' AND ', $where);
}
$sql .= " ORDER BY $orderBy LIMIT :limit OFFSET :offset";
$stmt = $pdo->prepare($sql);
// Bind parameters
foreach ($params as $key => $value) {
$stmt->bindValue($key, $value);
}
$stmt->bindValue(':limit', $perPage, \PDO::PARAM_INT);
$stmt->bindValue(':offset', $offset, \PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
/**
* Get all unique genres from albums
*/
public static function getAvailableGenres(\PDO $pdo): array
{
$stmt = $pdo->query("SELECT DISTINCT genre FROM music_albums WHERE genre IS NOT NULL AND genre != '' ORDER BY genre");
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
}
/**
* Get all unique artists from albums
*/
public static function getAvailableArtists(\PDO $pdo): array
{
$stmt = $pdo->query("SELECT DISTINCT artist_name FROM music_albums WHERE artist_name IS NOT NULL AND artist_name != '' ORDER BY artist_name");
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
}
/**
* Get album statistics
*/
public static function getStats(\PDO $pdo): array
{
$stmt = $pdo->query("
SELECT
COUNT(*) as total_albums,
COUNT(CASE WHEN is_favorite = 1 THEN 1 END) as favorite_albums,
SUM(track_count) as total_tracks,
SUM(total_duration_seconds) as total_duration
FROM music_albums
");
return $stmt->fetch(\PDO::FETCH_ASSOC);
}
}

197
app/Models/MusicArtist.php Normal file
View File

@@ -0,0 +1,197 @@
<?php
namespace App\Models;
class MusicArtist extends Model
{
protected string $table = 'music_artists';
protected array $fillable = [
'name',
'biography',
'formed_date',
'genre',
'country',
'image_url',
'banner_url',
'spotify_id',
'musicbrainz_id',
'is_favorite',
'metadata',
'source_id'
];
protected array $casts = [
'formed_date' => 'date',
'is_favorite' => 'bool'
];
public function source()
{
$stmt = $this->pdo->prepare("SELECT * FROM sources WHERE id = :source_id");
$stmt->execute(['source_id' => $this->source_id]);
$sourceData = $stmt->fetch(\PDO::FETCH_ASSOC);
return $sourceData ? new Source($this->pdo, $sourceData) : null;
}
/**
* Get all albums by this artist
*/
public function albums()
{
$stmt = $this->pdo->prepare("
SELECT * FROM music_albums
WHERE artist_id = :artist_id
ORDER BY release_date DESC, title ASC
");
$stmt->execute(['artist_id' => $this->id]);
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
/**
* Get all tracks by this artist
*/
public function tracks()
{
$stmt = $this->pdo->prepare("
SELECT * FROM music_tracks
WHERE artist_id = :artist_id
ORDER BY album_name ASC, track_number ASC, title ASC
");
$stmt->execute(['artist_id' => $this->id]);
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
/**
* Toggle favorite status
*/
public function toggleFavorite(): bool
{
return $this->update($this->id, [
'is_favorite' => !$this->is_favorite
]);
}
/**
* Get total count of artists with optional filters
*/
public static function getTotalCount(\PDO $pdo, string $search = '', array $genres = []): int
{
$where = [];
$params = [];
$sql = "SELECT COUNT(*) as count FROM music_artists ma JOIN sources s ON ma.source_id = s.id";
if (!empty($search)) {
$where[] = "(ma.name LIKE :search OR ma.biography LIKE :search)";
$params[':search'] = "%$search%";
}
if (!empty($genres)) {
$genreConditions = [];
foreach ($genres as $i => $genre) {
$param = ":genre_$i";
$genreConditions[] = "ma.genre LIKE $param";
$params[$param] = "%$genre%";
}
$where[] = "(" . implode(' OR ', $genreConditions) . ")";
}
if (!empty($where)) {
$sql .= " WHERE " . implode(' AND ', $where);
}
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
return (int)$stmt->fetchColumn();
}
/**
* Get paginated artists with optional filters
*/
public static function getAllWithPagination(
\PDO $pdo,
int $page = 1,
int $perPage = 20,
string $search = '',
array $genres = [],
string $sort = 'name_asc'
): array {
$offset = ($page - 1) * $perPage;
$where = [];
$params = [];
if (!empty($search)) {
$where[] = "(name LIKE :search OR biography LIKE :search)";
$params[':search'] = "%$search%";
}
if (!empty($genres)) {
$genreConditions = [];
foreach ($genres as $i => $genre) {
$param = ":genre$i";
$genreConditions[] = "genre LIKE $param";
$params[$param] = "%$genre%";
}
$where[] = "(" . implode(' OR ', $genreConditions) . ")";
}
// Determine sort order
$orderBy = 'name ASC';
switch ($sort) {
case 'name_desc':
$orderBy = 'name DESC';
break;
case 'formed_asc':
$orderBy = 'formed_date ASC';
break;
case 'formed_desc':
$orderBy = 'formed_date DESC';
break;
}
$sql = "SELECT ma.*, s.display_name as source_name FROM music_artists ma JOIN sources s ON ma.source_id = s.id";
if (!empty($where)) {
$sql .= " WHERE " . implode(' AND ', $where);
}
$sql .= " ORDER BY $orderBy LIMIT :limit OFFSET :offset";
$stmt = $pdo->prepare($sql);
// Bind parameters
foreach ($params as $key => $value) {
$stmt->bindValue($key, $value);
}
$stmt->bindValue(':limit', $perPage, \PDO::PARAM_INT);
$stmt->bindValue(':offset', $offset, \PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
/**
* Get all unique genres from artists
*/
public static function getAvailableGenres(\PDO $pdo): array
{
$stmt = $pdo->query("SELECT DISTINCT genre FROM music_artists WHERE genre IS NOT NULL AND genre != '' ORDER BY genre");
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
}
/**
* Get artist statistics
*/
public static function getStats(\PDO $pdo): array
{
$stmt = $pdo->query("
SELECT
COUNT(*) as total_artists,
COUNT(CASE WHEN is_favorite = 1 THEN 1 END) as favorite_artists,
COUNT(DISTINCT genre) as total_genres
FROM music_artists
");
return $stmt->fetch(\PDO::FETCH_ASSOC);
}
}

327
app/Models/MusicTrack.php Normal file
View File

@@ -0,0 +1,327 @@
<?php
namespace App\Models;
class MusicTrack extends Model
{
protected string $table = 'music_tracks';
protected array $fillable = [
'title',
'artist_name',
'album_name',
'track_number',
'duration_seconds',
'genre',
'release_date',
'play_count',
'is_favorite',
'metadata',
'artist_id',
'album_id',
'source_id',
'last_played_at'
];
protected array $casts = [
'track_number' => 'int',
'duration_seconds' => 'int',
'play_count' => 'int',
'is_favorite' => 'bool',
'release_date' => 'date',
'last_played_at' => 'datetime'
];
public function source()
{
$stmt = $this->pdo->prepare("SELECT * FROM sources WHERE id = :source_id");
$stmt->execute(['source_id' => $this->source_id]);
$sourceData = $stmt->fetch(\PDO::FETCH_ASSOC);
return $sourceData ? new Source($this->pdo, $sourceData) : null;
}
/**
* Get the artist for this track
*/
public function artist()
{
$stmt = $this->pdo->prepare("SELECT * FROM music_artists WHERE id = :artist_id");
$stmt->execute(['artist_id' => $this->artist_id]);
$artistData = $stmt->fetch(\PDO::FETCH_ASSOC);
return $artistData ? new MusicArtist($this->pdo, $artistData) : null;
}
/**
* Get the album for this track
*/
public function album()
{
if (!$this->album_id) {
return null;
}
$stmt = $this->pdo->prepare("SELECT * FROM music_albums WHERE id = :album_id");
$stmt->execute(['album_id' => $this->album_id]);
$albumData = $stmt->fetch(\PDO::FETCH_ASSOC);
return $albumData ? new MusicAlbum($this->pdo, $albumData) : null;
}
/**
* Toggle favorite status
*/
public function toggleFavorite(): bool
{
return $this->update($this->id, [
'is_favorite' => !$this->is_favorite
]);
}
/**
* Increment play count and update last played time
*/
public function markAsPlayed(): bool
{
return $this->update($this->id, [
'play_count' => $this->play_count + 1,
'last_played_at' => date('Y-m-d H:i:s')
]);
}
/**
* Get total count of tracks with optional filters
*/
public static function getTotalCount(\PDO $pdo, string $search = '', array $genres = [], array $artists = [], array $albums = []): int
{
$where = [];
$params = [];
$sql = "SELECT COUNT(*) as count FROM music_tracks mt JOIN sources s ON mt.source_id = s.id";
if (!empty($search)) {
$where[] = "(mt.title LIKE :search OR mt.artist_name LIKE :search OR mt.album_name LIKE :search)";
$params[':search'] = "%$search%";
}
if (!empty($genres)) {
$genreConditions = [];
foreach ($genres as $i => $genre) {
$param = ":genre_$i";
$genreConditions[] = "mt.genre LIKE $param";
$params[$param] = "%$genre%";
}
$where[] = "(" . implode(' OR ', $genreConditions) . ")";
}
if (!empty($artists)) {
$artistConditions = [];
foreach ($artists as $i => $artist) {
$param = ":artist_$i";
$artistConditions[] = "mt.artist_name LIKE $param";
$params[$param] = "%$artist%";
}
$where[] = "(" . implode(' OR ', $artistConditions) . ")";
}
if (!empty($albums)) {
$albumConditions = [];
foreach ($albums as $i => $album) {
$param = ":album_$i";
$albumConditions[] = "mt.album_name LIKE $param";
$params[$param] = "%$album%";
}
$where[] = "(" . implode(' OR ', $albumConditions) . ")";
}
if (!empty($where)) {
$sql .= " WHERE " . implode(' AND ', $where);
}
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
return (int)$stmt->fetchColumn();
}
/**
* Get paginated tracks with optional filters
*/
public static function getAllWithPagination(
\PDO $pdo,
int $page = 1,
int $perPage = 20,
string $search = '',
array $genres = [],
array $artists = [],
array $albums = [],
string $sort = 'title_asc'
): array {
$offset = ($page - 1) * $perPage;
$where = [];
$params = [];
if (!empty($search)) {
$where[] = "(title LIKE :search OR artist_name LIKE :search OR album_name LIKE :search)";
$params[':search'] = "%$search%";
}
if (!empty($genres)) {
$genreConditions = [];
foreach ($genres as $i => $genre) {
$param = ":genre$i";
$genreConditions[] = "genre LIKE $param";
$params[$param] = "%$genre%";
}
$where[] = "(" . implode(' OR ', $genreConditions) . ")";
}
if (!empty($artists)) {
$artistConditions = [];
foreach ($artists as $i => $artist) {
$param = ":artist$i";
$artistConditions[] = "artist_name LIKE $param";
$params[$param] = "%$artist%";
}
$where[] = "(" . implode(' OR ', $artistConditions) . ")";
}
if (!empty($albums)) {
$albumConditions = [];
foreach ($albums as $i => $album) {
$param = ":album$i";
$albumConditions[] = "album_name LIKE $param";
$params[$param] = "%$album%";
}
$where[] = "(" . implode(' OR ', $albumConditions) . ")";
}
// Determine sort order
$orderBy = 'title ASC';
switch ($sort) {
case 'title_desc':
$orderBy = 'title DESC';
break;
case 'artist_asc':
$orderBy = 'artist_name ASC';
break;
case 'artist_desc':
$orderBy = 'artist_name DESC';
break;
case 'album_asc':
$orderBy = 'album_name ASC';
break;
case 'album_desc':
$orderBy = 'album_name DESC';
break;
case 'duration_asc':
$orderBy = 'duration_seconds ASC';
break;
case 'duration_desc':
$orderBy = 'duration_seconds DESC';
break;
case 'play_count_desc':
$orderBy = 'play_count DESC';
break;
case 'last_played_desc':
$orderBy = 'last_played_at DESC NULLS LAST';
break;
}
$sql = "SELECT mt.*, s.display_name as source_name FROM music_tracks mt JOIN sources s ON mt.source_id = s.id";
if (!empty($where)) {
$sql .= " WHERE " . implode(' AND ', $where);
}
$sql .= " ORDER BY $orderBy LIMIT :limit OFFSET :offset";
$stmt = $pdo->prepare($sql);
// Bind parameters
foreach ($params as $key => $value) {
$stmt->bindValue($key, $value);
}
$stmt->bindValue(':limit', $perPage, \PDO::PARAM_INT);
$stmt->bindValue(':offset', $offset, \PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
/**
* Get all unique genres from tracks
*/
public static function getAvailableGenres(\PDO $pdo): array
{
$stmt = $pdo->query("SELECT DISTINCT genre FROM music_tracks WHERE genre IS NOT NULL AND genre != '' ORDER BY genre");
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
}
/**
* Get all unique artists from tracks
*/
public static function getAvailableArtists(\PDO $pdo): array
{
$stmt = $pdo->query("SELECT DISTINCT artist_name FROM music_tracks WHERE artist_name IS NOT NULL AND artist_name != '' ORDER BY artist_name");
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
}
/**
* Get all unique albums from tracks
*/
public static function getAvailableAlbums(\PDO $pdo): array
{
$stmt = $pdo->query("SELECT DISTINCT album_name FROM music_tracks WHERE album_name IS NOT NULL AND album_name != '' ORDER BY album_name");
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
}
/**
* Get track statistics
*/
public static function getStats(\PDO $pdo): array
{
$stmt = $pdo->query("
SELECT
COUNT(*) as total_tracks,
COUNT(CASE WHEN is_favorite = 1 THEN 1 END) as favorite_tracks,
SUM(play_count) as total_plays,
SUM(duration_seconds) as total_duration,
AVG(duration_seconds) as avg_duration
FROM music_tracks
");
return $stmt->fetch(\PDO::FETCH_ASSOC);
}
/**
* Get recently played tracks
*/
public static function getRecentlyPlayed(\PDO $pdo, int $limit = 10): array
{
$stmt = $pdo->prepare("
SELECT mt.*, s.display_name as source_name
FROM music_tracks mt
JOIN sources s ON mt.source_id = s.id
WHERE mt.last_played_at IS NOT NULL
ORDER BY mt.last_played_at DESC
LIMIT :limit
");
$stmt->execute(['limit' => $limit]);
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
/**
* Get most played tracks
*/
public static function getMostPlayed(\PDO $pdo, int $limit = 10): array
{
$stmt = $pdo->prepare("
SELECT mt.*, s.display_name as source_name
FROM music_tracks mt
JOIN sources s ON mt.source_id = s.id
ORDER BY mt.play_count DESC, mt.title ASC
LIMIT :limit
");
$stmt->execute(['limit' => $limit]);
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
}

View File

@@ -5,6 +5,9 @@ namespace App\Services;
use App\Models\Movie; use App\Models\Movie;
use App\Models\TvShow; use App\Models\TvShow;
use App\Models\TvEpisode; use App\Models\TvEpisode;
use App\Models\MusicArtist;
use App\Models\MusicAlbum;
use App\Models\MusicTrack;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
use Exception; use Exception;
@@ -94,8 +97,19 @@ class JellyfinSyncService extends BaseSyncService
$this->logProgress('Skipping TV shows sync (sync type: ' . $syncType . ')'); $this->logProgress('Skipping TV shows sync (sync type: ' . $syncType . ')');
} }
// Sync music (artists, albums, tracks) - TODO: Implement when music models are created // Sync music (artists, albums, tracks) if requested
// $this->syncMusic(); if (in_array($syncType, ['all', 'music'])) {
try {
$this->syncMusic();
} catch (Exception $e) {
$this->logProgress('Error syncing music: ' . $e->getMessage());
if ($syncType === 'music') {
throw $e;
}
}
} else {
$this->logProgress('Skipping music sync (sync type: ' . $syncType . ')');
}
$this->logProgress("Processed {$this->processedCount} items"); $this->logProgress("Processed {$this->processedCount} items");
} }
@@ -519,6 +533,299 @@ class JellyfinSyncService extends BaseSyncService
$this->logProgress("--- Completed sync for episode: {$episodeName} ---"); $this->logProgress("--- Completed sync for episode: {$episodeName} ---");
} }
private function syncMusic(): void
{
try {
$this->logProgress('=== Starting Music Sync ===');
// Sync artists first
$this->logProgress('Fetching music artists from Jellyfin...');
$artists = $this->getJellyfinItems('MusicArtist');
$artistCount = count($artists);
$this->logProgress("Found {$artistCount} artists in Jellyfin");
$processedArtists = 0;
$successfulArtists = 0;
$failedArtists = 0;
foreach ($artists as $artistData) {
$processedArtists++;
$artistName = $artistData['Name'] ?? 'Unknown Artist';
$this->logProgress("Processing artist {$processedArtists}/{$artistCount}: {$artistName}");
try {
$this->syncMusicArtist($artistData);
$successfulArtists++;
$this->logProgress("✓ Successfully synced artist: {$artistName}");
} catch (Exception $e) {
$failedArtists++;
$this->logProgress("✗ Failed to sync artist {$artistName}: " . $e->getMessage());
}
}
$this->logProgress("Artists sync summary: {$successfulArtists} successful, {$failedArtists} failed");
// Sync albums
$this->logProgress('Fetching music albums from Jellyfin...');
$albums = $this->getJellyfinItems('MusicAlbum');
$albumCount = count($albums);
$this->logProgress("Found {$albumCount} albums in Jellyfin");
$processedAlbums = 0;
$successfulAlbums = 0;
$failedAlbums = 0;
foreach ($albums as $albumData) {
$processedAlbums++;
$albumName = $albumData['Name'] ?? 'Unknown Album';
$this->logProgress("Processing album {$processedAlbums}/{$albumCount}: {$albumName}");
try {
$this->syncMusicAlbum($albumData);
$successfulAlbums++;
$this->logProgress("✓ Successfully synced album: {$albumName}");
} catch (Exception $e) {
$failedAlbums++;
$this->logProgress("✗ Failed to sync album {$albumName}: " . $e->getMessage());
}
}
$this->logProgress("Albums sync summary: {$successfulAlbums} successful, {$failedAlbums} failed");
// Sync tracks
$this->logProgress('Fetching music tracks from Jellyfin...');
$tracks = $this->getJellyfinItems('Audio');
$trackCount = count($tracks);
$this->logProgress("Found {$trackCount} tracks in Jellyfin");
$processedTracks = 0;
$successfulTracks = 0;
$failedTracks = 0;
foreach ($tracks as $trackData) {
$processedTracks++;
$trackName = $trackData['Name'] ?? 'Unknown Track';
$this->logProgress("Processing track {$processedTracks}/{$trackCount}: {$trackName}");
try {
$this->syncMusicTrack($trackData);
$successfulTracks++;
$this->logProgress("✓ Successfully synced track: {$trackName}");
} catch (Exception $e) {
$failedTracks++;
$this->logProgress("✗ Failed to sync track {$trackName}: " . $e->getMessage());
}
}
$this->logProgress("Tracks sync summary: {$successfulTracks} successful, {$failedTracks} failed");
$this->logProgress("=== Music Sync Completed ===");
} catch (Exception $e) {
$this->logProgress('CRITICAL ERROR in music sync: ' . $e->getMessage());
$this->logProgress('Stack trace: ' . $e->getTraceAsString());
throw $e;
}
}
private function syncMusicArtist(array $artistData): void
{
$artistModel = new MusicArtist($this->pdo);
// Check if artist already exists
$existingArtist = $artistModel->findAll([
'name' => $artistData['Name'],
'source_id' => $this->source['id']
]);
$artistDataForDb = [
'name' => $artistData['Name'],
'biography' => $artistData['Overview'] ?? null,
'formed_date' => isset($artistData['PremiereDate']) ? date('Y-m-d', strtotime($artistData['PremiereDate'])) : null,
'genre' => isset($artistData['Genres'][0]) ? $artistData['Genres'][0] : null,
'country' => null, // Jellyfin doesn't provide country info
'image_url' => $this->getImageUrl($artistData['Id'], 'Primary'),
'banner_url' => $this->getImageUrl($artistData['Id'], 'Backdrop'),
'spotify_id' => $artistData['ProviderIds']['MusicBrainzArtist'] ?? null,
'musicbrainz_id' => $artistData['ProviderIds']['MusicBrainzArtist'] ?? null,
'source_id' => $this->source['id'],
'metadata' => json_encode([
'jellyfin_id' => $artistData['Id']
])
];
if (empty($existingArtist)) {
$artistModel->create($artistDataForDb);
$this->newCount++;
} else {
$artistModel->update($existingArtist[0]['id'], $artistDataForDb);
$this->updatedCount++;
}
$this->processedCount++;
}
private function syncMusicAlbum(array $albumData): void
{
$albumModel = new MusicAlbum($this->pdo);
// Get or create artist first
$artistId = null;
if (isset($albumData['AlbumArtists']) && !empty($albumData['AlbumArtists'])) {
$artistName = $albumData['AlbumArtists'][0]['Name'];
$artistId = $this->getOrCreateMusicArtist($artistName);
}
// Check if album already exists
$existingAlbum = $albumModel->findAll([
'title' => $albumData['Name'],
'artist_id' => $artistId,
'source_id' => $this->source['id']
]);
// Download cover image
$coverPath = $this->downloadPosterImage($albumData['Id'], $albumData['Name']);
if (!$coverPath) {
$coverPath = $this->getImageUrl($albumData['Id'], 'Primary');
}
$albumDataForDb = [
'title' => $albumData['Name'],
'artist_name' => isset($albumData['AlbumArtists'][0]['Name']) ? $albumData['AlbumArtists'][0]['Name'] : 'Unknown Artist',
'release_date' => isset($albumData['PremiereDate']) ? date('Y-m-d', strtotime($albumData['PremiereDate'])) : null,
'genre' => isset($albumData['Genres'][0]) ? $albumData['Genres'][0] : null,
'track_count' => 0, // Will be updated when tracks are synced
'total_duration_seconds' => 0, // Will be updated when tracks are synced
'cover_url' => $coverPath,
'spotify_id' => $albumData['ProviderIds']['MusicBrainzAlbum'] ?? null,
'musicbrainz_id' => $albumData['ProviderIds']['MusicBrainzAlbum'] ?? null,
'artist_id' => $artistId,
'source_id' => $this->source['id'],
'metadata' => json_encode([
'jellyfin_id' => $albumData['Id']
])
];
if (empty($existingAlbum)) {
$albumModel->create($albumDataForDb);
$this->newCount++;
} else {
$albumModel->update($existingAlbum[0]['id'], $albumDataForDb);
$this->updatedCount++;
}
$this->processedCount++;
}
private function syncMusicTrack(array $trackData): void
{
$trackModel = new MusicTrack($this->pdo);
// Get or create artist
$artistId = null;
if (isset($trackData['AlbumArtists']) && !empty($trackData['AlbumArtists'])) {
$artistName = $trackData['AlbumArtists'][0]['Name'];
$artistId = $this->getOrCreateMusicArtist($artistName);
}
// Get or create album
$albumId = null;
if (isset($trackData['Album']) && !empty($trackData['Album'])) {
$albumId = $this->getOrCreateMusicAlbum($trackData['Album'], $artistId);
}
// Check if track already exists
$existingTrack = $trackModel->findAll([
'title' => $trackData['Name'],
'artist_id' => $artistId,
'album_id' => $albumId,
'source_id' => $this->source['id']
]);
$durationSeconds = isset($trackData['RunTimeTicks']) ? intval($trackData['RunTimeTicks'] / 10000000) : null;
$trackDataForDb = [
'title' => $trackData['Name'],
'artist_name' => isset($trackData['AlbumArtists'][0]['Name']) ? $trackData['AlbumArtists'][0]['Name'] : 'Unknown Artist',
'album_name' => $trackData['Album'] ?? null,
'track_number' => $trackData['IndexNumber'] ?? null,
'duration_seconds' => $durationSeconds,
'genre' => isset($trackData['Genres'][0]) ? $trackData['Genres'][0] : null,
'release_date' => isset($trackData['PremiereDate']) ? date('Y-m-d', strtotime($trackData['PremiereDate'])) : null,
'play_count' => 0,
'artist_id' => $artistId,
'album_id' => $albumId,
'source_id' => $this->source['id'],
'metadata' => json_encode([
'jellyfin_id' => $trackData['Id']
])
];
if (empty($existingTrack)) {
$trackModel->create($trackDataForDb);
$this->newCount++;
} else {
$trackModel->update($existingTrack[0]['id'], $trackDataForDb);
$this->updatedCount++;
}
$this->processedCount++;
}
private function getOrCreateMusicArtist(string $artistName): ?int
{
$artistModel = new MusicArtist($this->pdo);
// Check if artist exists
$existingArtist = $artistModel->findAll([
'name' => $artistName,
'source_id' => $this->source['id']
]);
if (!empty($existingArtist)) {
return $existingArtist[0]['id'];
}
// Create new artist
$artistData = [
'name' => $artistName,
'source_id' => $this->source['id'],
'metadata' => json_encode([])
];
$artistId = $artistModel->create($artistData);
return $artistId;
}
private function getOrCreateMusicAlbum(string $albumName, ?int $artistId): ?int
{
$albumModel = new MusicAlbum($this->pdo);
// Check if album exists
$existingAlbum = $albumModel->findAll([
'title' => $albumName,
'artist_id' => $artistId,
'source_id' => $this->source['id']
]);
if (!empty($existingAlbum)) {
return $existingAlbum[0]['id'];
}
// Create new album
$albumData = [
'title' => $albumName,
'artist_name' => 'Unknown Artist', // Will be updated when artist is found
'track_count' => 0,
'total_duration_seconds' => 0,
'artist_id' => $artistId,
'source_id' => $this->source['id'],
'metadata' => json_encode([])
];
$albumId = $albumModel->create($albumData);
return $albumId;
}
private function getShowEpisodes(string $jellyfinShowId): array private function getShowEpisodes(string $jellyfinShowId): array
{ {
$this->logProgress("--- Fetching episodes for show ID: {$jellyfinShowId} ---"); $this->logProgress("--- Fetching episodes for show ID: {$jellyfinShowId} ---");

View File

@@ -67,6 +67,11 @@
data-source-id="{{ source.id }}"> data-source-id="{{ source.id }}">
TV Shows Only TV Shows Only
</button> </button>
<button onclick="startSync({{ source.id }}, 'music')"
class="btn btn-outline-primary btn-sm flex-fill"
data-source-id="{{ source.id }}">
Music Only
</button>
</div> </div>
<div class="d-flex gap-1 mb-2"> <div class="d-flex gap-1 mb-2">
<button onclick="startSync({{ source.id }}, 'full')" <button onclick="startSync({{ source.id }}, 'full')"

View File

@@ -1,70 +1,659 @@
{% extends "layouts/app.twig" %} {% extends "layouts/app.twig" %}
{% block content %} {% block nav_controls %}
<div class="px-4 py-3">
<!-- Header with search and view controls -->
<div class="d-flex flex-column flex-sm-row justify-content-between align-items-start align-items-sm-center mb-4 gap-3">
<div>
<h1 class="display-4 fw-bold text-dark">Music</h1>
<div class="text-muted small mt-1">
Music collection coming soon
</div>
</div>
<div class="d-flex flex-column flex-sm-row gap-3 w-100 w-sm-auto">
<!-- Search form --> <!-- Search form -->
<form method="GET" class="d-flex gap-2"> <form method="GET" class="flex gap-2">
<input type="hidden" name="view" value="{{ view_mode }}"> <input type="hidden" name="view" value="{{ view_mode }}">
<input type="hidden" name="per_page" value="{{ pagination.per_page }}"> <input type="hidden" name="per_page" value="{{ pagination.per_page }}">
<div class="position-relative"> {% for genre in filters.genres %}
<input <input type="hidden" name="genres[]" value="{{ genre }}">
type="text" {% endfor %}
name="search" {% for artist in filters.artists %}
value="{{ search }}" <input type="hidden" name="artists[]" value="{{ artist }}">
placeholder="Search music..." {% endfor %}
class="form-control ps-5"
disabled
>
<svg class="position-absolute top-50 start-0 translate-middle-y ms-3 text-muted" width="20" height="20" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
</svg>
</div>
<button type="submit" class="btn btn-primary" disabled>
Search
</button>
</form> </form>
<!-- View mode switcher -->
<div class="btn-group" role="group"> <!-- Enhanced View mode switcher -->
<div class="flex gap-1 bg-gray-100 rounded-lg p-1" role="group">
{% for mode in view_modes %} {% for mode in view_modes %}
<button <a
class="btn btn-outline-secondary" href="?view={{ mode }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for artist in filters.artists %}&artists[]={{ artist }}{% endfor %}"
disabled class="inline-flex items-center px-3 py-2 text-sm font-medium rounded-md transition-all duration-200 {{ view_mode == mode ? 'bg-white text-blue-600 shadow-sm' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-200' }}"
title="Coming Soon" title="{{ mode|title }} View"
> >
{% if mode == 'grid' %} {% if mode == 'grid' %}
<svg class="me-1" width="16" height="16" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"/>
</svg> </svg>
{% elseif mode == 'list' %} {% endif %}
<svg class="me-1" width="16" height="16" fill="none" viewBox="0 0 24 24" stroke="currentColor"> {% if mode == 'list' %}
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h16M4 18h16"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h16M4 18h16"/>
</svg> </svg>
{% endif %} {% endif %}
{{ mode|title }} {% if mode == 'covers' %}
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
</svg>
{% endif %}
<span class="hidden sm:inline ml-1">{{ mode|title }}</span>
</a>
{% endfor %}
</div>
<!-- Sort dropdown -->
<div class="relative gap-1 bg-gray-100 rounded-lg p-1" x-data="{ open: false }">
<button @click="open = !open" class="inline-flex items-center px-3 py-2 text-sm font-medium rounded-md transition-all duration-200 {{ view_mode == mode ? 'bg-white text-blue-600 shadow-sm' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-200' }}">
<svg class="mr-1 h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4h14M3 8h9m-9 4h6m4 0l4-4m0 0l4 4m-4-4v12"/>
</svg>
<span class="hidden sm:inline">Sort</span>
</button> </button>
<div x-show="open" @click.away="open = false" class="absolute right-0 z-50 mt-2 w-56 bg-white rounded-md shadow-lg ring-1 ring-black ring-opacity-5">
<div class="py-1">
{% for key, label in sort_options %}
<a class="flex items-center justify-between px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 {{ sort == key ? 'bg-gray-50' : '' }}"
href="?sort={{ key }}&view={{ view_mode }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for artist in filters.artists %}&artists[]={{ artist }}{% endfor %}">
{{ label }}
{% if sort == key %}
<svg class="h-4 w-4 text-blue-600" fill="currentColor" viewBox="0 0 16 16">
<path d="M12.5 15a.5.5 0 0 1-.5-.5v-13a.5.5 0 0 1 1 0v13a.5.5 0 0 1-.5.5zM10 8a.5.5 0 0 1-.5.5H3.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L3.707 7.5H9.5a.5.5 0 0 1 .5.5z"/>
</svg>
{% endif %}
</a>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
</div> </div>
{% endblock %}
<!-- Coming Soon Message --> {% block item_list %}
<div class="text-center py-5"> {% if view_mode == 'list' and albums %}
<svg class="mx-auto text-muted mb-3" width="48" height="48" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <div class="space-y-4">
<!-- Group albums by first letter -->
{% set grouped_albums = {} %}
{% for album in albums %}
{% set first_letter = album.title|first|upper %}
{% if grouped_albums[first_letter] is defined %}
{% set grouped_albums = grouped_albums|merge({(first_letter): grouped_albums[first_letter]|merge([album])}) %}
{% else %}
{% set grouped_albums = grouped_albums|merge({(first_letter): [album]}) %}
{% endif %}
{% endfor %}
{% for letter, letter_albums in grouped_albums|sort %}
<div class="space-y-2">
<h4 class="text-sm font-semibold text-gray-900 border-b border-gray-200 pb-1">{{ letter }}</h4>
<div class="space-y-1">
{% for album in letter_albums %}
<a href="{{ path_for('music.show', {'id': album.id}) }}" class="flex items-center p-2 rounded-md hover:bg-gray-100 transition-colors">
{% if album.cover_url %}
<img class="w-8 h-12 object-cover rounded mr-3 flex-shrink-0" src="/images/{{ album.cover_url }}" alt="{{ album.title }}">
{% else %}
<div class="w-8 h-12 bg-gray-200 rounded mr-3 flex-shrink-0 flex items-center justify-center">
<svg class="w-4 h-4 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/>
</svg> </svg>
<h3 class="h5 fw-medium text-dark">Music Coming Soon</h3> </div>
<p class="text-muted">Music collection and management features are currently in development.</p> {% endif %}
<div class="flex-1 min-w-0">
<div class="text-sm font-medium text-gray-900 truncate">{{ album.title }}</div>
<div class="text-xs text-gray-500">{{ album.artist_name }}</div>
</div>
{% if album.release_date %}
<div class="flex-shrink-0 ml-2 text-xs text-gray-500">
{{ album.release_date|date('Y') }}
</div>
{% endif %}
{% if album.is_favorite %}
<div class="flex-shrink-0 ml-2">
<svg class="w-4 h-4 text-red-600" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 1.314C12.438-3.248 23.534 4.735 8 15-7.534 4.736 3.562-3.248 8 1.314z"/>
</svg>
</div>
{% endif %}
</a>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
{% else %}
<div class="space-y-4">
<div class="text-sm text-gray-500 text-center py-8">
No items to display
</div>
</div>
{% endif %}
{% endblock %}
{% block sidebar %}
<div class="space-y-4">
<!-- Filters -->
<div class="bg-gray-50 rounded-lg p-4">
<h3 class="text-sm font-medium text-gray-900 mb-4">Filters</h3>
<!-- Filter form -->
<form method="GET" id="filterForm">
<input type="hidden" name="view" value="{{ view_mode }}">
<input type="hidden" name="per_page" value="{{ pagination.per_page }}">
<input type="hidden" name="search" value="{{ search }}">
<!-- Genre filter -->
{% if available_filters.genres %}
<div class="mb-4">
<label class="block text-xs font-medium text-gray-700 mb-1">Genres</label>
<select class="select2 w-full text-sm border border-gray-300 rounded focus:ring-blue-500 focus:border-blue-500" name="genres[]" multiple data-placeholder="Select genres...">
{% for genre in available_filters.genres %}
<option value="{{ genre }}" {{ genre in filters.genres ? 'selected' : '' }}>
{{ genre }}
</option>
{% endfor %}
</select>
</div>
{% endif %}
<!-- Artist filter -->
{% if available_filters.artists %}
<div class="mb-4">
<label class="block text-xs font-medium text-gray-700 mb-1">Artists</label>
<select class="select2 w-full text-sm border border-gray-300 rounded focus:ring-blue-500 focus:border-blue-500" name="artists[]" multiple data-placeholder="Select artists...">
{% for artist in available_filters.artists %}
<option value="{{ artist }}" {{ artist in filters.artists ? 'selected' : '' }}>
{{ artist }}
</option>
{% endfor %}
</select>
</div>
{% endif %}
<!-- Filter actions -->
<div class="space-y-2">
<button type="submit" class="w-full bg-blue-600 text-white px-3 py-2 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 text-sm">
Apply Filters
</button>
<a href="{{ path_for('music.index') }}" class="w-full bg-gray-100 text-gray-700 px-3 py-2 rounded-md hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2 block text-center text-sm">
Clear All
</a>
</div>
</form>
</div>
<!-- Active Filters Summary -->
{% if filters.genres or filters.artists or search %}
<div class="bg-blue-50 rounded-lg p-4">
<h3 class="text-sm font-medium text-gray-900 mb-3">Active Filters</h3>
<div class="space-y-2">
{% if search %}
<div class="flex items-center justify-between">
<span class="text-sm text-gray-600">Search: "{{ search }}"</span>
<a href="?{% for key, value in filters %}{% if key != 'search' %}{{ key }}={{ value }}&{% endif %}{% endfor %}" class="text-blue-600 hover:text-blue-800">
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</a>
</div>
{% endif %}
{% for genre in filters.genres %}
<div class="flex items-center justify-between">
<span class="text-sm text-gray-600">Genre: {{ genre }}</span>
<a href="?{% for key, value in filters %}{% if key != 'genres' or (key == 'genres' and value != genre) %}{{ key }}={{ value }}&{% endif %}{% endfor %}" class="text-blue-600 hover:text-blue-800">
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</a>
</div>
{% endfor %}
{% for artist in filters.artists %}
<div class="flex items-center justify-between">
<span class="text-sm text-gray-600">Artist: {{ artist }}</span>
<a href="?{% for key, value in filters %}{% if key != 'artists' or (key == 'artists' and value != artist) %}{{ key }}={{ value }}&{% endif %}{% endfor %}" class="text-blue-600 hover:text-blue-800">
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</a>
</div>
{% endfor %}
</div>
</div>
{% endif %}
<!-- Quick Stats -->
<div class="bg-gray-50 rounded-lg p-4">
<h3 class="text-sm font-medium text-gray-900 mb-3">Quick Stats</h3>
<div class="space-y-2">
<div class="flex justify-between text-sm">
<span class="text-gray-600">Total Albums</span>
<span class="font-medium text-gray-900">{{ pagination.total_items }}</span>
</div>
<div class="flex justify-between text-sm">
<span class="text-gray-600">This Page</span>
<span class="font-medium text-gray-900">{{ albums|length }}</span>
</div>
{% if pagination.total_pages > 1 %}
<div class="flex justify-between text-sm">
<span class="text-gray-600">Page</span>
<span class="font-medium text-gray-900">{{ pagination.current_page }} of {{ pagination.total_pages }}</span>
</div>
{% endif %}
</div>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
{% block content %}
<!-- Main content area -->
<div class="p-6">
<!-- Header -->
<div class="mb-6">
<h1 class="text-3xl font-bold text-gray-900">Music</h1>
{% if pagination.total_items > 0 %}
<div class="text-gray-500 text-sm mt-1">
{{ pagination.total_items }} albums
{% if search %}
matching "{{ search }}"
{% endif %}
{% if filters.genres or filters.artists %}
{% if filters.genres %}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800 ml-2">{{ filters.genres|join(', ') }}</span>
{% endif %}
{% if filters.artists %}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800 ml-2">{{ filters.artists|join(', ') }}</span>
{% endif %}
{% endif %}
</div>
{% endif %}
</div>
{% if albums is empty %}
<div class="text-center py-12">
<svg class="mx-auto text-gray-400 mb-4 h-12 w-12" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/>
</svg>
<h3 class="text-lg font-medium text-gray-900 mb-2">
{% if search or filters.genres or filters.artists %}
No albums found matching your criteria
{% else %}
No albums found
{% endif %}
</h3>
<p class="text-gray-500 mb-4">
{% if search or filters.genres or filters.artists %}
Try adjusting your search terms or filters.
{% else %}
Start syncing your music libraries to see your albums here.
{% endif %}
</p>
{% if search or filters.genres or filters.artists %}
<a href="{{ path_for('music.index') }}" class="inline-flex items-center px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
Clear filters
</a>
{% endif %}
</div>
{% else %}
<!-- Albums content based on view mode -->
{% if view_mode == 'list' %}
<!-- List view -->
<div class="bg-white rounded-lg shadow-md border border-gray-200">
<ul class="divide-y divide-gray-200">
{% for album in albums %}
<li class="px-4 py-3">
<div class="flex justify-between items-center">
<div class="flex items-center">
<div class="flex-shrink-0">
{% if album.cover_url %}
<img class="rounded" style="width: 64px; height: 96px; object-fit: cover;" src="/images/{{ album.cover_url }}" alt="{{ album.title }}">
{% else %}
<div class="bg-gray-100 rounded flex items-center justify-center" style="width: 64px; height: 96px;">
<svg class="text-gray-600" width="32" height="32" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/>
</svg>
</div>
{% endif %}
</div>
<div class="ml-3 flex-1">
<h3 class="text-sm font-semibold mb-1">
<a href="{{ path_for('music.show', {'id': album.id}) }}" class="no-underline text-gray-900 hover:text-blue-600">
{{ album.title }}
</a>
</h3>
<div class="flex items-center gap-3 text-sm text-gray-600">
<span>{{ album.artist_name }}</span>
{% if album.release_date %}
<span>{{ album.release_date|date('Y') }}</span>
{% endif %}
{% if album.track_count %}
<span>{{ album.track_count }} tracks</span>
{% endif %}
<span>{{ album.source_name }}</span>
</div>
</div>
</div>
<div class="flex gap-2">
{% if album.is_favorite %}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
Favorite
</span>
{% endif %}
</div>
</div>
</li>
{% endfor %}
</ul>
</div>
{% elseif view_mode == 'covers' %}
<!-- Enhanced Cover grid view -->
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-8 gap-4">
{% for album in albums %}
<div class="group relative bg-white rounded-xl shadow-lg border border-gray-200 overflow-hidden hover:shadow-2xl transition-all duration-300 transform hover:-translate-y-1">
{% if album.cover_url %}
<div class="relative aspect-square overflow-hidden">
<img src="/images/{{ album.cover_url }}" alt="{{ album.title }}" class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300">
<!-- Overlay with album info -->
<div class="absolute inset-0 bg-gradient-to-t from-black/80 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300">
<div class="absolute bottom-0 left-0 right-0 p-3">
{% if album.track_count %}
<div class="flex items-center mb-2">
<svg class="w-4 h-4 text-white mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/>
</svg>
<span class="text-white text-sm font-medium">{{ album.track_count }} tracks</span>
</div>
{% endif %}
{% if album.is_favorite %}
<div class="flex items-center mb-1">
<svg class="w-3 h-3 text-red-400 mr-1" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M3.172 5.172a4 4 0 015.656 0L10 6.343l1.172-1.171a4 4 0 115.656 5.656L10 17.657l-6.828-6.829a4 4 0 010-5.656z" clip-rule="evenodd"/>
</svg>
<span class="text-red-400 text-xs">Favorite</span>
</div>
{% endif %}
</div>
</div>
</div>
{% else %}
<div class="flex items-center justify-center bg-gradient-to-br from-gray-100 to-gray-200 aspect-square min-h-[200px]">
<svg class="text-gray-400 w-12 h-12" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/>
</svg>
</div>
{% endif %}
<div class="p-4">
<h6 class="text-sm font-bold truncate mb-1" title="{{ album.title }}">
<a href="{{ path_for('music.show', {'id': album.id}) }}" class="no-underline text-gray-900 hover:text-blue-600 transition-colors">
{{ album.title }}
</a>
</h6>
<p class="text-xs text-gray-600 font-medium truncate">{{ album.artist_name }}</p>
{% if album.release_date %}
<p class="text-xs text-gray-600">{{ album.release_date|date('Y') }}</p>
{% endif %}
{% if album.genre %}
<div class="mt-2">
{% for genre in album.genre|split(',')|slice(0, 2) %}
<span class="inline-block bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded-full font-medium mr-1 mb-1">{{ genre|trim }}</span>
{% endfor %}
</div>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{% else %}
<!-- Default grid view -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-4">
{% for album in albums %}
<div class="bg-white rounded-lg shadow-md border border-gray-200 h-full">
<div class="p-4">
<div class="flex items-center">
<div class="flex-shrink-0">
{% if album.cover_url %}
<img class="rounded" style="width: 64px; height: 96px; object-fit: cover;" src="/images/{{ album.cover_url }}" alt="{{ album.title }}">
{% else %}
<div class="bg-gray-100 rounded flex items-center justify-center" style="width: 64px; height: 96px;">
<svg class="text-gray-600" width="32" height="32" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/>
</svg>
</div>
{% endif %}
</div>
<div class="ml-3 flex-1">
<h5 class="text-lg font-semibold mb-1">
<a href="{{ path_for('music.show', {'id': album.id}) }}" class="no-underline text-gray-900 hover:text-blue-600">
{{ album.title }}
</a>
</h5>
<div class="flex items-center gap-2 text-sm text-gray-600 mb-2">
<span>{{ album.artist_name }}</span>
{% if album.release_date %}
<span>{{ album.release_date|date('Y') }}</span>
{% endif %}
</div>
{% if album.source_name %}
<p class="text-sm text-gray-600 mb-2">
{{ album.source_name }}
</p>
{% endif %}
</div>
</div>
{% if album.track_count %}
<div class="mt-3">
<p class="text-sm text-gray-600">{{ album.track_count }} tracks</p>
</div>
{% endif %}
<div class="mt-3 flex justify-between items-center text-sm text-gray-600">
{% if album.total_duration_seconds %}
<span>{{ (album.total_duration_seconds / 60)|round(0) }} min</span>
{% endif %}
<div class="flex gap-1">
{% if album.is_favorite %}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
Favorite
</span>
{% endif %}
</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% endif %}
<!-- Top Pagination & Controls -->
{% if pagination.total_pages > 1 %}
<div class="flex items-center justify-between mb-6 p-4 bg-gray-50 rounded-lg">
<div class="flex items-center gap-4">
<div class="text-sm text-gray-700">
Showing {{ (pagination.current_page - 1) * pagination.per_page + 1 }} to {{ min(pagination.current_page * pagination.per_page, pagination.total_items) }} of {{ pagination.total_items }} albums
</div>
<div class="flex items-center gap-2">
<label for="per_page_top" class="text-sm font-medium text-gray-700">Show:</label>
<select id="per_page_top" class="text-sm border border-gray-300 rounded px-2 py-1 focus:ring-blue-500 focus:border-blue-500">
<option value="12" {{ pagination.per_page == 12 ? 'selected' : '' }}>12</option>
<option value="24" {{ pagination.per_page == 24 ? 'selected' : '' }}>24</option>
<option value="48" {{ pagination.per_page == 48 ? 'selected' : '' }}>48</option>
<option value="100" {{ pagination.per_page == 100 ? 'selected' : '' }}>100</option>
</select>
<span class="text-sm text-gray-600">per page</span>
</div>
</div>
<div class="flex items-center space-x-2">
<!-- Previous Button -->
{% if pagination.has_prev %}
<a href="?page={{ pagination.prev_page }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}&view={{ view_mode }}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for artist in filters.artists %}&artists[]={{ artist }}{% endfor %}"
class="px-3 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:text-gray-700 transition-colors flex items-center">
<svg class="w-4 h-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
</svg>
Previous
</a>
{% else %}
<span class="px-3 py-2 text-sm font-medium text-gray-300 bg-gray-100 border border-gray-200 rounded-lg cursor-not-allowed flex items-center">
<svg class="w-4 h-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
</svg>
Previous
</span>
{% endif %}
<!-- Page Numbers -->
{% set start_page = max(1, pagination.current_page - 2) %}
{% set end_page = min(pagination.total_pages, pagination.current_page + 2) %}
{% if start_page > 1 %}
<a href="?page=1{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}&view={{ view_mode }}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for artist in filters.artists %}&artists[]={{ artist }}{% endfor %}"
class="px-3 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:text-gray-700 transition-colors">1</a>
{% if start_page > 2 %}
<span class="px-2 py-2 text-sm font-medium text-gray-500">...</span>
{% endif %}
{% endif %}
{% for page_num in start_page..end_page %}
{% if page_num == pagination.current_page %}
<span class="px-3 py-2 text-sm font-medium text-white bg-blue-600 border border-blue-600 rounded-lg">{{ page_num }}</span>
{% else %}
<a href="?page={{ page_num }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}&view={{ view_mode }}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for artist in filters.artists %}&artists[]={{ artist }}{% endfor %}"
class="px-3 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:text-gray-700 transition-colors">{{ page_num }}</a>
{% endif %}
{% endfor %}
{% if end_page < pagination.total_pages %}
{% if end_page < pagination.total_pages - 1 %}
<span class="px-2 py-2 text-sm font-medium text-gray-500">...</span>
{% endif %}
<a href="?page={{ pagination.total_pages }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}&view={{ view_mode }}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for artist in filters.artists %}&artists[]={{ artist }}{% endfor %}"
class="px-3 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:text-gray-700 transition-colors">{{ pagination.total_pages }}</a>
{% endif %}
<!-- Next Button -->
{% if pagination.has_next %}
<a href="?page={{ pagination.next_page }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}&view={{ view_mode }}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for artist in filters.artists %}&artists[]={{ artist }}{% endfor %}"
class="px-3 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:text-gray-700 transition-colors flex items-center">
Next
<svg class="w-4 h-4 ml-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
</svg>
</a>
{% else %}
<span class="px-3 py-2 text-sm font-medium text-gray-300 bg-gray-100 border border-gray-200 rounded-lg cursor-not-allowed flex items-center">
Next
<svg class="w-4 h-4 ml-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
</svg>
</span>
{% endif %}
</div>
</div>
{% endif %}
{% endif %}
</div>
</div>
</div>
</div>
<style>
/* Sort dropdown styles */
.dropdown-menu {
min-width: 250px;
max-height: 400px;
overflow-y: auto;
}
.dropdown-item {
padding: 0.5rem 1.25rem;
white-space: normal;
line-height: 1.4;
}
.dropdown-item svg {
margin-top: 0.15rem;
}
/* Make sure the dropdown works on mobile */
@media (max-width: 575.98px) {
.dropdown-menu {
position: fixed !important;
top: auto !important;
left: 1rem !important;
right: 1rem !important;
width: auto !important;
margin-top: 0.5rem;
max-height: 70vh;
transform: none !important;
}
.dropdown-menu-end {
right: 1rem !important;
left: 1rem !important;
}
}
/* View mode buttons */
.btn-group .btn {
display: flex;
align-items: center;
justify-content: center;
padding: 0.375rem 0.75rem;
}
/* Custom styles for Select2 integration */
.select2-container {
z-index: 1050; /* Ensure Select2 dropdown appears above other elements */
}
.select2-selection {
min-height: 38px;
}
.select2-selection__choice {
background-color: #0d6efd !important;
border: none !important;
color: white !important;
}
.select2-selection__choice__remove {
color: white !important;
margin-right: 5px;
}
.select2-selection__choice__remove:hover {
color: #f8f9fa !important;
}
</style>
<script>
$(document).ready(function() {
// Initialize Select2 for all select2 elements
$('.select2').select2({
width: '100%',
allowClear: true,
placeholder: function() {
return $(this).data('placeholder');
}
});
// Auto-submit filter form when Select2 selection changes
$('.select2').on('change', function() {
document.getElementById('filterForm').submit();
});
});
document.getElementById('per_page')?.addEventListener('change', function() {
const url = new URL(window.location);
url.searchParams.set('per_page', this.value);
url.searchParams.set('page', '1'); // Reset to first page
window.location = url.toString();
});
document.getElementById('per_page_top')?.addEventListener('change', function() {
const url = new URL(window.location);
url.searchParams.set('per_page', this.value);
url.searchParams.set('page', '1'); // Reset to first page
window.location = url.toString();
});
</script>
{% endblock %}

View File

@@ -1,10 +1,10 @@
{% extends "layouts/app.twig" %} {% extends "layouts/app.twig" %}
{% block content %} {% block content %}
<div class="px-4 py-6 sm:px-0"> <div class="p-6">
<!-- Back button --> <!-- Back button -->
<div class="mb-6"> <div class="mb-6">
<a href="{{ path_for('music.index') }}" class="inline-flex items-center text-sm text-indigo-600 hover:text-indigo-800"> <a href="{{ path_for('music.index') }}" class="inline-flex items-center text-sm text-blue-600 hover:text-blue-800">
<svg class="w-4 h-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <svg class="w-4 h-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
</svg> </svg>
@@ -12,21 +12,179 @@
</a> </a>
</div> </div>
<!-- Coming Soon Message --> <!-- Album Header -->
<div class="text-center py-12"> <div class="bg-white rounded-lg shadow-md border border-gray-200 overflow-hidden mb-6">
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <div class="md:flex">
<!-- Album Cover -->
<div class="md:w-1/3 lg:w-1/4 p-6 flex justify-center">
{% if album.cover_url %}
<img src="/images/{{ album.cover_url }}" alt="{{ album.title }}" class="w-full max-w-sm rounded-lg shadow-lg">
{% else %}
<div class="w-full max-w-sm aspect-square bg-gradient-to-br from-gray-100 to-gray-200 rounded-lg flex items-center justify-center">
<svg class="text-gray-400 w-24 h-24" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/>
</svg> </svg>
<h3 class="mt-2 text-sm font-medium text-gray-900">Music Details Coming Soon</h3> </div>
<p class="mt-1 text-sm text-gray-500">{{ message }}</p> {% endif %}
<div class="mt-6"> </div>
<div class="inline-flex items-center px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 bg-white">
<!-- Album Info -->
<div class="md:w-2/3 lg:w-3/4 p-6">
<div class="flex items-start justify-between mb-4">
<div class="flex-1">
<h1 class="text-3xl font-bold text-gray-900 mb-2">{{ album.title }}</h1>
{% if artist %}
<h2 class="text-xl text-gray-600 mb-2">
<a href="#" class="hover:text-blue-600">{{ artist.name }}</a>
</h2>
{% else %}
<h2 class="text-xl text-gray-600 mb-2">{{ album.artist_name }}</h2>
{% endif %}
</div>
{% if album.is_favorite %}
<div class="ml-4">
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-red-100 text-red-800">
<svg class="w-4 h-4 mr-1" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M3.172 5.172a4 4 0 015.656 0L10 6.343l1.172-1.171a4 4 0 115.656 5.656L10 17.657l-6.828-6.829a4 4 0 010-5.656z" clip-rule="evenodd"/>
</svg>
Favorite
</span>
</div>
{% endif %}
</div>
<!-- Album Details -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-4">
{% if album.release_date %}
<div>
<dt class="text-sm font-medium text-gray-500">Release Date</dt>
<dd class="text-sm text-gray-900">{{ album.release_date|date('M j, Y') }}</dd>
</div>
{% endif %}
{% if album.track_count %}
<div>
<dt class="text-sm font-medium text-gray-500">Tracks</dt>
<dd class="text-sm text-gray-900">{{ album.track_count }}</dd>
</div>
{% endif %}
{% if album.total_duration_seconds %}
<div>
<dt class="text-sm font-medium text-gray-500">Duration</dt>
<dd class="text-sm text-gray-900">{{ (album.total_duration_seconds / 60)|round(0) }} min</dd>
</div>
{% endif %}
{% if album.genre %}
<div>
<dt class="text-sm font-medium text-gray-500">Genre</dt>
<dd class="text-sm text-gray-900">{{ album.genre }}</dd>
</div>
{% endif %}
</div>
<!-- Source Info -->
<div class="flex items-center text-sm text-gray-600 mb-4">
<span>Source: {{ album.source_name }}</span>
</div>
<!-- Action Buttons -->
<div class="flex gap-3">
<button class="inline-flex items-center px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
<svg class="w-4 h-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <svg class="w-4 h-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.828 14.828a4 4 0 01-5.656 0M9 10h1.586a1 1 0 01.707.293l.707.707A1 1 0 0012.414 11H15m-3 7.5A9.5 9.5 0 1121.5 12 9.5 9.5 0 0112 2.5z"/>
</svg> </svg>
Music ID: {{ music.id }} Play Album
</button>
<button class="inline-flex items-center px-4 py-2 bg-gray-100 text-gray-700 text-sm font-medium rounded-md hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2">
<svg class="w-4 h-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
</svg>
Add to Playlist
</button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- Tracks Section -->
{% if tracks %}
<div class="bg-white rounded-lg shadow-md border border-gray-200 overflow-hidden">
<div class="px-6 py-4 border-b border-gray-200">
<h3 class="text-lg font-medium text-gray-900">Tracks</h3>
</div>
<div class="divide-y divide-gray-200">
{% for track in tracks %}
<div class="px-6 py-4 hover:bg-gray-50 transition-colors">
<div class="flex items-center justify-between">
<div class="flex items-center flex-1 min-w-0">
<!-- Track Number -->
<div class="flex-shrink-0 w-8 text-sm text-gray-500 text-center">
{{ track.track_number }}
</div>
<!-- Play Button -->
<button class="flex-shrink-0 w-8 h-8 flex items-center justify-center text-gray-400 hover:text-blue-600 mr-3">
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z" clip-rule="evenodd"/>
</svg>
</button>
<!-- Track Info -->
<div class="flex-1 min-w-0">
<div class="text-sm font-medium text-gray-900 truncate">{{ track.title }}</div>
{% if track.artist_name and track.artist_name != album.artist_name %}
<div class="text-sm text-gray-500 truncate">{{ track.artist_name }}</div>
{% endif %}
</div>
</div>
<!-- Track Duration -->
<div class="flex-shrink-0 text-sm text-gray-500 ml-4">
{% if track.duration_seconds %}
{{ '%02d'|format((track.duration_seconds / 60)|round(0)) }}:{{ '%02d'|format(track.duration_seconds % 60) }}
{% endif %}
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endif %}
<!-- Additional Information -->
{% if metadata %}
<div class="mt-6 bg-white rounded-lg shadow-md border border-gray-200 overflow-hidden">
<div class="px-6 py-4 border-b border-gray-200">
<h3 class="text-lg font-medium text-gray-900">Additional Information</h3>
</div>
<div class="px-6 py-4">
<dl class="grid grid-cols-1 md:grid-cols-2 gap-4">
{% if metadata.label %}
<div>
<dt class="text-sm font-medium text-gray-500">Label</dt>
<dd class="text-sm text-gray-900">{{ metadata.label }}</dd>
</div>
{% endif %}
{% if metadata.popularity %}
<div>
<dt class="text-sm font-medium text-gray-500">Popularity</dt>
<dd class="text-sm text-gray-900">{{ metadata.popularity }}/100</dd>
</div>
{% endif %}
{% if metadata.spotify_id %}
<div>
<dt class="text-sm font-medium text-gray-500">Spotify ID</dt>
<dd class="text-sm text-gray-900 font-mono">{{ metadata.spotify_id }}</dd>
</div>
{% endif %}
{% if metadata.musicbrainz_id %}
<div>
<dt class="text-sm font-medium text-gray-500">MusicBrainz ID</dt>
<dd class="text-sm text-gray-900 font-mono">{{ metadata.musicbrainz_id }}</dd>
</div>
{% endif %}
</dl>
</div>
</div>
{% endif %}
</div>
{% endblock %} {% endblock %}

View File

@@ -77,7 +77,7 @@ $sourceData = [
// Validate sync type // Validate sync type
if ($source['name'] === 'jellyfin') { if ($source['name'] === 'jellyfin') {
$validSyncTypes = ['full', 'incremental', 'all', 'movies', 'tvshows', 'cleanup']; $validSyncTypes = ['full', 'incremental', 'all', 'movies', 'tvshows', 'music', 'cleanup'];
if (!in_array($syncType, $validSyncTypes)) { if (!in_array($syncType, $validSyncTypes)) {
echo "Invalid sync type for Jellyfin source. Valid types: " . implode(', ', $validSyncTypes) . "\n"; echo "Invalid sync type for Jellyfin source. Valid types: " . implode(', ', $validSyncTypes) . "\n";
exit(1); exit(1);