Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Add scan option --chunksize (default to 100)
Browse files Browse the repository at this point in the history
  • Loading branch information
zas committed Jan 14, 2024
1 parent bb6eab8 commit e200bdb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lb_content_resolver/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class Status(IntEnum):
Status.ERROR: 'error',
}

CHUNK_SIZE = 100

StatusDetails = namedtuple('StatusDetails', ('recording_name', 'artist_name', 'release_name'))


Expand Down Expand Up @@ -101,7 +99,7 @@ def close(self):
""" Close the db."""
db.close()

def scan(self, music_dirs):
def scan(self, music_dirs, chunksize=100):
"""
Scan music directories and add tracks to sqlite.
"""
Expand All @@ -114,6 +112,8 @@ def scan(self, music_dirs):
print("No valid directories to scan")
return

self.chunksize = chunksize

# Keep some stats
self.total = 0
self.statuscounters = {
Expand Down Expand Up @@ -173,7 +173,7 @@ def traverse(self, dry_run=False):
number += 1
if not dry_run:
self.add(file_path, number)
if number % CHUNK_SIZE == 0:
if number % self.chunksize == 0:
self.manage_chunk()

if not dry_run:
Expand Down
8 changes: 6 additions & 2 deletions resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from troi.playlist import PLAYLIST_TRACK_EXTENSION_URI


DEFAULT_CHUNKSIZE = 100


def output_playlist(db, jspf, upload_to_subsonic, save_to_playlist, dont_ask):
if jspf is None:
return
Expand Down Expand Up @@ -98,8 +101,9 @@ def create(db_file):

@click.command()
@click.option("-d", "--db_file", help="Database file for the local collection", required=False, is_flag=False)
@click.option('-c', '--chunksize', default=DEFAULT_CHUNKSIZE)
@click.argument('music_dirs', nargs=-1, type=click.Path())
def scan(db_file, music_dirs):
def scan(db_file, music_dirs, chunksize=DEFAULT_CHUNKSIZE):
"""Scan one or more directories and their subdirectories for music files to add to the collection.
If no path is passed, check for MUSIC_DIRECTORIES in config instead.
"""
Expand All @@ -108,7 +112,7 @@ def scan(db_file, music_dirs):
db.open()
if not music_dirs:
music_dirs = music_directories_from_config()
db.scan(music_dirs)
db.scan(music_dirs, chunksize=chunksize)

# Remove any recordings from the unresolved recordings that may have just been added.
urt = UnresolvedRecordingTracker()
Expand Down

0 comments on commit e200bdb

Please sign in to comment.