mirror of
https://github.com/navidrome/navidrome.git
synced 2025-07-20 10:21:46 +03:00
Compare commits
No commits in common. "cec5fb0d6c23a7f337ef5a4cf11f934178267e2c" and "c4c99b7f753ec78a250847d7775e67c6f9e63cd9" have entirely different histories.
cec5fb0d6c
...
c4c99b7f75
@ -7,6 +7,7 @@ linters:
|
|||||||
- asciicheck
|
- asciicheck
|
||||||
- bidichk
|
- bidichk
|
||||||
- bodyclose
|
- bodyclose
|
||||||
|
- depguard
|
||||||
- dogsled
|
- dogsled
|
||||||
- durationcheck
|
- durationcheck
|
||||||
- errcheck
|
- errcheck
|
||||||
|
@ -129,11 +129,11 @@ func (s *Stream) EstimatedContentLength() int {
|
|||||||
func selectTranscodingOptions(ctx context.Context, ds model.DataStore, mf *model.MediaFile, reqFormat string, reqBitRate int) (format string, bitRate int) {
|
func selectTranscodingOptions(ctx context.Context, ds model.DataStore, mf *model.MediaFile, reqFormat string, reqBitRate int) (format string, bitRate int) {
|
||||||
format = "raw"
|
format = "raw"
|
||||||
if reqFormat == "raw" {
|
if reqFormat == "raw" {
|
||||||
return format, 0
|
return
|
||||||
}
|
}
|
||||||
if reqFormat == mf.Suffix && reqBitRate == 0 {
|
if reqFormat == mf.Suffix && reqBitRate == 0 {
|
||||||
bitRate = mf.BitRate
|
bitRate = mf.BitRate
|
||||||
return format, bitRate
|
return
|
||||||
}
|
}
|
||||||
trc, hasDefault := request.TranscodingFrom(ctx)
|
trc, hasDefault := request.TranscodingFrom(ctx)
|
||||||
var cFormat string
|
var cFormat string
|
||||||
@ -159,7 +159,7 @@ func selectTranscodingOptions(ctx context.Context, ds model.DataStore, mf *model
|
|||||||
cBitRate = reqBitRate
|
cBitRate = reqBitRate
|
||||||
}
|
}
|
||||||
if cBitRate == 0 && cFormat == "" {
|
if cBitRate == 0 && cFormat == "" {
|
||||||
return format, bitRate
|
return
|
||||||
}
|
}
|
||||||
t, err := ds.Transcoding(ctx).FindByFormat(cFormat)
|
t, err := ds.Transcoding(ctx).FindByFormat(cFormat)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/deluan/rest"
|
"github.com/deluan/rest"
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
"github.com/navidrome/navidrome/utils/slice"
|
"github.com/navidrome/navidrome/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type playlistTrackRepository struct {
|
type playlistTrackRepository struct {
|
||||||
@ -196,7 +196,7 @@ func (r *playlistTrackRepository) Reorder(pos int, newPos int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
newOrder := slice.Move(ids, pos-1, newPos-1)
|
newOrder := utils.MoveString(ids, pos-1, newPos-1)
|
||||||
return r.playlistRepo.updatePlaylist(r.playlistId, newOrder)
|
return r.playlistRepo.updatePlaylist(r.playlistId, newOrder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,16 +41,3 @@ func MostFrequent[T comparable](list []T) T {
|
|||||||
|
|
||||||
return topItem
|
return topItem
|
||||||
}
|
}
|
||||||
|
|
||||||
func Insert[T any](slice []T, value T, index int) []T {
|
|
||||||
return append(slice[:index], append([]T{value}, slice[index:]...)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Remove[T any](slice []T, index int) []T {
|
|
||||||
return append(slice[:index], slice[index+1:]...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Move[T any](slice []T, srcIndex int, dstIndex int) []T {
|
|
||||||
value := slice[srcIndex]
|
|
||||||
return Insert(Remove(slice, srcIndex), value, dstIndex)
|
|
||||||
}
|
|
||||||
|
@ -14,59 +14,45 @@ func TestSlice(t *testing.T) {
|
|||||||
RunSpecs(t, "Slice Suite")
|
RunSpecs(t, "Slice Suite")
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Describe("Slice Utils", func() {
|
var _ = Describe("Map", func() {
|
||||||
Describe("Map", func() {
|
It("returns empty slice for an empty input", func() {
|
||||||
It("returns empty slice for an empty input", func() {
|
mapFunc := func(v int) string { return strconv.Itoa(v * 2) }
|
||||||
mapFunc := func(v int) string { return strconv.Itoa(v * 2) }
|
result := slice.Map([]int{}, mapFunc)
|
||||||
result := slice.Map([]int{}, mapFunc)
|
Expect(result).To(BeEmpty())
|
||||||
Expect(result).To(BeEmpty())
|
|
||||||
})
|
|
||||||
|
|
||||||
It("returns a new slice with elements mapped", func() {
|
|
||||||
mapFunc := func(v int) string { return strconv.Itoa(v * 2) }
|
|
||||||
result := slice.Map([]int{1, 2, 3, 4}, mapFunc)
|
|
||||||
Expect(result).To(ConsistOf("2", "4", "6", "8"))
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Group", func() {
|
It("returns a new slice with elements mapped", func() {
|
||||||
It("returns empty map for an empty input", func() {
|
mapFunc := func(v int) string { return strconv.Itoa(v * 2) }
|
||||||
keyFunc := func(v int) int { return v % 2 }
|
result := slice.Map([]int{1, 2, 3, 4}, mapFunc)
|
||||||
result := slice.Group([]int{}, keyFunc)
|
Expect(result).To(ConsistOf("2", "4", "6", "8"))
|
||||||
Expect(result).To(BeEmpty())
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
It("groups by the result of the key function", func() {
|
var _ = Describe("Group", func() {
|
||||||
keyFunc := func(v int) int { return v % 2 }
|
It("returns empty map for an empty input", func() {
|
||||||
result := slice.Group([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, keyFunc)
|
keyFunc := func(v int) int { return v % 2 }
|
||||||
Expect(result).To(HaveLen(2))
|
result := slice.Group([]int{}, keyFunc)
|
||||||
Expect(result[0]).To(ConsistOf(2, 4, 6, 8, 10))
|
Expect(result).To(BeEmpty())
|
||||||
Expect(result[1]).To(ConsistOf(1, 3, 5, 7, 9, 11))
|
})
|
||||||
})
|
|
||||||
})
|
It("groups by the result of the key function", func() {
|
||||||
|
keyFunc := func(v int) int { return v % 2 }
|
||||||
Describe("MostFrequent", func() {
|
result := slice.Group([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, keyFunc)
|
||||||
It("returns zero value if no arguments are passed", func() {
|
Expect(result).To(HaveLen(2))
|
||||||
Expect(slice.MostFrequent([]int{})).To(BeZero())
|
Expect(result[0]).To(ConsistOf(2, 4, 6, 8, 10))
|
||||||
})
|
Expect(result[1]).To(ConsistOf(1, 3, 5, 7, 9, 11))
|
||||||
|
})
|
||||||
It("returns the single item", func() {
|
})
|
||||||
Expect(slice.MostFrequent([]string{"123"})).To(Equal("123"))
|
|
||||||
})
|
var _ = Describe("MostFrequent", func() {
|
||||||
It("returns the item that appeared more times", func() {
|
It("returns zero value if no arguments are passed", func() {
|
||||||
Expect(slice.MostFrequent([]string{"1", "2", "1", "2", "3", "2"})).To(Equal("2"))
|
Expect(slice.MostFrequent([]int{})).To(BeZero())
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
It("returns the single item", func() {
|
||||||
Describe("Move", func() {
|
Expect(slice.MostFrequent([]string{"123"})).To(Equal("123"))
|
||||||
It("moves item to end of slice", func() {
|
})
|
||||||
Expect(slice.Move([]string{"1", "2", "3"}, 0, 2)).To(ConsistOf("2", "3", "1"))
|
It("returns the item that appeared more times", func() {
|
||||||
})
|
Expect(slice.MostFrequent([]string{"1", "2", "1", "2", "3", "2"})).To(Equal("2"))
|
||||||
It("moves item to beginning of slice", func() {
|
|
||||||
Expect(slice.Move([]string{"1", "2", "3"}, 2, 0)).To(ConsistOf("3", "1", "2"))
|
|
||||||
})
|
|
||||||
It("keeps item in same position if srcIndex == dstIndex", func() {
|
|
||||||
Expect(slice.Move([]string{"1", "2", "3"}, 1, 1)).To(ConsistOf("1", "2", "3"))
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -17,6 +17,19 @@ func NoArticle(name string) string {
|
|||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InsertString(slice []string, value string, index int) []string {
|
||||||
|
return append(slice[:index], append([]string{value}, slice[index:]...)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveString(slice []string, index int) []string {
|
||||||
|
return append(slice[:index], slice[index+1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func MoveString(slice []string, srcIndex int, dstIndex int) []string {
|
||||||
|
value := slice[srcIndex]
|
||||||
|
return InsertString(RemoveString(slice, srcIndex), value, dstIndex)
|
||||||
|
}
|
||||||
|
|
||||||
func BreakUpStringSlice(items []string, chunkSize int) [][]string {
|
func BreakUpStringSlice(items []string, chunkSize int) [][]string {
|
||||||
numTracks := len(items)
|
numTracks := len(items)
|
||||||
var chunks [][]string
|
var chunks [][]string
|
||||||
|
@ -35,6 +35,18 @@ var _ = Describe("Strings", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Describe("MoveString", func() {
|
||||||
|
It("moves item to end of slice", func() {
|
||||||
|
Expect(MoveString([]string{"1", "2", "3"}, 0, 2)).To(ConsistOf("2", "3", "1"))
|
||||||
|
})
|
||||||
|
It("moves item to beginning of slice", func() {
|
||||||
|
Expect(MoveString([]string{"1", "2", "3"}, 2, 0)).To(ConsistOf("3", "1", "2"))
|
||||||
|
})
|
||||||
|
It("keeps item in same position if srcIndex == dstIndex", func() {
|
||||||
|
Expect(MoveString([]string{"1", "2", "3"}, 1, 1)).To(ConsistOf("1", "2", "3"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
Describe("BreakUpStringSlice", func() {
|
Describe("BreakUpStringSlice", func() {
|
||||||
It("returns no chunks if slice is empty", func() {
|
It("returns no chunks if slice is empty", func() {
|
||||||
var slice []string
|
var slice []string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user