Skip to content

Commit

Permalink
feat: Adds Audio Channel Metadata - navidrome#1036
Browse files Browse the repository at this point in the history
  • Loading branch information
mayanez committed Aug 22, 2021
1 parent 05e2709 commit 97f8768
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 3 deletions.
30 changes: 30 additions & 0 deletions db/migration/20210821212604_add_mediafile_channels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package migrations

import (
"database/sql"

"github.com/pressly/goose"
)

func init() {
goose.AddMigration(upAddMediafileChannels, downAddMediafileChannels)
}

func upAddMediafileChannels(tx *sql.Tx) error {
_, err := tx.Exec(`
alter table media_file
add channels integer;
create index if not exists media_file_channels
on media_file (channels);
`)
if err != nil {
return err
}
notice(tx, "A full rescan needs to be performed to import more tags")
return forceFullRescan(tx)
}

func downAddMediafileChannels(tx *sql.Tx) error {
return nil
}
1 change: 1 addition & 0 deletions model/mediafile.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type MediaFile struct {
Suffix string `structs:"suffix" json:"suffix"`
Duration float32 `structs:"duration" json:"duration"`
BitRate int `structs:"bit_rate" json:"bitRate"`
Channels int `structs:"channels" json:"channels"`
Genre string `structs:"genre" json:"genre"`
Genres Genres `structs:"-" json:"genres"`
FullText string `structs:"full_text" json:"fullText"`
Expand Down
1 change: 1 addition & 0 deletions scanner/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (s *mediaFileMapper) toMediaFile(md *metadata.Tags) model.MediaFile {
mf.DiscSubtitle = md.DiscSubtitle()
mf.Duration = md.Duration()
mf.BitRate = md.BitRate()
mf.Channels = md.Channels()
mf.Path = md.FilePath()
mf.Suffix = md.Suffix()
mf.Size = md.Size()
Expand Down
1 change: 1 addition & 0 deletions scanner/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (t *Tags) MbzAlbumComment() string {

func (t *Tags) Duration() float32 { return float32(t.getFloat("duration")) }
func (t *Tags) BitRate() int { return t.getInt("bitrate") }
func (t *Tags) Channels() int { return t.getInt("channels") }
func (t *Tags) ModificationTime() time.Time { return t.fileInfo.ModTime() }
func (t *Tags) Size() int64 { return t.fileInfo.Size() }
func (t *Tags) FilePath() string { return t.filePath }
Expand Down
1 change: 1 addition & 0 deletions scanner/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var _ = Describe("Tags", func() {
Expect(m.HasPicture()).To(BeTrue())
Expect(m.Duration()).To(BeNumerically("~", 1, 0.01))
Expect(m.BitRate()).To(Equal(192))
Expect(m.Channels()).To(Equal(2))
Expect(m.FilePath()).To(Equal("tests/fixtures/test.mp3"))
Expect(m.Suffix()).To(Equal("mp3"))
Expect(m.Size()).To(Equal(int64(51876)))
Expand Down
1 change: 1 addition & 0 deletions scanner/metadata/taglib/taglib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var _ = Describe("Parser", func() {
Expect(m).To(HaveKeyWithValue("has_picture", []string{"true"}))
Expect(m).To(HaveKeyWithValue("duration", []string{"1"}))
Expect(m).To(HaveKeyWithValue("bitrate", []string{"192"}))
Expect(m).To(HaveKeyWithValue("channels", []string{"2"}))
Expect(m).To(HaveKeyWithValue("comment", []string{"Comment1\nComment2"}))
Expect(m).To(HaveKeyWithValue("lyrics", []string{"Lyrics 1\rLyrics 2"}))
Expect(m).To(HaveKeyWithValue("bpm", []string{"123"}))
Expand Down
1 change: 1 addition & 0 deletions scanner/metadata/taglib/taglib_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int taglib_read(const char *filename, unsigned long id) {
const TagLib::AudioProperties *props(f.audioProperties());
go_map_put_int(id, (char *)"duration", props->length());
go_map_put_int(id, (char *)"bitrate", props->bitrate());
go_map_put_int(id, (char *)"channels", props->channels());

TagLib::PropertyMap tags = f.file()->properties();

Expand Down
3 changes: 2 additions & 1 deletion ui/src/album/AlbumSongs.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const AlbumSongs = (props) => {
/>
),
quality: isDesktop && <QualityInfo source="quality" sortable={false} />,
channels: isDesktop && <NumberField source="channels" sortable={true} />,
bpm: isDesktop && <NumberField source="bpm" sortable={false} />,
rating: isDesktop && config.enableStarRating && (
<RatingField
Expand All @@ -135,7 +136,7 @@ const AlbumSongs = (props) => {
resource: 'albumSong',
columns: toggleableFields,
omittedColumns: ['title'],
defaultOff: ['bpm', 'year'],
defaultOff: ['channels', 'bpm', 'year'],
})

return (
Expand Down
1 change: 1 addition & 0 deletions ui/src/common/SongDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const SongDetails = (props) => {
),
compilation: <BooleanField source="compilation" />,
bitRate: <BitrateField source="bitRate" />,
channels: <NumberField source="channels" />,
size: <SizeField source="size" />,
updatedAt: <DateField source="updatedAt" showTime />,
playCount: <TextField source="playCount" />,
Expand Down
1 change: 1 addition & 0 deletions ui/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"size": "File size",
"updatedAt": "Updated at",
"bitRate": "Bit rate",
"channels": "Channels",
"discSubtitle": "Disc Subtitle",
"starred": "Favourite",
"comment": "Comment",
Expand Down
3 changes: 2 additions & 1 deletion ui/src/playlist/PlaylistSongs.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,15 @@ const PlaylistSongs = ({ playlistId, readOnly, actions, ...props }) => {
/>
),
quality: isDesktop && <QualityInfo source="quality" sortable={false} />,
channels: isDesktop && <NumberField source="channels" sortable={true} />,
bpm: isDesktop && <NumberField source="bpm" />,
}
}, [isDesktop, classes.draggable])

const columns = useSelectedFields({
resource: 'playlistTrack',
columns: toggleableFields,
defaultOff: ['bpm', 'year'],
defaultOff: ['channels', 'bpm', 'year'],
})

return (
Expand Down
12 changes: 11 additions & 1 deletion ui/src/song/SongList.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ const SongList = (props) => {
/>
),
quality: isDesktop && <QualityInfo source="quality" sortable={false} />,
channels: isDesktop && (
<NumberField source="channels" sortByOrder={'ASC'} />
),
duration: <DurationField source="duration" />,
rating: config.enableStarRating && (
<RatingField
Expand All @@ -139,7 +142,14 @@ const SongList = (props) => {
const columns = useSelectedFields({
resource: 'song',
columns: toggleableFields,
defaultOff: ['bpm', 'playDate', 'albumArtist', 'genre', 'comment'],
defaultOff: [
'channels',
'bpm',
'playDate',
'albumArtist',
'genre',
'comment',
],
})

return (
Expand Down

0 comments on commit 97f8768

Please sign in to comment.