User Tools

Site Tools


plaintext

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
plaintext [2020/10/25 13:32] – ↷ Page moved from form:plaintext to plaintext rjtplaintext [2024/03/02 18:03] (current) – Added some commands I use to work with playlists rjt
Line 1: Line 1:
 ====== Plaintext ====== ====== Plaintext ======
 +
 +===== My Use =====
 +
 +I mostly use [[mpd]] for playing digital music. This means the playlists are in a plaintext format (m3u), which I find really handy as I can easily modify them. Some examples:
 +
 +Search playlists for a term, for example a song or artist name.
 +
 +<code bash>grep -r -n -i [term] .</code>
 +
 +Replace term in playlists. For example if I move a directory or change a filename. You have to escape more non alphanumeric characters with a ''\'', common ones being ''/'', ''['', '']'', ''('', '')''. You can replace the asterisk with a specific file if you want. I'm using a pound symbol instead of the deaful ''/'' to make this a little less of a hassle.
 +
 +<code bash>sed -i 's#[find]#[replace]#g' *</code>
 +
 +I have a convoluted [[bash]] script to convert the paths in playlists formatted to work with [[mpd]] to ones that will works with, say, [[vlc]]. But hey, I learnt how to add arguments and do if/then statements in Bash so I'm very happy it works. (still have to add logging and show diff options)
 +
 +<code bash>
 +#!/bin/bash
 +# Converts .M3U playlists generated in MPD into
 +# ones usable outside MPD—in VLC, for example—by
 +# prepending information to the paths.
 +
 +# options:
 +# -f Convert single playlist, provide filename with extension.
 +# By default it will convert all .M3U files in mpd directory
 +# -a Convert to absolute paths (in /home/[user]/Music/Playlists/path_absolute)
 +# -r Convert to relative paths (in /home/[user]/Music/Playlists)
 +
 +dir=true
 +abs=false
 +rel=false
 +
 +while getopts :f:ard flag
 +do
 + case $flag in
 + f)
 + file=${OPTARG}
 + dir=false
 + ;;
 + a)
 + abs=true
 + ;;
 + r)
 + rel=true
 + ;;
 + esac
 +done
 +
 +if [ "$dir" = true ]
 +then
 + if [ "$abs" = true ] && [ "$rel" = false ]
 + then
 + for pl in /home/[user]/Music/Playlists/mpd/*.m3u
 + do
 + sed -e "s#^#/home/[user]/Music/#" "$pl" > "/home/[user]/Music/Playlists/path_absolute/${pl##*/}"
 + done
 + echo "Converted directory using absolute paths"
 + elif [ "$rel" = true ] && [ "$abs" = false ]
 + then
 + for pl in /home/[user]/Music/Playlists/mpd/*.m3u
 + do
 + sed -e "s#^#../#" "$pl" > "/home/[user]/Music/Playlists/${pl##*/}"
 + done
 + echo "Converted directory using relative paths"
 + elif [ "$abs" = true ] && [ "$rel" = true ]
 + then
 + for pl in /home/[user]/Music/Playlists/mpd/*.m3u
 + do
 + sed -e "s#^#/home/[user]/Music/#" "$pl" > "/home/[user]/Music/Playlists/path_absolute/${pl##*/}" &&
 + sed -e "s#^#../#" "$pl" > "/home/[user]/Music/Playlists/${pl##*/}"
 + done
 + echo "Converted directory using absolute and relative paths"
 + fi
 +elif [ "$dir" = false ]
 +then
 + if [ "$abs" = true ] && [ "$rel" = false ]
 + then
 + sed -e "s#^#/home/[user]/Music/#" "/home/[user]/Music/Playlists/mpd/$file.m3u" > "/home/[user]/Playlists/path_absolute/$file.m3u"
 + echo "Converted single file using absolute paths"
 + elif [ "$rel" = true ] && [ "$abs" = false ]
 + then
 + sed -e "s#^#../#" "/home/[user]/Music/Playlists/mpd/$file.m3u" > "/home/[user]/Music/Playlists/$file.m3u"
 + echo "Converted single file using relative paths"
 + elif [ "$abs" = true ] && [ "$rel" = true ]
 + then
 + sed -e "s#^#/home/[user]/Music/#" "/home/[user]/Music/Playlists/mpd/$file.m3u" > "/home/[user]/Playlists/path_absolute/$file.m3u" &&
 + sed -e "s#^#../#" "/home/[user]/Music/Playlists/mpd/$file.m3u" > "/home/[user]/Music/Playlists/$file.m3u"
 + echo "Converted single file using absolute and relative paths"
 + fi
 +fi
 +</code>
  
 ===== Metaforms ===== ===== Metaforms =====
Line 8: Line 98:
  
 ===== See Also ===== ===== See Also =====
 +
 +{{tag>form text}}
plaintext.txt · Last modified: 2024/03/02 18:03 by rjt