refactor: remove godirwalk dep

This commit is contained in:
sentriz
2021-11-12 20:14:57 +00:00
committed by Senan Kelly
parent fc50f01de3
commit e10c8bafdf
26 changed files with 342 additions and 452 deletions

1
go.mod
View File

@@ -22,7 +22,6 @@ require (
github.com/jinzhu/gorm v1.9.16
github.com/josephburnett/jd v0.0.0-20191228205456-aa1a7c66b42f
github.com/json-iterator/go v1.1.12 // indirect
github.com/karrick/godirwalk v1.16.1
github.com/matryer/is v1.4.0
github.com/mewkiz/pkg v0.0.0-20211102230744-16a6ce8f1b77 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect

2
go.sum
View File

@@ -213,8 +213,6 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
github.com/jszwec/csvutil v1.5.1/go.mod h1:Rpu7Uu9giO9subDyMCIQfHVDuLrcaC36UA4YcJjGBkg=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/karrick/godirwalk v1.16.1 h1:DynhcF+bztK8gooS0+NDJFrdNZjJ3gzVzC545UNA9iw=
github.com/karrick/godirwalk v1.16.1/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=

View File

@@ -5,27 +5,14 @@
"type": "gonic",
"albumList": {
"album": [
{
"id": "al-2",
"coverArt": "al-2",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"album": "",
"parent": "al-1",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-3",
"coverArt": "al-3",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"title": "album-0",
"album": "",
"parent": "al-1",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
@@ -36,9 +23,22 @@
"coverArt": "al-4",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"album": "",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-5",
"coverArt": "al-5",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"album": "",
"parent": "al-1",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,

View File

@@ -6,13 +6,13 @@
"albumList": {
"album": [
{
"id": "al-2",
"coverArt": "al-2",
"id": "al-3",
"coverArt": "al-3",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"album": "",
"parent": "al-1",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
@@ -45,13 +45,13 @@
"duration": 300
},
{
"id": "al-3",
"coverArt": "al-3",
"id": "al-4",
"coverArt": "al-4",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"album": "",
"parent": "al-1",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
@@ -84,13 +84,13 @@
"duration": 300
},
{
"id": "al-4",
"coverArt": "al-4",
"id": "al-5",
"coverArt": "al-5",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"album": "",
"parent": "al-1",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,

View File

@@ -5,27 +5,14 @@
"type": "gonic",
"albumList": {
"album": [
{
"id": "al-2",
"coverArt": "al-2",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"album": "",
"parent": "al-1",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-3",
"coverArt": "al-3",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"title": "album-0",
"album": "",
"parent": "al-1",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
@@ -36,9 +23,22 @@
"coverArt": "al-4",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"album": "",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-5",
"coverArt": "al-5",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"album": "",
"parent": "al-1",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,

View File

@@ -6,11 +6,11 @@
"albumList": {
"album": [
{
"id": "al-13",
"coverArt": "al-13",
"id": "al-12",
"coverArt": "al-12",
"artist": "artist-2",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"title": "album-1",
"album": "",
"parent": "al-10",
"isDir": true,
@@ -19,11 +19,11 @@
"duration": 300
},
{
"id": "al-8",
"coverArt": "al-8",
"id": "al-7",
"coverArt": "al-7",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"title": "album-0",
"album": "",
"parent": "al-6",
"isDir": true,
@@ -32,37 +32,24 @@
"duration": 300
},
{
"id": "al-2",
"coverArt": "al-2",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"album": "",
"parent": "al-1",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-3",
"coverArt": "al-3",
"id": "al-4",
"coverArt": "al-4",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"album": "",
"parent": "al-1",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-11",
"coverArt": "al-11",
"id": "al-13",
"coverArt": "al-13",
"artist": "artist-2",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"title": "album-2",
"album": "",
"parent": "al-10",
"isDir": true,
@@ -84,24 +71,11 @@
"duration": 300
},
{
"id": "al-7",
"coverArt": "al-7",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"album": "",
"parent": "al-6",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-12",
"coverArt": "al-12",
"id": "al-11",
"coverArt": "al-11",
"artist": "artist-2",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"title": "album-0",
"album": "",
"parent": "al-10",
"isDir": true,
@@ -110,13 +84,39 @@
"duration": 300
},
{
"id": "al-4",
"coverArt": "al-4",
"id": "al-3",
"coverArt": "al-3",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"album": "",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-8",
"coverArt": "al-8",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"album": "",
"parent": "al-6",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-5",
"coverArt": "al-5",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"album": "",
"parent": "al-1",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,

View File

@@ -6,8 +6,8 @@
"albumList2": {
"album": [
{
"id": "al-2",
"coverArt": "al-2",
"id": "al-3",
"coverArt": "al-3",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
@@ -19,8 +19,8 @@
"year": 2021
},
{
"id": "al-3",
"coverArt": "al-3",
"id": "al-4",
"coverArt": "al-4",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
@@ -32,8 +32,8 @@
"year": 2021
},
{
"id": "al-4",
"coverArt": "al-4",
"id": "al-5",
"coverArt": "al-5",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",

View File

@@ -6,8 +6,8 @@
"albumList2": {
"album": [
{
"id": "al-2",
"coverArt": "al-2",
"id": "al-3",
"coverArt": "al-3",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
@@ -45,8 +45,8 @@
"year": 2021
},
{
"id": "al-3",
"coverArt": "al-3",
"id": "al-4",
"coverArt": "al-4",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
@@ -84,8 +84,8 @@
"year": 2021
},
{
"id": "al-4",
"coverArt": "al-4",
"id": "al-5",
"coverArt": "al-5",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",

View File

@@ -6,8 +6,8 @@
"albumList2": {
"album": [
{
"id": "al-2",
"coverArt": "al-2",
"id": "al-3",
"coverArt": "al-3",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
@@ -19,8 +19,8 @@
"year": 2021
},
{
"id": "al-3",
"coverArt": "al-3",
"id": "al-4",
"coverArt": "al-4",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
@@ -32,8 +32,8 @@
"year": 2021
},
{
"id": "al-4",
"coverArt": "al-4",
"id": "al-5",
"coverArt": "al-5",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",

View File

@@ -5,45 +5,6 @@
"type": "gonic",
"albumList2": {
"album": [
{
"id": "al-4",
"coverArt": "al-4",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-2",
"coverArt": "al-2",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-12",
"coverArt": "al-12",
"artistId": "ar-3",
"artist": "artist-2",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-3",
"coverArt": "al-3",
@@ -52,46 +13,20 @@
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-13",
"coverArt": "al-13",
"artistId": "ar-3",
"artist": "artist-2",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-7",
"coverArt": "al-7",
"artistId": "ar-2",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-8",
"coverArt": "al-8",
"artistId": "ar-2",
"artist": "artist-1",
"id": "al-5",
"coverArt": "al-5",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
@@ -121,6 +56,71 @@
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-13",
"coverArt": "al-13",
"artistId": "ar-3",
"artist": "artist-2",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-4",
"coverArt": "al-4",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-8",
"coverArt": "al-8",
"artistId": "ar-2",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-7",
"coverArt": "al-7",
"artistId": "ar-2",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-12",
"coverArt": "al-12",
"artistId": "ar-3",
"artist": "artist-2",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
}
]
}

View File

@@ -11,14 +11,14 @@
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021,
"song": [
{
"id": "tr-4",
"album": "album-1",
"id": "tr-1",
"album": "album-0",
"albumId": "al-3",
"artist": "artist-0",
"artistId": "ar-1",
@@ -30,7 +30,7 @@
"isDir": false,
"isVideo": false,
"parent": "al-3",
"path": "artist-0/album-1/track-0.flac",
"path": "artist-0/album-0/track-0.flac",
"suffix": "flac",
"title": "title-0",
"track": 1,
@@ -39,8 +39,8 @@
"year": 2021
},
{
"id": "tr-5",
"album": "album-1",
"id": "tr-2",
"album": "album-0",
"albumId": "al-3",
"artist": "artist-0",
"artistId": "ar-1",
@@ -52,7 +52,7 @@
"isDir": false,
"isVideo": false,
"parent": "al-3",
"path": "artist-0/album-1/track-1.flac",
"path": "artist-0/album-0/track-1.flac",
"suffix": "flac",
"title": "title-1",
"track": 1,
@@ -61,8 +61,8 @@
"year": 2021
},
{
"id": "tr-6",
"album": "album-1",
"id": "tr-3",
"album": "album-0",
"albumId": "al-3",
"artist": "artist-0",
"artistId": "ar-1",
@@ -74,7 +74,7 @@
"isDir": false,
"isVideo": false,
"parent": "al-3",
"path": "artist-0/album-1/track-2.flac",
"path": "artist-0/album-0/track-2.flac",
"suffix": "flac",
"title": "title-2",
"track": 1,

View File

@@ -5,84 +5,12 @@
"type": "gonic",
"album": {
"id": "al-2",
"coverArt": "al-2",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021,
"song": [
{
"id": "tr-1",
"album": "album-0",
"albumId": "al-2",
"artist": "artist-0",
"artistId": "ar-1",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-2",
"path": "artist-0/album-0/track-0.flac",
"suffix": "flac",
"title": "title-0",
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
},
{
"id": "tr-2",
"album": "album-0",
"albumId": "al-2",
"artist": "artist-0",
"artistId": "ar-1",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-2",
"path": "artist-0/album-0/track-1.flac",
"suffix": "flac",
"title": "title-1",
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
},
{
"id": "tr-3",
"album": "album-0",
"albumId": "al-2",
"artist": "artist-0",
"artistId": "ar-1",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-2",
"path": "artist-0/album-0/track-2.flac",
"suffix": "flac",
"title": "title-2",
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
}
]
"name": "",
"songCount": 0,
"duration": 0
}
}
}

View File

@@ -9,8 +9,8 @@
"albumCount": 3,
"album": [
{
"id": "al-2",
"coverArt": "al-2",
"id": "al-3",
"coverArt": "al-3",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
@@ -22,8 +22,8 @@
"year": 2021
},
{
"id": "al-3",
"coverArt": "al-3",
"id": "al-4",
"coverArt": "al-4",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
@@ -35,8 +35,8 @@
"year": 2021
},
{
"id": "al-4",
"coverArt": "al-4",
"id": "al-5",
"coverArt": "al-5",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",

View File

@@ -10,8 +10,8 @@
{
"name": "a",
"artist": [
{ "id": "al-1", "name": "artist-0", "albumCount": 3 },
{ "id": "al-14", "name": "artist-0", "albumCount": 3 },
{ "id": "al-2", "name": "artist-0", "albumCount": 3 },
{ "id": "al-15", "name": "artist-0", "albumCount": 3 },
{ "id": "al-6", "name": "artist-1", "albumCount": 3 },
{ "id": "al-19", "name": "artist-1", "albumCount": 3 },
{ "id": "al-10", "name": "artist-2", "albumCount": 3 },

View File

@@ -10,7 +10,7 @@
{
"name": "a",
"artist": [
{ "id": "al-1", "name": "artist-0", "albumCount": 3 },
{ "id": "al-2", "name": "artist-0", "albumCount": 3 },
{ "id": "al-6", "name": "artist-1", "albumCount": 3 },
{ "id": "al-10", "name": "artist-2", "albumCount": 3 }
]

View File

@@ -10,7 +10,7 @@
{
"name": "a",
"artist": [
{ "id": "al-14", "name": "artist-0", "albumCount": 3 },
{ "id": "al-15", "name": "artist-0", "albumCount": 3 },
{ "id": "al-19", "name": "artist-1", "albumCount": 3 },
{ "id": "al-23", "name": "artist-2", "albumCount": 3 }
]

View File

@@ -5,12 +5,12 @@
"type": "gonic",
"directory": {
"id": "al-3",
"parent": "al-1",
"name": "album-1",
"parent": "al-2",
"name": "album-0",
"child": [
{
"id": "tr-4",
"album": "album-1",
"id": "tr-1",
"album": "album-0",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
@@ -20,7 +20,7 @@
"isDir": false,
"isVideo": false,
"parent": "al-3",
"path": "artist-0/album-1/track-0.flac",
"path": "artist-0/album-0/track-0.flac",
"suffix": "flac",
"title": "title-0",
"track": 1,
@@ -28,8 +28,8 @@
"type": "music"
},
{
"id": "tr-5",
"album": "album-1",
"id": "tr-2",
"album": "album-0",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
@@ -39,7 +39,7 @@
"isDir": false,
"isVideo": false,
"parent": "al-3",
"path": "artist-0/album-1/track-1.flac",
"path": "artist-0/album-0/track-1.flac",
"suffix": "flac",
"title": "title-1",
"track": 1,
@@ -47,8 +47,8 @@
"type": "music"
},
{
"id": "tr-6",
"album": "album-1",
"id": "tr-3",
"album": "album-0",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
@@ -58,7 +58,7 @@
"isDir": false,
"isVideo": false,
"parent": "al-3",
"path": "artist-0/album-1/track-2.flac",
"path": "artist-0/album-0/track-2.flac",
"suffix": "flac",
"title": "title-2",
"track": 1,

View File

@@ -6,64 +6,34 @@
"directory": {
"id": "al-2",
"parent": "al-1",
"name": "album-0",
"name": "artist-0",
"child": [
{
"id": "tr-1",
"album": "album-0",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"id": "al-3",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isDir": true,
"isVideo": false,
"parent": "al-2",
"path": "artist-0/album-0/track-0.flac",
"suffix": "flac",
"title": "title-0",
"track": 1,
"discNumber": 1,
"type": "music"
"title": "album-0"
},
{
"id": "tr-2",
"album": "album-0",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"id": "al-4",
"coverArt": "al-4",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isDir": true,
"isVideo": false,
"parent": "al-2",
"path": "artist-0/album-0/track-1.flac",
"suffix": "flac",
"title": "title-1",
"track": 1,
"discNumber": 1,
"type": "music"
"title": "album-1"
},
{
"id": "tr-3",
"album": "album-0",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"id": "al-5",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isDir": true,
"isVideo": false,
"parent": "al-2",
"path": "artist-0/album-0/track-2.flac",
"suffix": "flac",
"title": "title-2",
"track": 1,
"discNumber": 1,
"type": "music"
"title": "album-2"
}
]
}

View File

@@ -6,8 +6,8 @@
"searchResult3": {
"album": [
{
"id": "al-2",
"coverArt": "al-2",
"id": "al-3",
"coverArt": "al-3",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
@@ -19,8 +19,8 @@
"year": 2021
},
{
"id": "al-3",
"coverArt": "al-3",
"id": "al-4",
"coverArt": "al-4",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
@@ -32,8 +32,8 @@
"year": 2021
},
{
"id": "al-4",
"coverArt": "al-4",
"id": "al-5",
"coverArt": "al-5",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",

View File

@@ -8,16 +8,16 @@
{
"id": "tr-1",
"album": "album-0",
"albumId": "al-2",
"albumId": "al-3",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-2",
"parent": "al-3",
"path": "artist-0/album-0/track-0.flac",
"suffix": "flac",
"title": "title-0",
@@ -29,16 +29,16 @@
{
"id": "tr-2",
"album": "album-0",
"albumId": "al-2",
"albumId": "al-3",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-2",
"parent": "al-3",
"path": "artist-0/album-0/track-1.flac",
"suffix": "flac",
"title": "title-1",
@@ -50,16 +50,16 @@
{
"id": "tr-3",
"album": "album-0",
"albumId": "al-2",
"albumId": "al-3",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-2",
"parent": "al-3",
"path": "artist-0/album-0/track-2.flac",
"suffix": "flac",
"title": "title-2",
@@ -71,16 +71,16 @@
{
"id": "tr-4",
"album": "album-1",
"albumId": "al-3",
"albumId": "al-4",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-3",
"coverArt": "al-4",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-3",
"parent": "al-4",
"path": "artist-0/album-1/track-0.flac",
"suffix": "flac",
"title": "title-0",
@@ -92,16 +92,16 @@
{
"id": "tr-5",
"album": "album-1",
"albumId": "al-3",
"albumId": "al-4",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-3",
"coverArt": "al-4",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-3",
"parent": "al-4",
"path": "artist-0/album-1/track-1.flac",
"suffix": "flac",
"title": "title-1",
@@ -113,16 +113,16 @@
{
"id": "tr-6",
"album": "album-1",
"albumId": "al-3",
"albumId": "al-4",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-3",
"coverArt": "al-4",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-3",
"parent": "al-4",
"path": "artist-0/album-1/track-2.flac",
"suffix": "flac",
"title": "title-2",
@@ -134,16 +134,16 @@
{
"id": "tr-7",
"album": "album-2",
"albumId": "al-4",
"albumId": "al-5",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-4",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-4",
"parent": "al-5",
"path": "artist-0/album-2/track-0.flac",
"suffix": "flac",
"title": "title-0",
@@ -155,16 +155,16 @@
{
"id": "tr-8",
"album": "album-2",
"albumId": "al-4",
"albumId": "al-5",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-4",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-4",
"parent": "al-5",
"path": "artist-0/album-2/track-1.flac",
"suffix": "flac",
"title": "title-1",
@@ -176,16 +176,16 @@
{
"id": "tr-9",
"album": "album-2",
"albumId": "al-4",
"albumId": "al-5",
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-4",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-4",
"parent": "al-5",
"path": "artist-0/album-2/track-2.flac",
"suffix": "flac",
"title": "title-2",

View File

@@ -5,23 +5,14 @@
"type": "gonic",
"searchResult2": {
"album": [
{
"id": "al-2",
"coverArt": "al-2",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
"isVideo": false,
"parent": "al-1",
"title": "album-0"
},
{
"id": "al-3",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
"isVideo": false,
"parent": "al-1",
"title": "album-1"
"parent": "al-2",
"title": "album-0"
},
{
"id": "al-4",
@@ -29,7 +20,16 @@
"created": "2019-11-30T00:00:00Z",
"isDir": true,
"isVideo": false,
"parent": "al-1",
"parent": "al-2",
"title": "album-1"
},
{
"id": "al-5",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
"isVideo": false,
"parent": "al-2",
"title": "album-2"
},
{

View File

@@ -5,9 +5,9 @@
"type": "gonic",
"searchResult2": {
"artist": [
{ "id": "al-1", "parent": "al-5", "name": "artist-0" },
{ "id": "al-6", "parent": "al-5", "name": "artist-1" },
{ "id": "al-10", "parent": "al-5", "name": "artist-2" }
{ "id": "al-2", "parent": "al-1", "name": "artist-0" },
{ "id": "al-6", "parent": "al-1", "name": "artist-1" },
{ "id": "al-10", "parent": "al-1", "name": "artist-2" }
]
}
}

View File

@@ -11,12 +11,12 @@
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-2",
"parent": "al-3",
"path": "artist-0/album-0/track-0.flac",
"suffix": "flac",
"title": "title-0",
@@ -30,12 +30,12 @@
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-2",
"parent": "al-3",
"path": "artist-0/album-0/track-1.flac",
"suffix": "flac",
"title": "title-1",
@@ -49,12 +49,12 @@
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-2",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-2",
"parent": "al-3",
"path": "artist-0/album-0/track-2.flac",
"suffix": "flac",
"title": "title-2",
@@ -68,12 +68,12 @@
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-3",
"coverArt": "al-4",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-3",
"parent": "al-4",
"path": "artist-0/album-1/track-0.flac",
"suffix": "flac",
"title": "title-0",
@@ -87,12 +87,12 @@
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-3",
"coverArt": "al-4",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-3",
"parent": "al-4",
"path": "artist-0/album-1/track-1.flac",
"suffix": "flac",
"title": "title-1",
@@ -106,12 +106,12 @@
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-3",
"coverArt": "al-4",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-3",
"parent": "al-4",
"path": "artist-0/album-1/track-2.flac",
"suffix": "flac",
"title": "title-2",
@@ -125,12 +125,12 @@
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-4",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-4",
"parent": "al-5",
"path": "artist-0/album-2/track-0.flac",
"suffix": "flac",
"title": "title-0",
@@ -144,12 +144,12 @@
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-4",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-4",
"parent": "al-5",
"path": "artist-0/album-2/track-1.flac",
"suffix": "flac",
"title": "title-1",
@@ -163,12 +163,12 @@
"artist": "artist-0",
"bitRate": 100,
"contentType": "audio/x-flac",
"coverArt": "al-4",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"duration": 100,
"isDir": false,
"isVideo": false,
"parent": "al-4",
"parent": "al-5",
"path": "artist-0/album-2/track-2.flac",
"suffix": "flac",
"title": "title-2",

View File

@@ -59,7 +59,7 @@ func new(t *testing.T, dirs []string) *MockFS {
}
parser := &mreader{map[string]*Tags{}}
scanner := scanner.New(absDirs, true, dbc, ";", parser)
scanner := scanner.New(absDirs, dbc, ";", parser)
return &MockFS{
t: t,

View File

@@ -3,6 +3,7 @@ package scanner
import (
"errors"
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
@@ -13,7 +14,6 @@ import (
"time"
"github.com/jinzhu/gorm"
"github.com/karrick/godirwalk"
"github.com/rainycape/unidecode"
"go.senan.xyz/gonic/multierr"
@@ -30,18 +30,16 @@ var (
type Scanner struct {
db *db.DB
musicPaths []string
sorted bool
musicDirs []string
genreSplit string
tagger tags.Reader
scanning *int32
}
func New(musicPaths []string, sorted bool, db *db.DB, genreSplit string, tagger tags.Reader) *Scanner {
func New(musicDirs []string, db *db.DB, genreSplit string, tagger tags.Reader) *Scanner {
return &Scanner{
db: db,
musicPaths: musicPaths,
sorted: sorted,
musicDirs: musicDirs,
genreSplit: genreSplit,
tagger: tagger,
scanning: new(int32),
@@ -76,14 +74,37 @@ func (s *Scanner) ScanAndClean(opts ScanOptions) error {
durSince(start), c.seenTracksNew, len(c.seenTracks), itemErrs.Len())
}()
for _, musicPath := range s.musicPaths {
err := s.scanPath(c, opts.IsFull, musicPath)
var subItemErrs *multierr.Err
switch {
case errors.As(err, &subItemErrs):
itemErrs.Extend(subItemErrs.Errors())
case err != nil:
return fmt.Errorf("scan %q: %w", musicPath, err)
for _, dir := range s.musicDirs {
dirName := filepath.Base(dir)
err := filepath.WalkDir(dir, func(absPath string, d fs.DirEntry, err error) error {
if err != nil {
itemErrs.Add(err)
return nil
}
if !d.IsDir() {
return nil
}
if dir == absPath {
return nil
}
relPath, _ := filepath.Rel(dir, absPath)
log.Printf("processing folder `%s` `%s`", dirName, relPath)
tx := s.db.Begin()
if err := s.scanDir(tx, c, opts.IsFull, dir, relPath); err != nil {
itemErrs.Add(fmt.Errorf("%q: %w", absPath, err))
tx.Rollback()
return nil
}
if err := tx.Commit().Error; err != nil {
return fmt.Errorf("commit tx: %w", err)
}
return nil
})
if err != nil {
return fmt.Errorf("walk %q: %w", dir, err)
}
}
@@ -111,67 +132,41 @@ func (s *Scanner) ScanAndClean(opts ScanOptions) error {
return nil
}
func (s *Scanner) scanPath(c *collected, isFull bool, musicPath string) error {
itemErrs := multierr.Err{}
return godirwalk.Walk(musicPath, &godirwalk.Options{
Callback: func(_ string, _ *godirwalk.Dirent) error {
return nil
},
PostChildrenCallback: func(itemPath string, _ *godirwalk.Dirent) error {
return s.callback(c, isFull, musicPath, itemPath)
},
Unsorted: !s.sorted,
FollowSymbolicLinks: true,
ErrorCallback: func(path string, err error) godirwalk.ErrorAction {
itemErrs.Add(fmt.Errorf("%q: %w", path, err))
return godirwalk.SkipNode
},
})
}
func (s *Scanner) callback(c *collected, isFull bool, rootAbsPath string, itemAbsPath string) error {
relpath, _ := filepath.Rel(rootAbsPath, itemAbsPath)
log.Printf("processing folder `%s`", relpath)
if rootAbsPath == itemAbsPath {
return nil
}
gs, err := godirwalk.NewScanner(itemAbsPath)
func (s *Scanner) scanDir(tx *db.DB, c *collected, isFull bool, musicDir string, relPath string) error {
absPath := filepath.Join(musicDir, relPath)
items, err := os.ReadDir(absPath)
if err != nil {
return err
}
var tracks []string
var cover string
for gs.Scan() {
if isCover(gs.Name()) {
cover = gs.Name()
for _, item := range items {
if isCover(item.Name()) {
cover = item.Name()
continue
}
if _, ok := mime.FromExtension(ext(gs.Name())); ok {
tracks = append(tracks, gs.Name())
if _, ok := mime.FromExtension(ext(item.Name())); ok {
tracks = append(tracks, item.Name())
continue
}
}
tx := s.db.Begin()
defer tx.Commit()
pdir, pbasename := filepath.Split(filepath.Dir(relpath))
pdir, pbasename := filepath.Split(filepath.Dir(relPath))
parent := &db.Album{}
if err := tx.Where(db.Album{RootDir: rootAbsPath, LeftPath: pdir, RightPath: pbasename}).FirstOrCreate(parent).Error; err != nil {
if err := tx.Where(db.Album{RootDir: musicDir, LeftPath: pdir, RightPath: pbasename}).FirstOrCreate(parent).Error; err != nil {
return fmt.Errorf("first or create parent: %w", err)
}
c.seenAlbums[parent.ID] = struct{}{}
dir, basename := filepath.Split(relpath)
dir, basename := filepath.Split(relPath)
album := &db.Album{}
if err := tx.Where(db.Album{RootDir: rootAbsPath, LeftPath: dir, RightPath: basename}).First(album).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
if err := tx.Where(db.Album{RootDir: musicDir, LeftPath: dir, RightPath: basename}).First(album).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return fmt.Errorf("find album: %w", err)
}
if err := populateAlbumBasics(tx, rootAbsPath, parent, album, dir, basename, cover); err != nil {
if err := populateAlbumBasics(tx, musicDir, parent, album, dir, basename, cover); err != nil {
return fmt.Errorf("populate album basics: %w", err)
}
@@ -179,7 +174,7 @@ func (s *Scanner) callback(c *collected, isFull bool, rootAbsPath string, itemAb
sort.Strings(tracks)
for i, basename := range tracks {
abspath := filepath.Join(itemAbsPath, basename)
abspath := filepath.Join(musicDir, relPath, basename)
if err := s.populateTrackAndAlbumArtists(tx, c, i, album, basename, abspath, isFull); err != nil {
return fmt.Errorf("process %q: %w", "", err)
}
@@ -188,7 +183,7 @@ func (s *Scanner) callback(c *collected, isFull bool, rootAbsPath string, itemAb
return nil
}
func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *collected, i int, album *db.Album, basename string, abspath string, isFull bool) error {
func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *collected, i int, album *db.Album, basename string, absPath string, isFull bool) error {
track := &db.Track{AlbumID: album.ID, Filename: filepath.Base(basename)}
if err := tx.Where(track).First(track).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return fmt.Errorf("query track: %w", err)
@@ -196,7 +191,7 @@ func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *collected, i int, a
c.seenTracks[track.ID] = struct{}{}
stat, err := os.Stat(abspath)
stat, err := os.Stat(absPath)
if err != nil {
return fmt.Errorf("stating %q: %w", basename, err)
}
@@ -204,7 +199,7 @@ func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *collected, i int, a
return nil
}
trags, err := s.tagger.Read(abspath)
trags, err := s.tagger.Read(absPath)
if err != nil {
return fmt.Errorf("%v: %w", err, ErrReadingTags)
}
@@ -279,8 +274,8 @@ func populateAlbumBasics(tx *db.DB, rootAbsPath string, parent, album *db.Album,
return nil
}
func populateTrack(tx *db.DB, album *db.Album, albumArtist *db.Artist, track *db.Track, trags tags.Parser, abspath string, size int) error {
basename := filepath.Base(abspath)
func populateTrack(tx *db.DB, album *db.Album, albumArtist *db.Artist, track *db.Track, trags tags.Parser, absPath string, size int) error {
basename := filepath.Base(absPath)
track.Filename = basename
track.FilenameUDec = decoded(basename)
track.Size = size

View File

@@ -54,7 +54,7 @@ func New(opts Options) (*Server, error) {
tagger := &tags.TagReader{}
scanner := scanner.New(opts.MusicPaths, false, opts.DB, opts.GenreSplit, tagger)
scanner := scanner.New(opts.MusicPaths, opts.DB, opts.GenreSplit, tagger)
base := &ctrlbase.Controller{
DB: opts.DB,
ProxyPrefix: opts.ProxyPrefix,