-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtr.sh
executable file
·53 lines (41 loc) · 1.33 KB
/
mtr.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
ADBPATH="/Users/Thomas/Dropbox/ADB/"
LIBPATH="/Users/Thomas/Music/iTunes/iTunes Music Library.xml"
BGCPMAX=1
PLAYLISTNAME=$1
DEST="/sdcard/Music/$PLAYLISTNAME"
function getTrackIdList {
TRACKLISTSEDSTRING="/<key>Name<\/key><string>$PLAYLISTNAME/,/<\/array>/p"
cat "$LIBPATH" | sed -n $TRACKLISTSEDSTRING | grep '<key>Track ID</key>' | awk -F">|<" '{print $7}' | sort -n | uniq
}
function urldecode {
# Credits to Chris Down
# http:/cdown
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\x}"
echo ""
}
function getTrackLocation {
TRACKID=$1
TRACKIDSEDSTRING="/<\/key><integer>$TRACKID<\/integer>/,/<\/dict>/p"
urldecode `cat "$LIBPATH" | sed -n $TRACKIDSEDSTRING | grep '<key>Location</key><string>' | awk -F">|<" '{print $7}' | sed 's|file:\/\/localhost||g' | sed 's|\&|\&|g' | sed 's|+|%2B|'`
}
TRACKLIST=`getTrackIdList`
SINGLE=`echo $TRACKLIST | awk '{ print $3 }'`
"$ADBPATH"adb shell mkdir -p $DEST
for SINGLE in $TRACKLIST
do
FILE=`getTrackLocation $SINGLE`
BGCPCOUNT=`ps -ef | grep 'adb push' | grep -v grep | wc -l`
echo ''
echo $FILE | awk -F'/' '{ print $NF }'
if [ $BGCPCOUNT -lt $BGCPMAX ]
then
echo "in bg"
"$ADBPATH"adb push "$FILE" $DEST $OP 2> /dev/null &
else
echo "in fg"
"$ADBPATH"adb push "$FILE" $DEST $OP 2> /dev/null
fi
done
echo "$TRACKARR"