Post Reply 
Creating a New Music library view
06-03-2019, 18:26
Post: #10
RE: Creating a New Music library view
(06-03-2019 10:02)simoncn Wrote:  You can't match a missing tag but there is no need to do this. To add a RECENTLYADDED tag to this album, you can put the following in your tag update file:

@ALBUM=The SMiLE Sessions
&ALBUMARTIST=Beach Boys, The
&DATE=2011
+RECENTLYADDED=1

No idea how I missed that, sorry.

In that case my crude script will work. I only have flac so it searches for the latest 500 flac files (could be any number depending on how many albums you want to flag), loops through them in a time based order until it finds 10 albums (which are uniquely identified in my tags by ALBUM, ALBUMARTIST and DATE) then writes those out to a tagUpdate file.
I'm not addressing the scenario where I batch update files as I don't do that often. I then just have to add "RecentlyAdded=1" to indexTags.

This software continues to surprise me with how flexible it is!

Code:
#!/bin/bash

nLatestAlbums=10
musicRoot="/media/music"
tagUpdateFile="/media/music/tagUpdate.txt"


isInArray () {
  local e match="$1"
  shift
  for e; do
    [[ $e == $match ]] && return 0
  done
  return 1
}

nCount=0
> "$tagUpdateFile"

IFS='|'

# look at the first 500 files, modified in the last 60 days
find "$musicRoot"/ -name "*.flac" -type f -mtime -60 -printf '%T@ %p\n' | sort -k1,1nr | head -500 | cut -f2- -d" " |
{
while read fname; do

  albumKey=$(metaflac --list --block-type=VORBIS_COMMENT "$fname" | egrep -i ": (album=|albumartist=|date=)" | cut -f2- -d":" | sort -k1,1 -t'=' | cut -f2- -d"=" | tr '\n' '|')

  if [[ $albumKey != $lastAlbumKey ]]; then
    echo "$albumKey"

    isInArray "$albumKey" "${latestAlbums[@]}"
    if [[ $? -ne  0 ]]; then
      albumAttrs=($albumKey)
      echo "@ALBUM=${albumAttrs[0]}"$'\n'"&ALBUMARTIST=${albumAttrs[1]}"$'\n'"&DATE=${albumAttrs[2]}"$'\n'"+RECENTLYADDED=1" >> "$tagUpdateFile"

      nCount=$((nCount+1))
      if [[ $nCount -eq $nLatestAlbums ]]; then
        break
      fi
      latestAlbums+=("$albumKey")

    fi
    lastAlbumKey=$albumKey

  fi
done
}
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Creating a New Music library view - simbun - 06-03-2019 18:26

Forum Jump:


User(s) browsing this thread: 1 Guest(s)