This commit is contained in:
cangui 2025-06-21 18:35:32 +02:00
parent 2f868380a1
commit 2687a16e25
2 changed files with 21 additions and 48 deletions

View File

@ -870,12 +870,13 @@ func probe(ctx context.Context, file string) (*ffprobeOut, error) {
} }
type mediaItemView struct { type mediaItemView struct {
Title string Title string
Duration int64 Duration int64 // en secondes
Width, Height int DurationFmt string // ex: "3:45"
ThumbURL string Width, Height int
FilePath string ThumbURL string
MediaPartID int64 FilePath string
MediaPartID int64
} }
// PathMedia renvoie la liste des sous-dossiers et médias du dossier `PathDownload` // PathMedia renvoie la liste des sous-dossiers et médias du dossier `PathDownload`
@ -942,6 +943,8 @@ func PathMedia(db *gorm.DB) http.HandlerFunc {
if err == nil { if err == nil {
if d, err := strconv.ParseFloat(info.Format.Duration, 64); err == nil { if d, err := strconv.ParseFloat(info.Format.Duration, 64); err == nil {
view.Duration = int64(d) view.Duration = int64(d)
view.DurationFmt = fmt.Sprintf("%d:%02d", view.Duration/60, view.Duration%60)
} }
for _, s := range info.Streams { for _, s := range info.Streams {
if s.CodecType == "video" { if s.CodecType == "video" {

View File

@ -1,49 +1,19 @@
<div class="breadcrumb mb-4"> <div class="media grid grid-cols-4 gap-4">
{{if .CurrentSub}} {{range .MediaItems}}
<div class="card p-2 rounded shadow">
<a <a
href="/api/paths/{{.PathID}}/media" href="#"
hx-get="/api/paths/{{.PathID}}/media" hx-get="/media/0?path={{urlquery .FilePath}}"
hx-target="#content"
hx-swap="innerHTML"
>🔙 Racine</a>
&nbsp;/&nbsp;{{.CurrentSub}}
{{end}}
</div>
<div class="dirs grid grid-cols-4 gap-4 mb-6">
{{range .Dirs}}
<div class="card p-3 rounded shadow">
<a
hx-get="/api/paths/{{$.PathID}}/media?sub={{urlquery .SubPath}}"
hx-target="#content" hx-swap="innerHTML" hx-target="#content" hx-swap="innerHTML"
> >
<i class="fas fa-folder fa-2x"></i> <img src="{{.ThumbURL}}" alt="{{.Title}}" class="w-full h-32 object-cover rounded" />
<div>{{.Name}}</div> <div class="mt-2">
<h3 class="text-sm font-semibold truncate">{{.Title}}</h3>
{{if .Duration}}
<small>{{.DurationFmt}}</small>
{{end}}
</div>
</a> </a>
</div> </div>
{{end}} {{end}}
</div> </div>
<div class="media grid grid-cols-4 gap-4">
{{if .MediaItems}}
{{range .MediaItems}}
<div class="card p-2 rounded shadow">
<a
href="#"
hx-get="/media/0?path={{urlquery .FilePath}}"
hx-target="#content" hx-swap="innerHTML"
>
<img src="{{.ThumbURL}}" alt="{{.Title}}" class="w-full h-32 object-cover rounded" />
<div class="mt-2">
<h3 class="text-sm font-semibold truncate">{{.Title}}</h3>
{{if .Duration}}
<small>{{printf "%d:%02d" (div .Duration 60) (mod .Duration 60)}}</small>
{{end}}
</div>
</a>
</div>
{{end}}
{{else}}
<p>Aucun média dans ce dossier.</p>
{{end}}
</div>