Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions scan-batch-dir
Original file line number Diff line number Diff line change
Expand Up @@ -636,25 +636,28 @@ def process_unknown(file_path:str):
def get_file_info(file_path: str):
"""
Obtain information about the file_path file.

Args:
file_path (str) The Path to the file.

Returns:
pid (str) The PID of the file.
pid (str) The PID of the file (everything before the first period).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it impossible for a PID to contain a period, which I think is an undesirable restriction.

Instead, let's simplify the whole thing as @ojas-uls-dev suggested. Just use os.path.splitext to extract the extension, and everything before that is the PID. If bad data is given where ".mp3" in incorrectly included in the PID, that is for a human to correct.

If you really want to go the extra mile to look for double extensions, use the list of known extensions to strip them out.

parent (str) The parent directory of the file.
file (str) The filename and extension of the file.
dir (str) The directory that the file is located in.
ext (str) The file extension of the file.
ext (str) The file extension of the file (everything after the last period).
"""
dir,ext = os.path.splitext(file_path) # Split the file_path into directory and extension.
file_name = os.path.basename(dir) # Get the file_name of the object which will usually be the pid.
pid = file_name # Assign pid to the last piece of the directory.
parent = os.path.basename(os.path.dirname(file_path))
dir = os.path.dirname(file_path)
file = f"{pid}{ext}"
full_name = os.path.basename(file_path) # e.g. "abc.def.ghi.txt"
parent = os.path.basename(dir)

return(pid,parent,file,dir,ext)
if '.' in full_name:
pid = full_name.split('.')[0] # Everything before the first period.
ext = '.' + full_name.rsplit('.', 1)[1] # Everything after the last period.
else:
pid = full_name
ext = ''

file = full_name
return (pid, parent, file, dir, ext)


def add_update_dataframe(df: pd.DataFrame, pid: str, row_data):
Expand Down Expand Up @@ -797,7 +800,12 @@ def process_file(df: pd.DataFrame, file_path: str, level):

file_folder = os.path.dirname(file_path) # The Full Path including Directory containing the file.
base_name = os.path.basename(file_path) # The Base filename with extension of the file give the file_path.
file_name,file_ext = os.path.splitext(base_name)# The Separated Filename and Extension of the Base filename.
if '.' in base_name:
file_name = base_name.split('.')[0] # The Base filename without extension of the file give the file_path.
file_ext = '.' + base_name.rsplit('.', 1)[1] # The Extension of the file give the file_path.
else:
file_name = base_name
file_ext = ''

# Set the file weight if the file_name is a digit or contains "-\d{4}"
file_weight = ''
Expand Down Expand Up @@ -880,6 +888,7 @@ def process_file(df: pd.DataFrame, file_path: str, level):
# Override Row Data.
# For transcription files just update the transcript column.
row_data = {
'id': pid,
'transcript': file_path
}

Expand Down