#!/bin/bash # # Get playlist files using git-annex. # # Parameters BASENAME="`basename $0`" PLAYLIST="$1" DEST="$2" MEDIA="/var/cache/media/noise" PLAYLISTS="$MEDIA/playlists" APP="git annex" # Basic syntax if [ -z "$PLAYLIST" ]; then echo "Usage: $BASENAME [dest]" if [ -d "$PLAYLISTS" ]; then echo "" echo "Available playlists: " ls $PLAYLISTS fi echo "Examples:" echo "" echo "$BASENAME ambient adb" echo "$BASENAME groove /media/usb" echo "$BASENAME funk remote-repository" exit 1 elif [ ! -f "$PLAYLISTS/$PLAYLIST.m3u" ]; then echo "No such playlist $PLAYLISTS/$PLAYLIST.m3u" exit 1 fi # Set action if [ "$BASENAME" == "playlist-drop" ]; then action="drop" elif [ "$BASENAME" == "playlist-copy" ]; then if [ -z "$DEST" ]; then echo "No destination specified" exit 1 elif [ -d "$DEST" ]; then APP="cp -Lv" action="" # Force absolute path DEST="`cd $DEST && pwd`" elif [ "$DEST" == "adb" ]; then APP="adb" action="push" #DEST="/storage/emulated/0/Music" DEST="/sdcard/Music" else DEST="--to $DEST" action="copy" fi else action="get" fi # Start echo "Getting files from $PLAYLISTS/$PLAYLIST.m3u..." cd $MEDIA # Process cat $PLAYLISTS/$PLAYLIST.m3u | while read file; do if [ -z "$action" ] && [ "$APP" == "cp -Lv" ]; then prefix="/$(dirname "$file")" mkdir -p "$DEST$prefix" $APP $action "$file" "$DEST$prefix" elif [ "$action" == "get" ]; then $APP $action "$file" elif [ "$APP" == "adb" ]; then prefix="/$(dirname "$file")" echo mkdir -p \"$DEST$prefix\" | adb shell $APP $action "$file" "$DEST$prefix" else $APP $action "$file" $DEST fi done # Additional procedures if [ "$action" != "get" ]; then # Copy the playlist to the destination $APP $action "$PLAYLISTS/$PLAYLIST.m3u" $DEST/$PLAYLIST.m3u # Refresh file list at the destination if [ "$APP" == "adb" ]; then # Thanks https://stackoverflow.com/questions/17928576/refresh-android-mediastore-using-adb echo "Updating file list at the destination..." adb shell "find $DEST -exec am broadcast \ -a android.intent.action.MEDIA_SCANNER_SCAN_FILE \ -d file://{} \\;" fi fi