Natenoms Wiki

Weil Teilen Spaß macht :)

Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

Übersetzungen dieser Seite:

Navigation



Lizenz dieses Wikis
Über dieses Wiki
Feed des Wikis
Impressum


Was gerade in meinem Blog geschieht:

linux:scripte:moc:moc_extend

Bash Script moc_extend.sh für Music on Console

Das alte moc_move.sh Script wurde erweitert … und in moc_extend.sh umbenannt.

Features

  • (Neu) FreeMusicCharts Playliste herunterladen, anhören und einzelne Stücke herunterladen (inspiriert durch diesen Artikel).
    • MOC scheint mit dem Status „302 Moved Temporarily“ nichts anfangen zu können und gibt die Meldung „Format not supported“ aus.
      In dem Fall einfach die Datei herunterladen und so anhören :)
  • Man kann Musik in vorhandene Kategorien einordnen oder neue Kategorien erstellen.
  • Aktuelle Datei/aktuelles Verzeichnis löschen (bzw. in den „badmusic“ Ordner verschieben).
  • Musikwertung vergeben/abfragen (0-50 Punkte).
  • Musik in ein Zip-Archiv packen (weil öfters Leute die gerade laufende Musik haben wollen).
  • Radio-Streams anzeigen und anhören (extra Script).
  • Playliste der am besten bewerteten Stücke erstellen.
  • Musik-Infos per ssh auf ein Webverzeichnis hochladen (ogginfo, id3tag oder nur der Dateiname).
  • Zeigt die Metadaten einer Datei an.

Alles was knotify, kdialog oder gnome notify verwendete (die aufpoppenden Nachrichten), wurde entfernt; Nachrichten werden jetzt direkt im Terminal angezeigt.

Screenshots


Das verwendete Terminal ist übrigens rxvt-unicode mit dieser Konfiguration.

Konfiguration

Damit das Ganze wie gezeigt im eigenen MOC läuft, muss man das natürlich in seinem MOC hinterlegen:

Z. B. aktuell bei mir:

ExecCommand1            = "/home/apps/scripts/jamendo_listen.sh -v -snlm moc"
ExecCommand2            = "/home/apps/scripts/jamendo_listen.sh -lvf .lvurl_from_start -snlm moc"
#ExecCommand3           = "/home/apps/scripts/jamendo_listen.sh -plv"
ExecCommand4            = "/home/apps/scripts/feed_ices.sh add %f"
ExecCommand5            = "/home/apps/scripts/moc_extend.sh %f selection"
ExecCommand6            = "/home/apps/scripts/moc_extend.sh %f automaticcats"
#ExecCommand7           = "/home/apps/bin/moc_extend.sh %f radio"
ExecCommand8            = "/home/apps/scripts/moc_extend.sh %f delete"
ExecCommand10            = "/home/apps/scripts/moc_extend.sh %f help"

Das Script

Die alte Version 0.1.7 findet man hier: https://wiki.natenom.de/uploads/scripts/moc_extend-0.1.7.sh.

moc_extend-0.1.8.5.sh
#!/bin/bash
AUTHOR="Natenom"
EMAIL="natenom@natenom.com"
VERSION="0.1.8.5"
LASTEDIT="2010-11-02"
 
MOCP="/bin/mocp"
#Important: If in this script mocp is called it must be started into the background "mocp &".
 
# Use it like this:
#  $0 PATH_TO_FILE WHAT_TO_DO [SUBTARGET]
# SUBTARGET it not necessary.
 
#### SETTINGS ####
#  Directories:
MUSIC_BASE="/home/Music" #Base directory for our music.
MUSIC_FREE="${MUSIC_BASE}/Music_Free" #Free Music Directory.
M_DST_DELETE="/home/badmusic" #Instead of deleting move bad music to this directory.
M_SENDTOARCH_ARCHIVE="/home/username/Desktop/Music.zip" #Music archive (zip) to send music...
FREE_MUSIC_CHARTS_DEST="${MUSIC_FREE}/FreeMusicCharts" #Where to download FreeMusicCharts files to.
 
