diff --git a/splimport/decode.py b/splimport/decode.py index 589c258..82c38f4 100644 --- a/splimport/decode.py +++ b/splimport/decode.py @@ -1,4 +1,8 @@ +import os +import sys import struct +import requests + from apev2 import Apev2 # apev2 spec: https://wiki.hydrogenaud.io/index.php?title=APEv2_specification @@ -14,14 +18,34 @@ def swap32(i): return struct.unpack("I", i))[0] -ape = Apev2.from_file('OMYG.apetag') +ignore_tags = [ + "Energy", "Gender", "HookLen", "HookStart", "Rating", "Tempo", "Intro", "Outro", "CueDB", "CueOverlap", + "SegueDB", "Cue", "FadeSpeed", "RecordDate", "Duration", "Segue", "REPLAYGAIN_TRACK_GAIN", "Genre", "Category", + "XLastScheduled", "EAN/UPC", "Comment", "Record Date", "XEndDate", "XRestrictions" +] +query_params = {} + +if len(sys.argv) <= 1: + sys.exit("no argument passed") +else: + tagpath = sys.argv[1] + +# ape = Apev2.from_file('OMYG.apetag') +# ape = Apev2.from_file('MULE DRIVER - Snorer.apetag') + +ape = Apev2.from_file(tagpath) + +time_list = [] +date_list = [] for item in ape.tag.frames: key = item.item_key value = item.item_value # print(key, value) - if key == 'XLastPlayed': + if key in ignore_tags: + pass + elif key == 'XLastPlayed': hex = value.hex() for i in range(0, len(hex), 8): @@ -29,4 +53,44 @@ for item in ape.tag.frames: d=swap32(int(hex_chunk, 16)) Y,M,D,h,m,s = 1980+(d>>25), (d>>21)&0xf, (d>>16)&0x1f, (d>>11)&0x1f, (d>>5)&0x3f, (d<<1)&0x3f - print(Y,M,D,h,m,s) + + if Y == 1980: + continue + + # print(Y,M,D,h,m,s) + + time_list.append("{}:{}:{}".format(h, m, s)) + date_list.append("{}/{}/{}".format(M, D, Y)) + elif key == "Other": + query_params["country"] = value.decode() + elif key == "Year": + query_params["year"] = value.decode() + elif key == "Title": + query_params["track_name"] = value.decode() + elif key == "Artist": + query_params["artist_name"] = value.decode() + elif key == "Publisher": + query_params["label"] = value.decode() + elif key == "Album": + query_params["release_name"] = value.decode() + elif key == "URL": + query_params["info_url"] = value.decode() + elif key == "URL2": + query_params["img_url"] = value.decode() + else: + print(key, value) + +i=0 +while i < len(time_list): + # print(time_list[i], date_list[i]) + query_params["time"] = time_list[i] + query_params["date"] = date_list[i] + # print(query_params) + + response = requests.get( + 'http://localhost:8082/spl/1', + params=query_params + ) + # print(response) + + i+=1 diff --git a/splimport/extracttags.sh b/splimport/extracttags.sh new file mode 100755 index 0000000..c64ee2d --- /dev/null +++ b/splimport/extracttags.sh @@ -0,0 +1,44 @@ +#!/usr/bin/bash + +SOURCEDIR=$1 +TARGETDIR=$2 + +if [ -z "$SOURCEDIR" ]; then + echo "no source dir set" + exit 1 +fi + +if [ -z "$TARGETDIR" ]; then + echo "creating dir for tags: apetags/" + mkdir apetags + TARGETDIR="apetags/" +fi + + +SAVEIFS=$IFS +IFS=$(echo -en "\n\b") + +for file in $(find $SOURCEDIR -iname "*.mp3" -o -iname "*.wav"); do + DIR=${file%/*} + NEWDIR=$TARGETDIR${DIR#$SOURCEDIR} + + if [ ! -f "$NEWDIR" ]; then + mkdir -p $NEWDIR + fi + + OLDFILE=${file##*/} + NEWFILE=${OLDFILE%.*}.apetag + + TARGETFILE=$NEWDIR/$NEWFILE + echo $TARGETFILE + + if [ -f "$TARGETFILE" ]; then + rm $TARGETFILE + fi + + ./apetag/apetag -i $file -file $TARGETFILE +done + +IFS=$SAVEIFS + +echo "apetags created in $TARGETDIR" diff --git a/splimport/importtags.sh b/splimport/importtags.sh new file mode 100755 index 0000000..80d7c96 --- /dev/null +++ b/splimport/importtags.sh @@ -0,0 +1,17 @@ +#!/usr/bin/bash + +SOURCEDIR=$1 + +if [ -z "$SOURCEDIR" ]; then + echo "no source dir set" + exit 1 +fi + +SAVEIFS=$IFS +IFS=$(echo -en "\n\b") +for tag in $(find $SOURCEDIR -iname "*.apetag"); do + echo $tag + python decode.py $tag +done +IFS=$SAVEIFS +