Skip to content

Commit

Permalink
Fix output path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kahst committed Jun 1, 2022
1 parent 5610b92 commit 08f0315
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 8 additions & 4 deletions analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,17 @@ def analyzeFile(item):
# Save as selection table
try:

# Make directory if it doesn't exist
if len(os.path.dirname(cfg.OUTPUT_PATH)) > 0 and not os.path.exists(os.path.dirname(cfg.OUTPUT_PATH)):
os.makedirs(os.path.dirname(cfg.OUTPUT_PATH), exist_ok=True)
# We have to check if output path is a file or directory
if not cfg.OUTPUT_PATH.rsplit('.', 1)[-1].lower() in ['txt', 'csv']:

if os.path.isdir(cfg.OUTPUT_PATH):
rpath = fpath.replace(cfg.INPUT_PATH, '')
rpath = rpath[1:] if rpath[0] in ['/', '\\'] else rpath

# Make target directory if it doesn't exist
rdir = os.path.join(cfg.OUTPUT_PATH, os.path.dirname(rpath))
if not os.path.exists(rdir):
os.makedirs(rdir, exist_ok=True)

if cfg.RESULT_TYPE == 'table':
rtype = '.BirdNET.selection.table.txt'
elif cfg.RESULT_TYPE == 'audacity':
Expand Down
14 changes: 9 additions & 5 deletions embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,20 @@ def analyzeFile(item):
writeErrorLog(msg)
return

# Save as selection table
# Save as embeddings file
try:

# Make directory if it doesn't exist
if len(os.path.dirname(cfg.OUTPUT_PATH)) > 0 and not os.path.exists(os.path.dirname(cfg.OUTPUT_PATH)):
os.makedirs(os.path.dirname(cfg.OUTPUT_PATH))
# We have to check if output path is a file or directory
if not cfg.OUTPUT_PATH.rsplit('.', 1)[-1].lower() in ['txt', 'csv']:

if os.path.isdir(cfg.OUTPUT_PATH):
fpath = fpath.replace(cfg.INPUT_PATH, '')
fpath = fpath[1:] if fpath[0] in ['/', '\\'] else fpath

# Make target directory if it doesn't exist
fdir = os.path.join(cfg.OUTPUT_PATH, os.path.dirname(fpath))
if not os.path.exists(fdir):
os.makedirs(fdir, exist_ok=True)

saveAsEmbeddingsFile(results, os.path.join(cfg.OUTPUT_PATH, fpath.rsplit('.', 1)[0] + '.birdnet.embeddings.txt'))
else:
saveAsEmbeddingsFile(results, cfg.OUTPUT_PATH)
Expand Down

0 comments on commit 08f0315

Please sign in to comment.