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

Expanded file datetime options #182

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -157,6 +157,7 @@ view the admin UI at http://localhost:4747
|`GONIC_SCAN_INTERVAL`|`-scan-interval`|**optional** interval (in minutes) to check for new music (automatic scanning disabled if omitted)|
|`GONIC_JUKEBOX_ENABLED`|`-jukebox-enabled`|**optional** whether the subsonic [jukebox api](https://airsonic.github.io/docs/jukebox/) should be enabled|
|`GONIC_GENRE_SPLIT`|`-genre-split`|**optional** a string or character to split genre tags on for multi-genre support (eg. `;`)|
|`CREATE_SORT`|`-create-sort`|**optional** a boolean for if the date sort should be for time created (default time modified)|

## screenshots

Expand Down
2 changes: 2 additions & 0 deletions cmd/gonic/gonic.go
Expand Up @@ -37,6 +37,7 @@ func main() {
confJukeboxEnabled := set.Bool("jukebox-enabled", false, "whether the subsonic jukebox api should be enabled (optional)")
confProxyPrefix := set.String("proxy-prefix", "", "url path prefix to use if behind proxy. eg '/gonic' (optional)")
confGenreSplit := set.String("genre-split", "\n", "character or string to split genre tag data on (optional)")
confDateCreateSort := set.Bool("create-sort", false, "sort by date created (optional)")
confHTTPLog := set.Bool("http-log", true, "http request logging (optional)")
confShowVersion := set.Bool("version", false, "show gonic version")

Expand Down Expand Up @@ -119,6 +120,7 @@ func main() {
PodcastPath: *confPodcastPath,
HTTPLog: *confHTTPLog,
JukeboxEnabled: *confJukeboxEnabled,
CreateSort: *confDateCreateSort,
})
if err != nil {
log.Panicf("error creating server: %v\n", err)
Expand Down
1 change: 1 addition & 0 deletions contrib/config
Expand Up @@ -5,3 +5,4 @@ db-path /var/lib/gonic/gonic.db
jukebox-enabled false
listen-addr 127.0.0.1:4747
scan-interval 0
create-sort false
12 changes: 7 additions & 5 deletions server/ctrladmin/ctrl.go
Expand Up @@ -52,13 +52,14 @@ func funcMap() template.FuncMap {

type Controller struct {
*ctrlbase.Controller
buffPool *bpool.BufferPool
templates map[string]*template.Template
sessDB *gormstore.Store
Podcasts *podcasts.Podcasts
buffPool *bpool.BufferPool
templates map[string]*template.Template
sessDB *gormstore.Store
Podcasts *podcasts.Podcasts
createSort bool
}

func New(b *ctrlbase.Controller, sessDB *gormstore.Store, podcasts *podcasts.Podcasts) (*Controller, error) {
func New(b *ctrlbase.Controller, sessDB *gormstore.Store, podcasts *podcasts.Podcasts, createSort bool) (*Controller, error) {
tmpl := template.
New("layout").
Funcs(sprig.FuncMap()).
Expand Down Expand Up @@ -96,6 +97,7 @@ func New(b *ctrlbase.Controller, sessDB *gormstore.Store, podcasts *podcasts.Pod
templates: pages,
sessDB: sessDB,
Podcasts: podcasts,
createSort: createSort,
}, nil
}

Expand Down
10 changes: 9 additions & 1 deletion server/ctrladmin/handlers.go
Expand Up @@ -45,9 +45,17 @@ func (c *Controller) ServeHome(r *http.Request) *Response {
// users box
c.DB.Find(&data.AllUsers)
// recent folders box
var dateOrder string

if c.createSort {
dateOrder = "created_at DESC"
} else {
dateOrder = "modified_at DESC"
}

c.DB.
Where("tag_artist_id IS NOT NULL").
Order("modified_at DESC").
Order(dateOrder).
Limit(8).
Find(&data.RecentFolders)
data.IsScanning = c.Scanner.IsScanning()
Expand Down
14 changes: 11 additions & 3 deletions server/scanner/scanner.go
Expand Up @@ -11,6 +11,7 @@ import (
"strconv"
"strings"
"sync/atomic"
"syscall"
"time"

"github.com/jinzhu/gorm"
Expand Down Expand Up @@ -243,8 +244,10 @@ func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *ctx, i int, album *
return nil
}

if err := populateAlbum(tx, album, albumArtist, trags, stat.ModTime()); err != nil {
return fmt.Errorf("propulate album: %w", err)
stat_t := stat.Sys().(*syscall.Stat_t)

if err := populateAlbum(tx, album, albumArtist, trags, stat.ModTime(), timespecToTime(stat_t.Ctim)); err != nil {
return fmt.Errorf("populate album: %w", err)
}

if err := populateAlbumGenres(tx, album, genreIDs); err != nil {
Expand All @@ -254,14 +257,15 @@ func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *ctx, i int, album *
return nil
}

func populateAlbum(tx *db.DB, album *db.Album, albumArtist *db.Artist, trags tags.Parser, modTime time.Time) error {
func populateAlbum(tx *db.DB, album *db.Album, albumArtist *db.Artist, trags tags.Parser, modTime time.Time, createTime time.Time) error {
albumName := trags.SomeAlbum()
album.TagTitle = albumName
album.TagTitleUDec = decoded(albumName)
album.TagBrainzID = trags.AlbumBrainzID()
album.TagYear = trags.Year()
album.TagArtistID = albumArtist.ID
album.ModifiedAt = modTime
album.CreatedAt = createTime

if err := tx.Save(&album).Error; err != nil {
return fmt.Errorf("saving album: %w", err)
Expand All @@ -270,6 +274,10 @@ func populateAlbum(tx *db.DB, album *db.Album, albumArtist *db.Artist, trags tag
return nil
}

func timespecToTime(ts syscall.Timespec) time.Time {
return time.Unix(int64(ts.Sec), int64(ts.Nsec))
}

func populateAlbumBasics(tx *db.DB, rootAbsPath string, parent, album *db.Album, dir, basename string, cover string) error {
album.RootDir = rootAbsPath
album.LeftPath = dir
Expand Down
3 changes: 2 additions & 1 deletion server/server.go
Expand Up @@ -35,6 +35,7 @@ type Options struct {
GenreSplit string
HTTPLog bool
JukeboxEnabled bool
CreateSort bool
}

type Server struct {
Expand Down Expand Up @@ -84,7 +85,7 @@ func New(opts Options) (*Server, error) {

podcast := podcasts.New(opts.DB, opts.PodcastPath, tagger)

ctrlAdmin, err := ctrladmin.New(base, sessDB, podcast)
ctrlAdmin, err := ctrladmin.New(base, sessDB, podcast, opts.CreateSort)
if err != nil {
return nil, fmt.Errorf("create admin controller: %w", err)
}
Expand Down