mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 21:09:05 +00:00
Merge pull request #221 from Kjeldgaard/ignore_media
Ignore media files
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
type AlbumScannerCache struct {
|
||||
path_contains_photos map[string]bool
|
||||
photo_types map[string]MediaType
|
||||
ignore_data map[string][]string
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
@@ -17,6 +18,7 @@ func MakeAlbumCache() *AlbumScannerCache {
|
||||
return &AlbumScannerCache{
|
||||
path_contains_photos: make(map[string]bool),
|
||||
photo_types: make(map[string]MediaType),
|
||||
ignore_data: make(map[string][]string),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,3 +86,22 @@ func (c *AlbumScannerCache) GetMediaType(path string) (*MediaType, error) {
|
||||
|
||||
return mediaType, nil
|
||||
}
|
||||
|
||||
func (c *AlbumScannerCache) GetAlbumIgnore(path string) (*[]string) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
|
||||
ignore_data, found := c.ignore_data[path]
|
||||
if found {
|
||||
return &ignore_data
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *AlbumScannerCache) InsertAlbumIgnore(path string, ignore_data []string) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
|
||||
c.ignore_data[path] = ignore_data
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package scanner
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"github.com/photoview/photoview/api/scanner/face_detection"
|
||||
"github.com/photoview/photoview/api/utils"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sabhiram/go-gitignore"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -136,10 +138,19 @@ func findMediaForAlbum(album *models.Album, cache *AlbumScannerCache, db *gorm.D
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get ignore data
|
||||
albumIgnore := ignore.CompileIgnoreLines(*cache.GetAlbumIgnore(album.Path)...)
|
||||
|
||||
for _, item := range dirContent {
|
||||
photoPath := path.Join(album.Path, item.Name())
|
||||
|
||||
if !item.IsDir() && isPathMedia(photoPath, cache) {
|
||||
// Match file against ignore data
|
||||
if (albumIgnore.MatchesPath(item.Name())) {
|
||||
log.Printf("File %s ignored\n", item.Name())
|
||||
continue
|
||||
}
|
||||
|
||||
// Skip the JPEGs that are compressed version of raw files
|
||||
counterpartFile := scanForRawCounterpartFile(photoPath)
|
||||
if counterpartFile != nil {
|
||||
|
||||
@@ -147,6 +147,9 @@ func findAlbumsForUser(db *gorm.DB, user *models.User, album_cache *AlbumScanner
|
||||
Path: albumPath,
|
||||
}
|
||||
|
||||
// Store album ignore
|
||||
album_cache.InsertAlbumIgnore(albumPath, albumIgnore)
|
||||
|
||||
if err := tx.Create(&album).Error; err != nil {
|
||||
return errors.Wrap(err, "insert album into database")
|
||||
}
|
||||
@@ -170,6 +173,8 @@ func findAlbumsForUser(db *gorm.DB, user *models.User, album_cache *AlbumScanner
|
||||
}
|
||||
}
|
||||
|
||||
// Update album ignore
|
||||
album_cache.InsertAlbumIgnore(albumPath, albumIgnore)
|
||||
}
|
||||
|
||||
userAlbums = append(userAlbums, album)
|
||||
@@ -191,7 +196,7 @@ func findAlbumsForUser(db *gorm.DB, user *models.User, album_cache *AlbumScanner
|
||||
continue
|
||||
}
|
||||
|
||||
if item.IsDir() && directoryContainsPhotos(subalbumPath, album_cache) {
|
||||
if item.IsDir() && directoryContainsPhotos(subalbumPath, album_cache, albumIgnore) {
|
||||
scanQueue.PushBack(scanInfo{
|
||||
path: subalbumPath,
|
||||
parent: album,
|
||||
@@ -207,7 +212,7 @@ func findAlbumsForUser(db *gorm.DB, user *models.User, album_cache *AlbumScanner
|
||||
return userAlbums, scanErrors
|
||||
}
|
||||
|
||||
func directoryContainsPhotos(rootPath string, cache *AlbumScannerCache) bool {
|
||||
func directoryContainsPhotos(rootPath string, cache *AlbumScannerCache, albumIgnore []string) bool {
|
||||
|
||||
if contains_image := cache.AlbumContainsPhotos(rootPath); contains_image != nil {
|
||||
return *contains_image
|
||||
@@ -225,6 +230,15 @@ func directoryContainsPhotos(rootPath string, cache *AlbumScannerCache) bool {
|
||||
|
||||
scanned_directories = append(scanned_directories, dirPath)
|
||||
|
||||
// Update ignore dir list
|
||||
photoviewIgnore, err := getPhotoviewIgnore(dirPath)
|
||||
if err != nil {
|
||||
log.Printf("Failed to get ignore file, err = %s", err)
|
||||
} else {
|
||||
albumIgnore = append(albumIgnore, photoviewIgnore...)
|
||||
}
|
||||
ignoreEntries := ignore.CompileIgnoreLines(albumIgnore...)
|
||||
|
||||
dirContent, err := ioutil.ReadDir(dirPath)
|
||||
if err != nil {
|
||||
ScannerError("Could not read directory (%s): %s\n", dirPath, err.Error())
|
||||
@@ -237,6 +251,11 @@ func directoryContainsPhotos(rootPath string, cache *AlbumScannerCache) bool {
|
||||
scanQueue.PushBack(filePath)
|
||||
} else {
|
||||
if isPathMedia(filePath, cache) {
|
||||
if ignoreEntries.MatchesPath(fileInfo.Name()) {
|
||||
log.Printf("Match found %s, continue search for media", fileInfo.Name())
|
||||
continue
|
||||
}
|
||||
log.Printf("Insert Album %s %s, contains photo is true", dirPath, rootPath)
|
||||
cache.InsertAlbumPaths(dirPath, rootPath, true)
|
||||
return true
|
||||
}
|
||||
@@ -246,6 +265,7 @@ func directoryContainsPhotos(rootPath string, cache *AlbumScannerCache) bool {
|
||||
}
|
||||
|
||||
for _, scanned_path := range scanned_directories {
|
||||
log.Printf("Insert Album %s, contains photo is false", scanned_path)
|
||||
cache.InsertAlbumPath(scanned_path, false)
|
||||
}
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user