#  Else:
MESSAGE_TIME=1 #Time in seconds to show messages...
 
#Other Scripts:
STREAMSCRIPT="/bin/stream.sh"
RATESCRIPT="/bin/rate.sh"
#### End: SETTINGS ####
 
#####################################
#### DO NOT EDIT BELOW THIS LINE ####
#####################################
declare -a M__cats_free #indexed array (see man bash)
 
#PATH_TO_FILE
M_FILE="${1}"
 
#SUBTARGET
# Not necessary for every case.
SUBTARGET="${3}"
 
#Pushes the current song information onto a server using ssh.
function pushsonginformation() {
  _file="${1}"
	#_ssh_key="/path/to/key" #Only needed if not using a .ssh/config ...
	_remote_ip="yourip.ip.ip.ip or name"
	_remote_user="username"
	_remote_port="21"
	_songinfo_file_local="/tmp/song"
	_songinfo_file_remote="/var/www/dest/folder/file"
	_hide_path="/home/Music" #Hide/remove this part of your path (usually your private music directory).
 
	#Get Infos about the song and write them into the file.
	printtaginfo "${_file}" 0 | sed s+"${_hide_path}"++g > "${_songinfo_file_local}"
	scp -P ${_remote_port} "${_songinfo_file_local}" "${_remote_user}@${_remote_ip}:${_songinfo_file_remote}"
}
 
function printtaginfo() {
	_file=${1}
    _waitforkey=${2} #Do we need to wait until a keystroke?
 
  case $(echo "${_file}" | egrep -o '\.ogg$|\.mp3$|\.flac$|\.wav$|http:') in
    http:) #Probably a stream
        echo "${_file}"
        _in_suffix="Unknown file type."
        ;;
    .ogg) #Ogg file
		ogginfo "${_file}"
		;;
    .mp3) #MP3 file
		id3info "${_file}"
		;;
    .flac) #Flac file
		#echo "No program set for flac info... ."
		#at least print dir/filename
		echo "${_file}"
	;;
    .wav) #wav file
		#at least print dir/filename
		echo "${_file}"
	;;
    *) #anything different
		_in_suffix="Unknown file type."
		;;
  esac
 
  if [ "${_waitforkey}" == "1" ]; then 
      read _wait
  fi      
}
 
function addtoarch() {
      local _file="${1}"
      #Add the current file to default Music.zip archive.
      #Wir gehen erst ins Verzeichnis rein und nehmen den Dateinamen ohne Pfad,
      # damit am Ende nicht der volle Pfad der Datei im Archiv steht; todo, dafuer gibt es mit Sicherheit eine Option.
      m_sendtoarch_file=$(basename "${_file}")
      m_sendtoarch_path=$(dirname "${_file}")
      cd "${m_sendtoarch_path}" && zip -o "${M_SENDTOARCH_ARCHIVE}" -r "${m_sendtoarch_file}"
      #title="Music On Console - SendToArch"
      printf "SendToArch\nAdded \"${m_sendtoarch_file}\" to SendToArch\n"
      sleep ${MESSAGE_TIME}
      clear
}
 
#Reads current directories from ${MUSIC_FREE} and creates a selection menu.
#$0 can be free|unfree
function getcats() {
    _count=0
    for _cat in $(ls -D "${MUSIC_FREE}") #List only directories. #Does not work with spaces in dirnames.
    do
	    M__cats_free[$_count]="${_cat}"
	    _count=$(($_count+1))
    done
 
    printf "Music_Free\nChoose a destiny folder or press [c] to create a new one or [Enter] to leave:\n"
    _count=0
    for _cat_free in ${M__cats_free[@]} #M__cats_free is an indexed array.
    do
	  printf "%i - %s\n" $_count "${_cat_free}"
	  _count=$(($_count+1))
    done
    printf "\n> "
}
 
