Skip to content

Commit a884795

Browse files
authored
Merge pull request #753 from zacaj/feature/dateAdded-genre-albumArtist-cols
add columns for Date Added, Genre, Album Artist, File Type
2 parents 7266030 + 88f426d commit a884795

File tree

9 files changed

+217
-96
lines changed

9 files changed

+217
-96
lines changed

backend/mediaprovider/jellyfin/jellyfinmediaprovider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ func toTrack(ch *jellyfin.Song) *mediaprovider.Track {
435435
}
436436

437437
lastPlayed, _ := time.Parse(time.RFC3339Nano, ch.UserData.LastPlayedDate)
438+
dateAdded, _ := time.Parse(time.RFC3339Nano, ch.DateCreated)
438439

439440
t := &mediaprovider.Track{
440441
ID: ch.Id,
@@ -454,6 +455,7 @@ func toTrack(ch *jellyfin.Song) *mediaprovider.Track {
454455
Favorite: ch.UserData.IsFavorite,
455456
PlayCount: ch.UserData.PlayCount,
456457
LastPlayed: lastPlayed,
458+
DateAdded: dateAdded,
457459
}
458460
if len(ch.MediaSources) > 0 {
459461
t.FilePath = ch.MediaSources[0].Path

backend/mediaprovider/model.go

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -123,35 +123,39 @@ type Genre struct {
123123
}
124124

125125
type Track struct {
126-
ID string
127-
CoverArtID string
128-
ParentID string
129-
Title string
130-
Duration time.Duration
131-
TrackNumber int
132-
DiscNumber int
133-
Genres []string
134-
ArtistIDs []string
135-
ArtistNames []string
136-
ComposerIDs []string
137-
ComposerNames []string
138-
Album string
139-
AlbumID string
140-
Year int
141-
Rating int
142-
Favorite bool
143-
Size int64
144-
PlayCount int
145-
LastPlayed time.Time
146-
FilePath string
147-
BitRate int
148-
ContentType string
149-
Comment string
150-
BPM int
151-
ReplayGain ReplayGainInfo
152-
SampleRate int
153-
BitDepth int
154-
Channels int
126+
ID string
127+
CoverArtID string
128+
ParentID string
129+
Title string
130+
Duration time.Duration
131+
TrackNumber int
132+
DiscNumber int
133+
Genres []string
134+
ArtistIDs []string
135+
ArtistNames []string
136+
AlbumArtistIDs []string
137+
AlbumArtistNames []string
138+
ComposerIDs []string
139+
ComposerNames []string
140+
Album string
141+
AlbumID string
142+
Year int
143+
Rating int
144+
Favorite bool
145+
Size int64
146+
PlayCount int
147+
LastPlayed time.Time
148+
FilePath string
149+
BitRate int
150+
ContentType string
151+
Comment string
152+
BPM int
153+
ReplayGain ReplayGainInfo
154+
SampleRate int
155+
BitDepth int
156+
Extension string
157+
Channels int
158+
DateAdded time.Time
155159
}
156160

157161
type ReplayGainInfo struct {

backend/mediaprovider/subsonic/subsonicmediaprovider.go

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,15 @@ func toTrack(ch *subsonic.Child) *mediaprovider.Track {
544544
artistIDs = append(artistIDs, ch.ArtistID)
545545
}
546546

547+
var albumArtistNames, albumArtistIDs []string
548+
if len(ch.AlbumArtists) > 0 {
549+
// OpenSubsonic extension
550+
for _, a := range ch.AlbumArtists {
551+
albumArtistIDs = append(albumArtistIDs, a.ID)
552+
albumArtistNames = append(albumArtistNames, a.Name)
553+
}
554+
}
555+
547556
var rGain mediaprovider.ReplayGainInfo
548557
if rg := ch.ReplayGain; rg != nil {
549558
rGain.AlbumGain = rg.AlbumGain
@@ -570,35 +579,39 @@ func toTrack(ch *subsonic.Child) *mediaprovider.Track {
570579
}
571580

572581
return &mediaprovider.Track{
573-
ID: ch.ID,
574-
CoverArtID: ch.CoverArt,
575-
ParentID: ch.Parent,
576-
Title: ch.Title,
577-
Duration: time.Duration(ch.Duration) * time.Second,
578-
TrackNumber: ch.Track,
579-
DiscNumber: ch.DiscNumber,
580-
Genres: genres,
581-
ArtistIDs: artistIDs,
582-
ArtistNames: artistNames,
583-
ComposerIDs: composerIDs,
584-
ComposerNames: composers,
585-
Album: ch.Album,
586-
AlbumID: ch.AlbumID,
587-
Year: ch.Year,
588-
Rating: ch.UserRating,
589-
Favorite: !ch.Starred.IsZero(),
590-
PlayCount: int(ch.PlayCount),
591-
LastPlayed: ch.Played,
592-
FilePath: ch.Path,
593-
Size: ch.Size,
594-
BitRate: ch.BitRate,
595-
ContentType: ch.ContentType,
596-
Comment: ch.Comment,
597-
BPM: ch.BPM,
598-
ReplayGain: rGain,
599-
SampleRate: ch.SamplingRate,
600-
BitDepth: ch.BitDepth,
601-
Channels: ch.ChannelCount,
582+
ID: ch.ID,
583+
CoverArtID: ch.CoverArt,
584+
ParentID: ch.Parent,
585+
Title: ch.Title,
586+
Duration: time.Duration(ch.Duration) * time.Second,
587+
TrackNumber: ch.Track,
588+
DiscNumber: ch.DiscNumber,
589+
Genres: genres,
590+
ArtistIDs: artistIDs,
591+
ArtistNames: artistNames,
592+
AlbumArtistIDs: albumArtistIDs,
593+
AlbumArtistNames: albumArtistNames,
594+
ComposerIDs: composerIDs,
595+
ComposerNames: composers,
596+
Album: ch.Album,
597+
AlbumID: ch.AlbumID,
598+
Year: ch.Year,
599+
Rating: ch.UserRating,
600+
Favorite: !ch.Starred.IsZero(),
601+
PlayCount: int(ch.PlayCount),
602+
LastPlayed: ch.Played,
603+
DateAdded: ch.Created,
604+
FilePath: ch.Path,
605+
Size: ch.Size,
606+
BitRate: ch.BitRate,
607+
ContentType: ch.ContentType,
608+
Extension: ch.Suffix,
609+
Comment: ch.Comment,
610+
BPM: ch.BPM,
611+
ReplayGain: rGain,
612+
SampleRate: ch.SamplingRate,
613+
BitDepth: ch.BitDepth,
614+
Channels: ch.ChannelCount,
602615
}
603616
}
604617

res/translations/en.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"Add to queue": "Add to queue",
77
"Album": "Album",
88
"album": "album",
9+
"Album artist": "Album artist",
10+
"Album artists": "Album artists",
911
"Album count": "Album count",
1012
"Album Count": "Album Count",
1113
"Album filters": "Album filters",
@@ -63,6 +65,7 @@
6365
"Content type": "Content type",
6466
"Could not reach server": "Could not reach server",
6567
"Create new playlist": "Create new playlist",
68+
"Date added": "Date added",
6669
"day": "day",
6770
"days": "days",
6871
"Delete Playlist": "Delete Playlist",
@@ -95,6 +98,7 @@
9598
"Field Recording": "Field Recording",
9699
"File path": "File path",
97100
"File size": "File size",
101+
"File type": "File type",
98102
"Filter albums": "Filter albums",
99103
"Filter genres": "Filter genres",
100104
"Forward": "Forward",
@@ -294,12 +298,10 @@
294298
"Oct": "Oct",
295299
"Nov": "Nov",
296300
"Dec": "Dec",
297-
298301
"playlist.addedtracks": {
299302
"one": "Added one track to playlist",
300303
"other": "Added {{.trackCount}} tracks to playlist"
301304
},
302-
303305
"x_minutes_ago": {
304306
"one": "a minute ago",
305307
"other": "{{.minutes}} minutes ago"
@@ -320,4 +322,4 @@
320322
"one": "a year ago",
321323
"other": "{{.years}} years ago"
322324
}
323-
}
325+
}

ui/controller/connectactions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func (m *Controller) connectTracklistActionsWithReplayGainMode(tracklist *widget
5252
tracklist.OnShowArtistPage = func(artistID string) {
5353
m.NavigateTo(ArtistRoute(artistID))
5454
}
55+
tracklist.OnShowGenrePage = func(genre string) {
56+
m.NavigateTo(GenreRoute(genre))
57+
}
5558
tracklist.OnColumnVisibilityMenuShown = func(pop *widget.PopUp) {
5659
m.ClosePopUpOnEscape(pop)
5760
}

ui/dialogs/trackinfodialog.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ func (t *TrackInfoDialog) CreateRenderer() fyne.WidgetRenderer {
5858
}
5959
c.Add(artists)
6060

61+
if len(t.track.AlbumArtistNames) > 0 {
62+
c.Add(newFormText(lang.L("Album artists"), true))
63+
albumArtists := widgets.NewMultiHyperlink()
64+
albumArtists.BuildSegments(t.track.AlbumArtistNames, t.track.AlbumArtistIDs)
65+
albumArtists.OnTapped = func(id string) {
66+
if t.OnNavigateToArtist != nil {
67+
t.OnNavigateToArtist(id)
68+
}
69+
}
70+
c.Add(albumArtists)
71+
}
72+
6173
if len(t.track.ComposerNames) > 0 {
6274
c.Add(newFormText(lang.L("Composers"), true))
6375
composers := widgets.NewMultiHyperlink()
@@ -104,6 +116,7 @@ func (t *TrackInfoDialog) CreateRenderer() fyne.WidgetRenderer {
104116
c.Add(newFormText(t.track.FilePath, false))
105117

106118
addFormRow(c, lang.L("Content type"), t.track.ContentType)
119+
addFormRow(c, lang.L("File type"), t.track.Extension)
107120
addFormRow(c, lang.L("Bit rate"), fmt.Sprintf("%d kbps", t.track.BitRate))
108121
if t.track.SampleRate > 0 {
109122
addFormRow(c, lang.L("Sample rate"), fmt.Sprintf("%d Hz", t.track.SampleRate))
@@ -115,6 +128,11 @@ func (t *TrackInfoDialog) CreateRenderer() fyne.WidgetRenderer {
115128
addFormRow(c, lang.L("Channels"), strconv.Itoa(t.track.Channels))
116129
}
117130
addFormRow(c, lang.L("File size"), util.BytesToSizeString(t.track.Size))
131+
132+
if !t.track.DateAdded.IsZero() {
133+
addFormRow(c, lang.L("Date added"), t.track.DateAdded.Format(time.RFC1123))
134+
}
135+
118136
addFormRow(c, lang.L("Play count"), strconv.Itoa(t.track.PlayCount))
119137

120138
if !t.track.LastPlayed.IsZero() {

ui/util/util.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ func FormatItemDate(date mediaprovider.ItemDate) string {
100100
return sb.String()
101101
}
102102

103+
func FormatDate(t time.Time) string {
104+
if t.IsZero() {
105+
return ""
106+
}
107+
108+
v := []int{
109+
t.Local().Year(),
110+
int(t.Local().Month()),
111+
t.Local().Day(),
112+
}
113+
id := mediaprovider.ItemDate{
114+
Year: &v[0],
115+
Month: &v[1],
116+
Day: &v[2],
117+
}
118+
119+
return FormatItemDate(id)
120+
}
121+
103122
func LastPlayedDisplayString(t time.Time) string {
104123
if t.IsZero() {
105124
return lang.L("never")

ui/widgets/tracklist.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type Tracklist struct {
7979

8080
OnShowArtistPage func(artistID string)
8181
OnShowAlbumPage func(albumID string)
82+
OnShowGenrePage func(genre string)
8283

8384
OnColumnVisibilityMenuShown func(*widget.PopUp)
8485
OnVisibleColumnsChanged func([]string)
@@ -432,8 +433,12 @@ func (t *Tracklist) doSortTracks() {
432433
t.stringSort(func(tr *util.TrackListModel) string { return tr.Track().Title })
433434
case ColumnArtist:
434435
t.stringSort(func(tr *util.TrackListModel) string { return strings.Join(tr.Track().ArtistNames, ", ") })
436+
case ColumnAlbumArtist:
437+
t.stringSort(func(tr *util.TrackListModel) string { return strings.Join(tr.Track().AlbumArtistNames, ", ") })
435438
case ColumnAlbum:
436439
t.stringSort(func(tr *util.TrackListModel) string { return tr.Track().Album })
440+
case ColumnGenre:
441+
t.stringSort(func(tr *util.TrackListModel) string { return strings.Join(tr.Track().Genres, ", ") })
437442
case ColumnPath:
438443
t.stringSort(func(tr *util.TrackListModel) string { return tr.Track().FilePath })
439444
case ColumnRating:
@@ -450,6 +455,8 @@ func (t *Tracklist) doSortTracks() {
450455
t.intSort(func(tr *util.TrackListModel) int64 { return tr.Track().LastPlayed.Unix() })
451456
case ColumnComment:
452457
t.stringSort(func(tr *util.TrackListModel) string { return tr.Track().Comment })
458+
case ColumnFileType:
459+
t.stringSort(func(tr *util.TrackListModel) string { return tr.Track().Extension })
453460
case ColumnBPM:
454461
t.intSort(func(tr *util.TrackListModel) int64 { return int64(tr.Track().BPM) })
455462
case ColumnBitrate:
@@ -461,6 +468,8 @@ func (t *Tracklist) doSortTracks() {
461468
}
462469
return 0
463470
})
471+
case ColumnDateAdded:
472+
t.intSort(func(tr *util.TrackListModel) int64 { return tr.Track().DateAdded.Unix() })
464473
}
465474
}
466475

@@ -597,6 +606,12 @@ func (t *Tracklist) onAlbumTapped(albumID string) {
597606
}
598607
}
599608

609+
func (t *Tracklist) onGenreTapped(genre string) {
610+
if t.OnShowGenrePage != nil {
611+
t.OnShowGenrePage(genre)
612+
}
613+
}
614+
600615
func (t *Tracklist) onDownload(tracks []*mediaprovider.Track, downloadName string) {
601616
if t.OnDownload != nil {
602617
t.OnDownload(tracks, downloadName)

0 commit comments

Comments
 (0)