Scene filename to metadata parser (#164)

* Initial UI prototype

* Add backend support to update multiple scenes

* Fix title editing issues

* Add query regex support. UI improvements

* Rewrite parser. Add fields button and page size

* Add helper text for escaping {} characters

* Validate date

* Only set values if different from original

* Only update scenes that have something changed

* Add built in parser input recipes

* Make pattern matching case-insensistive
This commit is contained in:
WithoutPants
2019-10-31 00:37:21 +11:00
committed by Leopere
parent e59fd147cf
commit 7cb9cd8a38
12 changed files with 1140 additions and 14 deletions

View File

@@ -1,12 +1,14 @@
package database
import (
"database/sql"
"fmt"
"regexp"
"github.com/gobuffalo/packr/v2"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/source"
"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
sqlite3 "github.com/mattn/go-sqlite3"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/utils"
"os"
@@ -15,11 +17,16 @@ import (
var DB *sqlx.DB
var appSchemaVersion uint = 1
const sqlite3Driver = "sqlite3_regexp"
func Initialize(databasePath string) {
runMigrations(databasePath)
// register custom driver with regexp function
registerRegexpFunc()
// https://github.com/mattn/go-sqlite3
conn, err := sqlx.Open("sqlite3", "file:"+databasePath+"?_fk=true")
conn, err := sqlx.Open(sqlite3Driver, "file:"+databasePath+"?_fk=true")
conn.SetMaxOpenConns(25)
conn.SetMaxIdleConns(4)
if err != nil {
@@ -62,3 +69,16 @@ func runMigrations(databasePath string) {
}
}
}
func registerRegexpFunc() {
regexFn := func(re, s string) (bool, error) {
return regexp.MatchString(re, s)
}
sql.Register(sqlite3Driver,
&sqlite3.SQLiteDriver{
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
return conn.RegisterFunc("regexp", regexFn, true)
},
})
}