function move_item() {
    #$3 kann auch ein Verzeichnis sein
    local _dest_folder="${1}" #Zielverzeichnis
    local _subtarget="${2}"   #Subtarget (Classic, Electro, ...)
    local _file="${3}"        #kompletter Pfad zur Datei mit Dateinamen der aktuellen Datei
    local _operation="mv"     #Operation; bisher nur mv
 
    local _destpath="${_dest_folder}/${_subtarget}" #kompletter Pfad für neue Datei + Dateiname
    local _filename=$(basename "${_file}") #Dateiname ohne Pfad
 
    ${_operation} "${_file}" "${_destpath}" #Move/Copy the file.
    if [ $? == 0  ];
    then #Exitlevel 0, operation was successfull
	printf "\"%s\"\nmoved successfully to:\n\"%s\"" "${_filename}" "${_dest_folder}/${_filename}"
	sleep ${MESSAGE_TIME}
	clear
    else
	printf "Failed to move\n\"%s\" to\n\"%s\"" "${_filename}" "${_dest_folder}/${_filename}"
	sleep ${MESSAGE_TIME}
	clear
    fi
}
 
function main() {
    case ${2} in #WHAT_TO_DO
      automaticcats) #This is an interactive selection with possibility to create a new category.
	  clear
	  SUBTARGET=""
	  _selection="_"
	  getcats
	  read _selection
	  while [ "${_selection}" == "c" ]
	  do
		printf "You decided to add a new category; Enter the directory name for your new category:\n> "
		read _catname
		mkdir "${MUSIC_FREE}/${_catname}"
		getcats
		read _selection
 
	  done
	  if [ ! -z "${_selection}" ]; then #We need this because with an zero _selection value bash would use 0 for ${M__cats_free[$_selection]}
	      #If given any number
	      echo "Sel: $_selection"
	      DST_FOLD="${MUSIC_FREE}"
	      SUBTARGET=${M__cats_free[$_selection]}
	      echo "subtarget: "
	      echo "subtargarray: ${M__cats_free[$_selection]}"
	      read #waiting for the user ... :P
	      move_item "${DST_FOLD}" "${SUBTARGET}" "${M_FILE}"
	      clear
	  else
	      printf "Not given any number. [Press Enter to exit]"
	      read
	      clear
	      exit 0
	  fi
	  ;;
      selection) #This is an interactive selection with extended possibilities.
	  clear
	  cat<<EOF
Current item is:
"${M_FILE}"
 
====Publish Music====
8 - Send to Archive (${M_SENDTOARCH_ARCHIVE})
 
====RADIO====
r - Choose a favorite radio streams ... 
 
====Free Music Charts====
fmc - Add Free Music Charts Playlist to current Playlist
d - Download current song to "${FREE_MUSIC_CHARTS_DEST}"
 
====RATING====
sr - Set rating
gr - Get rating
pb - Generate playlist with best rated songs (ASC)
 
====Feed Ices====
fil    - FeedIces this file to the equeue (Feed Ices later)
 
====Information====
t - Show tag information (id3info, ogginfo, whatever)
 
====Jamendo====
jn - Search for next Album ID and load m3u. (Jamendo Next)
jo - Open current album site in browser. (Jamendo Open)
ji - Display current Album ID. (Jamendo ID)
jd - Open download page.
 
==Jamendo (from start, ~/.lvurl_from_start)==
jsn - Search for next Album ID and load m3u. (Jamendo Next)
jso - Open current album site in browser. (Jamendo Open)
jsi - Display current Album ID. (Jamendo ID)
jsd - Open download page.
 
==Songinfo==
psi  - Push Songinfo to webserver.
 
