First commit

This commit is contained in:
Git Commiter for 96-fromsofia.net 2023-02-27 01:16:56 +00:00
commit 4512ec62d1
2 changed files with 78 additions and 0 deletions

14
README.txt Normal file
View File

@ -0,0 +1,14 @@
DESCRIPTION:
If you ever tried to copy songs from your iPhone directly onto your filesystem (not using iTunes) then you know you will find all your songs renamed in a very weird "Apple" way.. This is regardless of what the filenames were when you were intially copying these onto your iphone as it will later on overwrite their file names.
This however is only for the actual file name. Meaning if your media had it's track title, performer or album in the metadata then this will still be there.
Using the help of the mediainfo utility you can pull metadata information from various media formats. Based on what is availbale in the metadata you can then rename your iphone songs with something that is actually human readable. This script attempts to automate this process.
NOTE:
1) This script works around the mediainfo package. It is a simple utility to get metadata info from various media types
2) This script relies on metadata in your media in order to rename your files. Depending on how you acquired your media in the first place, some metadata may be missing hence resulting in incomplete output!!
3) To mount your iphone on a Linux device, you will need libimodiledevice libraries + the ifuse package --> Ref: https://wiki.archlinux.org/title/IOS
AUTHOR:
96-fromsofia - 2A9-7CC@96-fromsofia.net || August 2021

View File

@ -0,0 +1,64 @@
#!/bin/bash
# NOTE:
# 1) This script works around the mediainfo package. It is a simple utility to get metadata info from various media types
# 2) This script relies on metadata in your media in order to rename your files. Depending on how you acquired your media in the first place, some metadata may be missing hence resulting in incomplete output!!
# 3) To mount your iphone on a Linux device, you will need libimodiledevice libraries + the ifuse package --> Ref: https://wiki.archlinux.org/title/IOS
# Set a random session number
session=$RANDOM
# Specify the particular delimiter for string devision by IFS (Internal Field Separator)
IFS='
'
# Specify the path where your iphone is mounted
mountpoint="/mnt/iphone"
iphone_music="$mountpoint/Music/F*/*"
# Specify the destination path where you want the new file names copied
destination="/home/user/Music"
# Create a temp file to store "failed items"
touch $PWD/failed_list$session.txt
fail_list=$PWD/failed_list$session.txt
# Loop through all the songs in $iphone_music
for song in $iphone_music
do
# Use the mediainfo utility to get the song name, it's performer and album
song_artist=$(mediainfo $song | grep "Album/Performer" | cut -c 44-)
song_name=$(mediainfo $song | grep -m 1 "Track name" | cut -c 44-)
song_album=$(mediainfo $song | grep -m 1 "Album" | cut -c 44-)
# If it doesn't have a song name add to failed list and continue with next song
if [ -z "$song_name" ]
then
echo $song >> $fail_list
continue
# Alternatively use next elif and else to create the $dest_name based on the metadata that has been found
elif [ -n "$song_artist" && -n "$song_album" ]
then
dest_name=$(printf "$song_name by $song_artist from $song_album")
elif [ -n "$song_artist" && -z "$song_album" ]
then
dest_name=$(printf "$song_name by $song_artist")
elif [ -z "$song_artist" && -n "$song_album" ]
dest_name=$(printf "$song_name from the album: $song_album")
else
dest_name=$(printf "$song_name")
fi
# Copy the original file to a new one in the specified $destination with it's new metadata generated name
cp $song "$destination/$dest_name"
done
# Update the user with the failed files
echo -e "WARNING \!\!\!\nThe following items have no song name in their metadata hence were not renamed and copied over:"
cat $fail_list
yes | rm $fail_list
# Confirm the successfully renamed and copied media
echo "The rest of your files have been saved into $destination"
ls -l $destination