<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>Autarchy of the Private Cave &#187; moodbar</title> <atom:link href="https://bogdan.org.ua/tags/moodbar/feed" rel="self" type="application/rss+xml" /><link>https://bogdan.org.ua</link> <description>Tiny bits of bioinformatics, [web-]programming etc</description> <lastBuildDate>Wed, 28 Dec 2022 16:09:04 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>https://wordpress.org/?v=3.8.27</generator> <item><title>Generate .mood moodbar files for your whole music collection</title><link>https://bogdan.org.ua/2011/04/10/generate-mood-moodbar-files-for-your-whole-music-collection.html</link> <comments>https://bogdan.org.ua/2011/04/10/generate-mood-moodbar-files-for-your-whole-music-collection.html#comments</comments> <pubDate>Sun, 10 Apr 2011 20:21:46 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[*nix]]></category> <category><![CDATA[Links]]></category> <category><![CDATA[Notepad]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[amarok]]></category> <category><![CDATA[moodbar]]></category> <category><![CDATA[music]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=1561</guid> <description><![CDATA[Amarok moodbar wiki page has 2 nice scripts to generate .mood files for your whole music collection (to be displayed by amarok when playing). Both scripts should be started from the directory where you keep your music. The .mood files will be generated next to the source music files (in the same directories). You can [&#8230;]]]></description> <content:encoded><![CDATA[<p><a
href="http://amarok.kde.org/wiki/Moodbar" class="broken_link" rel="nofollow">Amarok moodbar wiki</a> page has 2 nice scripts to generate .mood files for your whole music collection (to be displayed by amarok when playing).</p><p><span
id="more-1561"></span></p><p>Both scripts should be started from the directory where you keep your music. The .mood files will be generated next to the source music files (in the same directories). You can modify the scripts to have the moods stored to $HOME/.kde/share/apps/amarok/moods/, so as not to clutter your music directories.</p><p>Script for multicore CPUs (will not overwrite existing mood files):<br
/> <code><br
/> #!/bin/bash<br
/> NUMCPU="$(grep ^processor /proc/cpuinfo | wc -l)"</p><p>find . -type f -regextype posix-awk -iregex '.*\.(mp3|ogg|flac|wma)' | while read i ; do</p><p> while [ `jobs -p | wc -l` -ge $NUMCPU ] ; do<br
/> sleep 0.1<br
/> done</p><p> TEMP="${i%.*}.mood"<br
/> OUTF=`echo "$TEMP" | sed 's#\(.*\)/\([^,]*\)#\1/.\2#'`<br
/> if [ ! -e "$OUTF" ] ; then<br
/> moodbar -o "$OUTF" "$i" &#038;<br
/> fi<br
/> done<br
/> </code></p><p>Script for single-threaded moods generation (will only overwrite the last-generated mood file from a previous run):<br
/> <code><br
/> #!/bin/bash<br
/> DIR=${1:-.}<br
/> LAST=.moodbar-lastreadsong<br
/> C_RET=0</p><p>control_c()        # run if user hits control-c<br
/> {<br
/> echo "$1" > "$LAST"<br
/> echo "Exiting..."<br
/> exit<br
/> }</p><p>if [ -e "$LAST" ]; then<br
/> read filetodelete < "$LAST"
rm "$filetodelete" "$LAST"
fi
exec 9< <(find "$DIR" -type f -regextype posix-awk -iregex '.*\.(mp3|ogg|flac|wma)') # you may need to add m4a and mp4
while read i
do
TEMP="${i%.*}.mood"
OUTF=`echo "$TEMP" | sed 's#\(.*\)/\([^,]*\)#\1/.\2#'`
trap 'control_c "$OUTF"' INT
if [ ! -e "$OUTF" ] || [ "$i" -nt "$OUTF" ]; then
moodbar -o "$OUTF" "$i" || { C_RET=1; echo "An error occurred!" >&#038;2; }<br
/> fi<br
/> done <&#038;9
exec 9<&#038;-
exit $C_RET
</code></p><p>That same page has a link to an older, somewhat more polished <a
href="http://forum.kde.org/viewtopic.php?f=119&amp;t=84811" class="broken_link" rel="nofollow">ruby script</a> for the same task. It requires a running instance of Amarok, and uses it's media collection to find music files and create mood files for them. This script can potentially (after a little editing) store .mood files either with the music or to the $HOME/.kde/... path mentioned above. It is for an older version of Amarok, and thus is not likely to work with e.g. Amarok 2.4</p><p><code><br
/> #!/usr/bin/ruby</p><p># Simple moodbar file management utility by Joe Rabinoff<br
/> # This is also my first ever ruby script so bear with me</p><p>$moodbar_folder = "#{ENV['HOME']}/.kde/share/apps/amarok/moods/"</p><p>def usage()<br
/> print "This is the moodbar file management utility\n"<br
/> print "\n"<br
/> print "Usage is:\n"<br
/> print "   moodbar_util.rb -rename    Rename mood files" \<br
/> + " from any old naming scheme to the current one\n" \<br
/> + "                              (not applicable when mood" \<br
/> + " files are stored with music)\n"<br
/> print "   moodbar_util.rb -calcall   Calculate all un-calculated" \<br
/> + " mood files\n"<br
/> exit(1)<br
/> end</p><p>def check_amarok_running()<br
/> result = `dcop 'amarok*'`.split("\n")<br
/> return (result.length > 0)<br
/> end</p><p>def get_devices()<br
/> result = `dcop amarok collection query 'SELECT id, lastmountpoint FROM devices;'`.split("\n")<br
/> ret = Hash.new()<br
/> result.each_index do |i|<br
/> ret[result[i].to_i] = result[i+1] if i % 2 == 0<br
/> end<br
/> return ret<br
/> end</p><p>def mood_name(url, deviceid)<br
/> ret = url.gsub(/\//, ',')<br
/> return deviceid.to_s + "," + ret<br
/> end</p><p>def rename()<br
/> print "Renaming mood files from outdated naming schemes...\n"</p><p> # As far as I can tell, the best way to do this is just select all<br
/> # tracks, check the old possible moodbar names, and rename them<br
/> tracks = `dcop amarok collection query 'SELECT url, deviceid FROM tags;'`.split("\n")<br
/> devices = get_devices</p><p> 0.step(tracks.length-1, 2) do |i|<br
/> url      = tracks[i].sub(/\.[^\.]*$/, '.mood')<br
/> deviceid = tracks[i+1].to_i</p><p> path = url.sub(/\./, '')<br
/> if devices.has_key?(deviceid)<br
/> path = devices[deviceid] + path<br
/> end<br
/> moodfile  = $moodbar_folder + mood_name(url, deviceid)<br
/> moodfile1 = $moodbar_folder + path.gsub(/\//, ',')</p><p> next if FileTest.exists?(moodfile)</p><p> if FileTest.exists?(moodfile1)<br
/> system("mv", "-f", moodfile1, moodfile)<br
/> print "Moved ", moodfile1, " to ", moodfile, "\n"<br
/> end</p><p> end</p><p>end</p><p>def calcall()<br
/> print "Calculating all nonexisting moodbars...\n\n"</p><p> tracks = `dcop amarok collection query 'SELECT url, deviceid FROM tags;'`.split("\n")<br
/> devices = get_devices<br
/> withMusic = (`dcop amarok script readConfig MoodsWithMusic`.chomp == "true")</p><p> 0.step(tracks.length-1, 2) do |i|<br
/> url      = tracks[i]<br
/> deviceid = tracks[i+1].to_i</p><p> moodfile = ""</p><p> songpath = url.sub(/\./, '')<br
/> if devices.has_key?(deviceid)<br
/> songpath = devices[deviceid] + songpath<br
/> end</p><p> if withMusic<br
/> moodfile = songpath.sub(/\.[^\.]*$/, '.mood')<br
/> moodfile = File.dirname(moodfile) + "/." + File.basename(moodfile)<br
/> else<br
/> moodfile = $moodbar_folder \<br
/> + mood_name(url.sub(/\.[^\.]*$/, '.mood'), deviceid)<br
/> end</p><p> next if FileTest.exists?(moodfile) &#038;&#038; FileTest.size(moodfile) > 0<br
/> next unless FileTest.exists?(songpath)</p><p> print "Saving moodbar for ", songpath, "\n"<br
/> print "   to file ", moodfile, "\n"<br
/> system("moodbar", "-o", moodfile, songpath)<br
/> print "\n"</p><p> end</p><p>end</p><p>$mode = ARGV[0]</p><p>if !check_amarok_running<br
/> print "Amarok is not running!  Please start Amarok and re-run " \<br
/> "this script.\n"<br
/> end</p><p>if $mode == "-rename"<br
/> rename<br
/> elsif $mode == "-calcall"<br
/> calcall<br
/> else<br
/> usage<br
/> end<br
/> </code></p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F04%2F10%2Fgenerate-mood-moodbar-files-for-your-whole-music-collection.html&amp;linkname=Generate%20.mood%20moodbar%20files%20for%20your%20whole%20music%20collection" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F04%2F10%2Fgenerate-mood-moodbar-files-for-your-whole-music-collection.html&amp;linkname=Generate%20.mood%20moodbar%20files%20for%20your%20whole%20music%20collection" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F04%2F10%2Fgenerate-mood-moodbar-files-for-your-whole-music-collection.html&amp;linkname=Generate%20.mood%20moodbar%20files%20for%20your%20whole%20music%20collection" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F04%2F10%2Fgenerate-mood-moodbar-files-for-your-whole-music-collection.html&amp;linkname=Generate%20.mood%20moodbar%20files%20for%20your%20whole%20music%20collection" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F04%2F10%2Fgenerate-mood-moodbar-files-for-your-whole-music-collection.html&amp;linkname=Generate%20.mood%20moodbar%20files%20for%20your%20whole%20music%20collection" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2011%2F04%2F10%2Fgenerate-mood-moodbar-files-for-your-whole-music-collection.html&#038;title=Generate%20.mood%20moodbar%20files%20for%20your%20whole%20music%20collection" data-a2a-url="https://bogdan.org.ua/2011/04/10/generate-mood-moodbar-files-for-your-whole-music-collection.html" data-a2a-title="Generate .mood moodbar files for your whole music collection"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2011/04/10/generate-mood-moodbar-files-for-your-whole-music-collection.html/feed</wfw:commentRss> <slash:comments>3</slash:comments> </item> </channel> </rss>