|
1 | 1 | import datetime
|
| 2 | +from functools import partial |
2 | 3 | import glob
|
3 | 4 | import numpy as np
|
4 | 5 | import os
|
|
7 | 8 | import subprocess
|
8 | 9 |
|
9 | 10 | from .tables import IndexTable, IndexColumn, is_boolean
|
10 |
| -from .utils import get_audio_duration |
| 11 | +from .utils import get_audio_duration, path_is_parent |
11 | 12 |
|
12 | 13 |
|
13 | 14 | class ChildProject:
|
@@ -384,7 +385,10 @@ def validate(self, ignore_files: bool = False) -> tuple:
|
384 | 385 | self.warnings.append(message)
|
385 | 386 |
|
386 | 387 | # child id refers to an existing child in the children table
|
387 |
| - if str(row["child_id"]) not in self.children["child_id"].astype(str).tolist(): |
| 388 | + if ( |
| 389 | + str(row["child_id"]) |
| 390 | + not in self.children["child_id"].astype(str).tolist() |
| 391 | + ): |
388 | 392 | self.errors.append(
|
389 | 393 | "child_id '{}' in recordings on line {} cannot be found in the children table.".format(
|
390 | 394 | row["child_id"], index
|
@@ -483,19 +487,41 @@ def get_converted_recording_filename(
|
483 | 487 | self.converted_recordings_hashtable[key] = None
|
484 | 488 | return None
|
485 | 489 |
|
486 |
| - def get_recordings_from_list(self, recordings: list): |
| 490 | + def recording_from_path(self, path: str, profile: str = None) -> str: |
| 491 | + if profile: |
| 492 | + media_path = os.path.join(self.path, self.CONVERTED_RECORDINGS, profile) |
| 493 | + else: |
| 494 | + media_path = os.path.join(self.path, self.RAW_RECORDINGS) |
| 495 | + |
| 496 | + if not path_is_parent(media_path, path): |
| 497 | + return None |
| 498 | + |
| 499 | + recording = os.path.relpath( |
| 500 | + path, media_path |
| 501 | + ) |
| 502 | + |
| 503 | + return recording |
| 504 | + |
| 505 | + |
| 506 | + def get_recordings_from_list(self, recordings: list, profile: str = None) -> pd.DataFrame: |
| 507 | + """Recover recordings metadata from a list of recordings or path to recordings. |
| 508 | +
|
| 509 | + :param recordings: list of recording names or paths |
| 510 | + :type recordings: list |
| 511 | + :return: matching recordings |
| 512 | + :rtype: pd.DataFrame |
| 513 | + """ |
487 | 514 | _recordings = self.recordings.copy()
|
488 | 515 |
|
489 | 516 | if recordings is not None:
|
490 | 517 | # if the user provided paths,
|
491 | 518 | # transform those paths into recording_filename values
|
492 |
| - if all(map(os.path.exists, recordings)): |
493 |
| - recordings = [ |
494 |
| - os.path.relpath( |
495 |
| - recording, os.path.join(self.path, self.RAW_RECORDINGS) |
496 |
| - ) |
497 |
| - for recording in recordings |
498 |
| - ] |
| 519 | + recordings_from_paths = [ |
| 520 | + self.recording_from_path(recording, profile) for recording in recordings |
| 521 | + ] |
| 522 | + |
| 523 | + if None not in recordings_from_paths: |
| 524 | + recordings = recordings_from_paths |
499 | 525 |
|
500 | 526 | _recordings = _recordings[
|
501 | 527 | _recordings["recording_filename"].isin(recordings)
|
|
0 commit comments