this post was submitted on 12 Jul 2023
10 points (81.2% liked)

Linux

48143 readers
788 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Title basically, I need to parse the date modified, the time and seconds in order to reconstruct the filenames in the format of an android phone's camera roll.

I should be able to make the script once I know how to parse the metadata is all

you are viewing a single comment's thread
view the rest of the comments
[–] eager_eagle@lemmy.world 17 points 1 year ago

maybe something like this using mediainfo and exiftool?

#!/bin/bash

for file in *.jpg *.mp4; do
    # Extract date and time from file's metadata
    if [[ $file == *.jpg ]]; then
        datetime=$(exiftool -DateTimeOriginal -d "%Y%m%d_%H%M%S" "$file" | awk -F': ' '{print $2}')
    else
        datetime=$(mediainfo --Output="General;%File_Modified_Date%" "$file" | awk -F' ' '{print $1"_"$2}' | tr -d ':' | tr -d '-')
    fi

    # If datetime was found, rename the file 
    if [ -n "$datetime" ]; then
        # Extract extension of file 
        ext="${file##*.}"
        # Rename file with date and time as prefix (remove echo after testing it)
        echo mv -- "$file" "${datetime}.${ext}"
    fi

done