Choose or press ENTER to continue...
EOF
	  echo -en "\033[45;5m>\033[0m "
	  read __type
	  case ${__type} in
	    psi)
			pushsonginformation "${M_FILE}"
			exit 0
	      ;;
		fmc)
		  FMCPL="/tmp/fmcplay.list"
		  wget https://www.archive.org/download/freemusiccharts.songs/fmc.xml -O "${FMCPL}"
		  for song in $(cat "${FMCPL}" | grep -e "<url>.*</url>" | sed -e 's#</*url>##g' ); do ${MOCP} -a "$song"; done & #im Hintergrund, da mocp sonst nicht laeuft :P
		  ;;
		d) #Download song from FreeMusicCharts
		  cd "${FREE_MUSIC_CHARTS_DEST}" && wget "${M_FILE}"
		  ;;
		pb) #Playlist Best (external script)
		  m3u="$(${RATESCRIPT} --playlist1)"
		  #muss im Hintergrund laufen, da es sonst nie weitergeht weil ja mocp schon laeuft :P
		  ${MOCP} --off shuffle & #wir wollen ja oben anfangen :)
		  ${MOCP} -a "${m3u}" &
		  ${MOCP} -p &
		  exit 0
		  ;;
		sr) #set rating
		  printf "Enter rating for this file (0-50): "
		  read _rating
		  ${RATESCRIPT} --setratingbypath "${M_FILE}" "${_rating}"
		  exit 0
		  ;;
		gr) #get rating
		  printf "Your previous rating for this file was: "
		  ${RATESCRIPT} --getratingbypath "${M_FILE}"
		  read _lala
		  exit 0
		  ;;
		r) #Show streamlist (external script)
		  "${STREAMSCRIPT}" --showlist
		  exit 0
		  ;;
		8) #Copy file to archive to send it.
		  addtoarch "${M_FILE}"
		  exit 0
		  ;;
		fil) #Add a file to equeue of feedices
		  /home/apps/scripts/feed_ices.sh addtoequeue "${M_FILE}"
		  exit 0
		  ;;
		t)
                  printtaginfo "${M_FILE}" 1
                  exit 0
		  ;;
		jn) #Jamendo Next ID
                  /home/apps/scripts/jamendo_listen.sh -snlm moc
                  exit 0
		  ;;
		jo) #Open Jamendo Album Page.
                  /home/apps/scripts/jamendo_listen.sh -o
                  exit 0
		  ;;
		ji) #Print Jamendo ID
                  /home/apps/scripts/jamendo_listen.sh -plv
                  exit 0
		  ;;
		jd) #Open download page.
                  /home/apps/scripts/jamendo_listen.sh -s -d
                  exit 0
		  ;;
		jsn) #Jamendo Next ID
                  /home/apps/scripts/jamendo_listen.sh -lvf /home/username/.lvurl_from_start -snlm moc
                  exit 0
		  ;;
		jso) #Open Jamendo Album Page.
                  /home/apps/scripts/jamendo_listen.sh -lvf /home/username/.lvurl_from_start -o
                  exit 0
		  ;;
		jsi) #Print Jamendo ID
                  /home/apps/scripts/jamendo_listen.sh -lvf /home/username/.lvurl_from_start -plv
                  exit 0
		  ;;
		jsd) #Open download page.
                  /home/apps/scripts/jamendo_listen.sh -lvf /home/username/.lvurl_from_start -s -d
                  exit 0
		  ;;
		*)
		  echo "No valid choice. Bye :)"
		  exit 0
		  ;;
	  esac
	  ;;
      delete)
	  #delete (internally move to badmusic directory)
	  move_item "${M_DST_DELETE}" "${SUBTARGET}" "${M_FILE}"
	  ;;
      help)
	  clear
	  echo -e "\033[45;5mMusic on Console - Help\033[0m "
	  cat <<EOF
  F1  - Search next Album ID on Jamendo and load m3u to playlist.
  F2  - Search next Album ID on Jamendo and load m3u to playlist (Session from start).
 
  F4  - FeedIces-Script (external script)
 
  F5  - Extended Menu
 
  F6  - Move to Category or create a new one (only free Music).
  F8  - Delete current Folder/File (... just move it to badmusic folder :P)
 
  F10 - This Help
 
----------------------------------------------------
$0
Version: ${VERSION}
${LASTEDIT} by ${AUTHOR} - ${EMAIL}"
 
EOF
	  echo "Press Enter to continue..."
	  read
	  exit 0
	  ;;
    esac
}
 
main "${@}"
linux/scripte/moc/moc_extend.txt · Zuletzt geändert: 2015/11/26 18:58 von Natenom