I finally taught myself how to get at source codes. At first I thought I had to figure out git, but then I stumbled upon this:
Code:
sudo apt-get build-deb libmtp
sudo apt-get source libmtp
Once I realized where the source was put (current directory), I soon found the original C files of the mtp-tools. After some selective commenting-out and minimizing of printf() commands, I navigated to the root folder of the source package and compiled:
Code:
./configure
make
make install
I now have a unique build of the mtp-tools that output exactly what I want. I went ahead and tried out my own scripts (posted here in case anyone else want to try and do something like this):
/home/cerapter/scripts/playlist_main.sh:
Code:
#!/bin/bash
ind_music=87
ind_max=500
pFile=$(zenity --file-selection --filename="/home/cerapter/Downloads/" --title="Choose your CSV playlist")
if [ $? != 1 ]; then
pName=$(zenity --entry --title="Playlist name" --text="Enter the name of the playlist (0 for guess)" --entry-text "0")
# apparently doesn't work
if [ $? -eq 1 ]; then
pName="Blubb gakk"
fi
today=$(date +%m.%d)
gFolder="${today} ${pName}"
echo "Executing: mtp-newfolder \"${gFolder}\" ${ind_music} 0"
# don't need folder ID, but get it anyway
ind_folder=$(mtp-newfolder "${gFolder}" ${ind_music} 0)
wait ${!}
echo "Created folder with ID ${ind_folder}"
arg_accum=""
for (( c=0; c<=ind_max; c++ ))
do
pArgs=$(python /home/cerapter/scripts/playlist_transfer.py "${pFile}" "${pName}" "${gFolder}" $c)
command="mtp-sendtr ${pArgs}"
if [ "$pArgs" == "STOP" ]; then
echo "Reached end of CSV list."
break
fi
echo "Executing: 'mtp-sendtr ${pArgs}'"
# get track IDs!
ind_track=$(eval $command)
wait ${!}
echo "Sent track to track ID ${ind_track}"
arg_accum="${arg_accum} -i ${ind_track}"
done
echo "Executing: mtp-newplaylist -n \"${pName}\" ${arg_accum}"
# and then get playlist ID (don't need this either)
ind_list=$(mtp-newplaylist -n "${pName}" $arg_accum)
wait ${!}
echo "Made playlist with ID ${ind_list}"
fi
/home/cerapter/scripts/playlist_transfer.py:
Code:
#!/usr/bin/python
import string, csv, sys
# from bash script:
playlist_file = str(sys.argv[1])
playlist_name = str(sys.argv[2])
gFolder = str(sys.argv[3])
counter = int(sys.argv[4])
# get music player directory
path = "/Music/" + gFolder + "/"
# get the current line of the CSV
fList = csv.DictReader(open(playlist_file, 'r'))
fList = list(fList)
# if last line is reached, say STOP!
try:
row = fList[counter]
# use the data from this line
fPath = row['Folder'] + "/" + row['Filename']
gPath = path + row['Filename']
# build the mtp-sendtr command
lTrack = '-q -t "'+row['Title']+'"'
lTrack = lTrack + ' -a "'+row['Artist']+'"'
lTrack = lTrack + ' -l "'+row['Album']+'"'
lTrack = lTrack + ' -g "'+row['Genres']+'"'
lTrack = lTrack + ' -n '+row['Track']
lTrack = lTrack + ' -y '+row['Year']
lTrack = lTrack + ' -d '+row['Length']
lTrack = lTrack + ' -s 0 "'+fPath+'" "'+gPath+'"'
#oTrack.wavecodec =
print lTrack
except IndexError:
print 'STOP'
I have not yet succeeded. I get this error output after calling a command that should work, and which works if I run it by itself manually afterwards:
Code:
Executing: mtp-sendtr -q -t "Chronologie Part.4" -a "Jean Michel Jarre" -l "Chronologie" -g "New Age" -n 4 -y 1993 -d 239 -s 0 "/home/cerapter/Musikk/Artister/Jean Michel Jarre - Chronologie Part.4.mp3" "/Music/07.23 Snupp tupp/Jean Michel Jarre - Chronologie Part.4.mp3"
Device 0 (VID=041e and PID=4162) is a Creative ZEN X-Fi.
usage: sendtr [ -D debuglvl ] [ -q ]
-t <title> -a <artist> -A <Album artist> -w <writer or composer>
-l <album> -c <codec> -g <genre> -n <track number> -y <year>
-d <duration in seconds> -s <storage_id> <local path> <remote path>
(-q means the program will not ask for missing information.)
I'm now going to look into the C files again to trace back and troubleshoot this error. It does take a while, since between each attempt I have to wake up, unmount and clean up the player..
EDIT: Script works now, updated code.
Bookmarks