From fb382cbe3164dc809246756113057f3c4cd8008c Mon Sep 17 00:00:00 2001
From: Chris Pomeroy <chris.pomeroy@hotmail.com>
Date: Tue, 24 Oct 2017 02:19:28 +0000
Subject: [PATCH] Added the querysubsonic into this repo. Added a check to make sure we didn't already have the aax ablum in the library. This needs refinement as if the name isn't an exact match it won't work.
---
querysubsonic | 71 +++++++++++++++++++++++++++++++++++
aaxConvert.py | 48 +++++++++++++----------
2 files changed, 98 insertions(+), 21 deletions(-)
diff --git a/aaxConvert.py b/aaxConvert.py
index 3206fdb..9afe859 100755
--- a/aaxConvert.py
+++ b/aaxConvert.py
@@ -6,6 +6,7 @@
import shlex
import json
from getaaxkey.getaaxkey import getcorrectkey
+import querysubsonic
# arguments
# activation_key, file name, codec(default to mp3)
@@ -128,26 +129,31 @@
for rfile in glob.glob(args.filename):
if rfile.find("aax") != -1 and os.path.isfile(rfile):
- act_byte = getcorrectkey(rfile)
metadata = getmetadata(rfile)
album = getmetadatatags('album')
- artist = getmetadatatags('artist')
- title = getmetadatatags('title')
- ddir = "%s/%s/%s" % (path, artist, title)
- single_file_path = "%s/%s.mp3" % (ddir, title)
- if not os.path.exists(ddir):
- os.makedirs(ddir)
- print ddir
- reencode(rfile, single_file_path)
- if mode == 'chapter':
- chapter = 0
- numchapters = getchaptercount()
- while (numchapters > 0 ):
- cstart = getchaptermetadata(chapter, 'start_time')
- cend = getchaptermetadata(chapter, 'end_time')
- chapter += 1
- numchapters -= 1
- schap = str(chapter).zfill(2)
- movetochapters(single_file_path, ddir, schap, title, cstart,cend)
- os.remove(single_file_path)
- getcoverart(rfile, ddir)
\ No newline at end of file
+ #See if we got it already
+ if findalbumbyname(album):
+ return 0
+ else:
+ artist = getmetadatatags('artist')
+ title = getmetadatatags('title')
+ act_byte = getcorrectkey(rfile)
+ ddir = "%s/%s/%s" % (path, artist, title)
+ single_file_path = "%s/%s.mp3" % (ddir, title)
+ if not os.path.exists(ddir):
+ os.makedirs(ddir)
+ print ddir
+ reencode(rfile, single_file_path)
+ if mode == 'chapter':
+ chapter = 0
+ numchapters = getchaptercount()
+ while (numchapters > 0 ):
+ cstart = getchaptermetadata(chapter, 'start_time')
+ cend = getchaptermetadata(chapter, 'end_time')
+ chapter += 1
+ numchapters -= 1
+ schap = str(chapter).zfill(2)
+ movetochapters(single_file_path, ddir, schap, title, cstart,cend)
+ os.remove(single_file_path)
+ getcoverart(rfile, ddir)
+ updatelibrary('testuser','testpass')
\ No newline at end of file
diff --git a/querysubsonic b/querysubsonic
new file mode 100644
index 0000000..5b5e0fb
--- /dev/null
+++ b/querysubsonic
@@ -0,0 +1,71 @@
+#!/usr/bin/python
+
+## Eaxmple url
+## https://subsonic.darkurthe.net/audiobooks/rest/getMusicFolders.view?u=testuser&t=0733b8e9889d7a9986d82764cee9db1c&s=O5kgRb6X5jFFbPSW&v=1.15.0&c=myapp&f=json
+## https://subsonic.darkurthe.net/audiobooks/rest/search3.view?u=testuser&t=0733b8e9889d7a9986d82764cee9db1c&s=O5kgRb6X5jFFbPSW&c=myapp&f=json&v=1.15.0&query=album="Gypsy Morph"
+
+from hashlib import md5
+import random
+import requests
+
+
+def gensalt():
+ ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ chars = []
+ salt = ""
+ for i in range(16):
+ chars.append(random.choice(ALPHABET))
+ salt = ''.join(str(x) for x in chars )
+ return salt
+
+
+def gentoken(passwd,salt):
+ m = md5()
+ m.update(passwd + salt)
+ return m.hexdigest()
+
+
+def getalbumlist(user,passwd):
+ s = gensalt()
+ t = gentoken(passwd,s)
+ payload = {'u': user, 't': t, 's': s, 'c': 'audible', 'v': '1.15.0', 'f': 'json', 'type': 'alphabeticalByName', 'size': '500'}
+ r = requests.get('http://zombietc01.darkurthe.net:8080/audiobooks/rest/getAlbumList.view', payload, verify=False)
+ if r.status_code == 200:
+ jr = r.json()
+ return jr
+
+
+def findalbumbyname(album):
+ album = album.strip()
+ alj = getalbumlist('testuser', 'testpass')
+ for item in alj["subsonic-response"]["albumList"]["album"]:
+ sablum = str(item['album'])
+ sablum = sablum.strip()
+ if sablum.lower() == album.lower():
+ return True
+ return False
+
+
+def updatelibrary(user,passwd):
+ s = gensalt()
+ t = gentoken(passwd,s)
+ payload = {'u': user, 't': t, 's': s, 'c': 'audible', 'v': '1.15.0'}
+ r = requests.get('http://zombietc01.darkurthe.net:8080/audiobooks/rest/startScan.view', payload, verify=False)
+ if r.status_code == 200:
+ return True
+ else:
+ return False
+
+
+if __name__ == "__main__":
+ import sys
+ if len(sys.argv) >= 2:
+ args = sys.argv[1]
+ else:
+ print "I need an album name to lookup"
+ sys.exit(1)
+ out = findalbumbyname(str(sys.argv[1]))
+ if out == True:
+ print "Found: ",sys.argv[1]
+ else:
+ print sys.argv[1], "not found on subsonic server"
--
Gitblit v1.10.0