Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a new idea of a "transcoder" #205

Merged
merged 2 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/gonic/gonic.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"go.senan.xyz/gonic"
"go.senan.xyz/gonic/server"
"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/db"
)

const (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 9 additions & 10 deletions server/db/model.go → db/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// TODO: remove this dep

"go.senan.xyz/gonic/server/ctrlsubsonic/specid"
"go.senan.xyz/gonic/server/mime"
"go.senan.xyz/gonic/mime"
)

func splitInt(in, sep string) []int {
Expand Down Expand Up @@ -72,10 +72,11 @@ type Genre struct {
// AudioFile is used to avoid some duplication in handlers_raw.go
// between Track and Podcast
type AudioFile interface {
AudioFilename() string
Ext() string
MIME() string
AudioFilename() string
AudioBitrate() int
AudioLength() int
}

type Track struct {
Expand All @@ -100,6 +101,9 @@ type Track struct {
TagBrainzID string `sql:"default: null"`
}

func (t *Track) AudioLength() int { return t.Length }
func (t *Track) AudioBitrate() int { return t.Bitrate }

func (t *Track) SID() *specid.ID {
return &specid.ID{Type: specid.Track, Value: t.ID}
}
Expand All @@ -124,10 +128,6 @@ func (t *Track) AudioFilename() string {
return t.Filename
}

func (t *Track) AudioBitrate() int {
return t.Bitrate
}

func (t *Track) MIME() string {
v, _ := mime.FromExtension(t.Ext())
return v
Expand Down Expand Up @@ -364,6 +364,9 @@ type PodcastEpisode struct {
Error string
}

func (pe *PodcastEpisode) AudioLength() int { return pe.Length }
func (pe *PodcastEpisode) AudioBitrate() int { return pe.Bitrate }

func (pe *PodcastEpisode) SID() *specid.ID {
return &specid.ID{Type: specid.PodcastEpisode, Value: pe.ID}
}
Expand All @@ -385,10 +388,6 @@ func (pe *PodcastEpisode) MIME() string {
return v
}

func (pe *PodcastEpisode) AudioBitrate() int {
return pe.Bitrate
}

type Bookmark struct {
ID int `gorm:"primary_key"`
User *User
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/disintegration/imaging v1.6.2
github.com/dustin/go-humanize v1.0.0
github.com/faiface/beep v1.1.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0
github.com/gorilla/securecookie v1.1.1
Expand All @@ -26,7 +27,7 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/lib/pq v1.3.0 // indirect
github.com/matryer/is v1.4.0
github.com/mattn/go-sqlite3 v1.14.11 // indirect
github.com/mattn/go-sqlite3 v1.14.11
github.com/mewkiz/pkg v0.0.0-20211102230744-16a6ce8f1b77 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mmcdole/gofeed v1.1.3
Expand All @@ -40,7 +41,7 @@ require (
github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20220209155544-dad33157f4bf // indirect
golang.org/x/exp/shiny v0.0.0-20220209042442-160e291fcf24 // indirect
golang.org/x/exp/shiny v0.0.0-20220407100705-7b9b53b0aca4 // indirect
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect
golang.org/x/mobile v0.0.0-20220112015953-858099ff7816 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
Expand Down
6 changes: 5 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/d4l3k/messagediff v1.2.2-0.20190829033028-7e0a312ae40b/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f/go.mod h1:xN/JuLBIz4bjkxNmByTiV1IbhfnYb6oo99phBn4Eqhc=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
Expand Down Expand Up @@ -50,6 +49,8 @@ github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2V
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
Expand All @@ -76,6 +77,7 @@ github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6 h1:8UsGZ2rr2ksmEru6lTo
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/jezek/xgb v1.0.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/jfreymuth/oggvorbis v1.0.1/go.mod h1:NqS+K+UXKje0FUYUPosyQ+XTVvjmVjps1aEZH1sumIk=
github.com/jfreymuth/vorbis v1.0.0/go.mod h1:8zy3lUAm9K/rJJk223RKy6vjCZTWC61NA2QD06bfOE0=
github.com/jinzhu/gorm v1.9.2/go.mod h1:Vla75njaFJ8clLU1W44h34PjIkijhjHIYnZxMqCdxqo=
Expand Down Expand Up @@ -170,6 +172,8 @@ golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMD
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/exp/shiny v0.0.0-20220209042442-160e291fcf24 h1:jn6Q9FOmCn1Kk7ec3Qm9lfygAr7dv8J1YfEx6RQcRJQ=
golang.org/x/exp/shiny v0.0.0-20220209042442-160e291fcf24/go.mod h1:NtXcNtv5Wu0zUbBl574y/D5MMZvnQnV3sgjZxbs64Jo=
golang.org/x/exp/shiny v0.0.0-20220407100705-7b9b53b0aca4 h1:ywNGLBFk8tKaiu+GYZeoXWzrFoJ/a1LHYKy1lb3R9cM=
golang.org/x/exp/shiny v0.0.0-20220407100705-7b9b53b0aca4/go.mod h1:VjAR7z0ngyATZTELrBSkxOOHhhlnVUxDye4mcjx5h/8=
golang.org/x/image v0.0.0-20190220214146-31aff87c08e9/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
Expand Down
2 changes: 1 addition & 1 deletion server/jukebox/jukebox.go → jukebox/jukebox.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"

"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/db"
)

type Status struct {
Expand Down
3 changes: 0 additions & 3 deletions server/mime/mime.go → mime/mime.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package mime

// this package is at such a high level in the hierarchy because
// it's used by both `server/db` and `server/scanner`

func FromExtension(ext string) (string, bool) {
types := map[string]string{
"mp3": "audio/mpeg",
Expand Down
39 changes: 34 additions & 5 deletions server/mockfs/mockfs.go → mockfs/mockfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"time"

"github.com/mattn/go-sqlite3"
"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/server/scanner"
"go.senan.xyz/gonic/server/scanner/tags"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/scanner"
"go.senan.xyz/gonic/scanner/tags"
)

var ErrPathNotFound = errors.New("path not found")
Expand Down Expand Up @@ -148,6 +148,22 @@ func (m *MockFS) Symlink(src, dest string) {
}
}

func (m *MockFS) SetRealAudio(path string, length int, audioPath string) {
abspath := filepath.Join(m.dir, path)
if err := os.Remove(abspath); err != nil {
m.t.Fatalf("remove all: %v", err)
}
wd, _ := os.Getwd()
if err := os.Symlink(filepath.Join(wd, audioPath), abspath); err != nil {
m.t.Fatalf("symlink: %v", err)
}
m.SetTags(path, func(tags *Tags) error {
tags.RawLength = length
tags.RawBitrate = 0
return nil
})
}

func (m *MockFS) LogItems() {
m.t.Logf("\nitems")
var items int
Expand Down Expand Up @@ -337,6 +353,9 @@ type Tags struct {
RawAlbum string
RawAlbumArtist string
RawGenre string

RawBitrate int
RawLength int
}

func (m *Tags) Title() string { return m.RawTitle }
Expand All @@ -348,10 +367,11 @@ func (m *Tags) AlbumBrainzID() string { return "" }
func (m *Tags) Genre() string { return m.RawGenre }
func (m *Tags) TrackNumber() int { return 1 }
func (m *Tags) DiscNumber() int { return 1 }
func (m *Tags) Length() int { return 100 }
func (m *Tags) Bitrate() int { return 100 }
func (m *Tags) Year() int { return 2021 }

func (m *Tags) Length() int { return firstInt(100, m.RawLength) }
func (m *Tags) Bitrate() int { return firstInt(100, m.RawBitrate) }

func (m *Tags) SomeAlbum() string { return first("Unknown Album", m.Album()) }
func (m *Tags) SomeArtist() string { return first("Unknown Artist", m.Artist()) }
func (m *Tags) SomeAlbumArtist() string { return first("Unknown Artist", m.AlbumArtist(), m.Artist()) }
Expand All @@ -367,3 +387,12 @@ func first(or string, strs ...string) string {
}
return or
}

func firstInt(or int, ints ...int) int {
for _, int := range ints {
if int > 0 {
return int
}
}
return or
}
6 changes: 3 additions & 3 deletions server/podcasts/podcasts.go → podcasts/podcasts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"github.com/mmcdole/gofeed"

"go.senan.xyz/gonic/multierr"
"go.senan.xyz/gonic/server/db"
gmime "go.senan.xyz/gonic/server/mime"
"go.senan.xyz/gonic/server/scanner/tags"
"go.senan.xyz/gonic/db"
gmime "go.senan.xyz/gonic/mime"
"go.senan.xyz/gonic/scanner/tags"
)

const downloadAllWaitInterval = 3 * time.Second
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions server/scanner/scanner.go → scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"github.com/rainycape/unidecode"

"go.senan.xyz/gonic/multierr"
"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/server/mime"
"go.senan.xyz/gonic/server/scanner/tags"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/mime"
"go.senan.xyz/gonic/scanner/tags"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"go.senan.xyz/gonic/server/mockfs"
"go.senan.xyz/gonic/mockfs"
)

func BenchmarkScanIncremental(b *testing.B) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/matryer/is"
"go.senan.xyz/gonic/server/mockfs"
"go.senan.xyz/gonic/mockfs"
)

func FuzzScanner(f *testing.F) {
Expand Down
6 changes: 3 additions & 3 deletions server/scanner/scanner_test.go → scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/matryer/is"

"go.senan.xyz/gonic/multierr"
"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/server/mockfs"
"go.senan.xyz/gonic/server/scanner"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/mockfs"
"go.senan.xyz/gonic/scanner"
)

func TestMain(m *testing.M) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"strconv"
"time"

"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/server/scrobble"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/scrobble"
)

const (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"net/http/httputil"
"time"

"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/server/scrobble"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/scrobble"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion server/scrobble/scrobble.go → scrobble/scrobble.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scrobble
import (
"time"

"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/db"
)

type Scrobbler interface {
Expand Down
4 changes: 2 additions & 2 deletions server/ctrladmin/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"go.senan.xyz/gonic"
"go.senan.xyz/gonic/server/assets"
"go.senan.xyz/gonic/server/ctrlbase"
"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/server/podcasts"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/podcasts"
)

type CtxKey int
Expand Down
12 changes: 6 additions & 6 deletions server/ctrladmin/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

"github.com/mmcdole/gofeed"

"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/server/encode"
"go.senan.xyz/gonic/server/scanner"
"go.senan.xyz/gonic/server/scrobble/lastfm"
"go.senan.xyz/gonic/server/scrobble/listenbrainz"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/scanner"
"go.senan.xyz/gonic/scrobble/lastfm"
"go.senan.xyz/gonic/scrobble/listenbrainz"
"go.senan.xyz/gonic/transcode"
)

func doScan(scanner *scanner.Scanner, opts scanner.ScanOptions) {
Expand Down Expand Up @@ -67,7 +67,7 @@ func (c *Controller) ServeHome(r *http.Request) *Response {
c.DB.
Where("user_id=?", user.ID).
Find(&data.TranscodePreferences)
for profile := range encode.Profiles() {
for profile := range transcode.UserProfiles {
data.TranscodeProfiles = append(data.TranscodeProfiles, profile)
}
// podcasts box
Expand Down
2 changes: 1 addition & 1 deletion server/ctrladmin/handlers_playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/jinzhu/gorm"

"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/db"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion server/ctrladmin/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gorilla/sessions"

"go.senan.xyz/gonic"
"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/db"
)

func (c *Controller) WithSession(next http.Handler) http.Handler {
Expand Down
4 changes: 2 additions & 2 deletions server/ctrlbase/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"net/http"
"path"

"go.senan.xyz/gonic/server/db"
"go.senan.xyz/gonic/server/scanner"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/scanner"
)

type statusWriter struct {
Expand Down
8 changes: 5 additions & 3 deletions server/ctrlsubsonic/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
"go.senan.xyz/gonic/server/ctrlbase"
"go.senan.xyz/gonic/server/ctrlsubsonic/params"
"go.senan.xyz/gonic/server/ctrlsubsonic/spec"
"go.senan.xyz/gonic/server/jukebox"
"go.senan.xyz/gonic/server/podcasts"
"go.senan.xyz/gonic/server/scrobble"
"go.senan.xyz/gonic/jukebox"
"go.senan.xyz/gonic/podcasts"
"go.senan.xyz/gonic/scrobble"
"go.senan.xyz/gonic/transcode"
)

type CtxKey int
Expand All @@ -34,6 +35,7 @@ type Controller struct {
Jukebox *jukebox.Jukebox
Scrobblers []scrobble.Scrobbler
Podcasts *podcasts.Podcasts
Transcoder transcode.Transcoder
}

type metaResponse struct {
Expand Down
Loading