aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2021-09-02 03:09:03 +0000
committerMike Crute <mike@crute.us>2021-09-02 03:09:03 +0000
commit4337fd79a6a70ff833c71167d787d3dd12f5d012 (patch)
tree44cbaaf5af8036f0f172d7a193e7bd0c2dd33cd0
parent816c7e47942c15b0ca35276fad8d23d33100798e (diff)
downloadpydora-4337fd79a6a70ff833c71167d787d3dd12f5d012.tar.bz2
pydora-4337fd79a6a70ff833c71167d787d3dd12f5d012.tar.xz
pydora-4337fd79a6a70ff833c71167d787d3dd12f5d012.zip
Config file format and location change
-rw-r--r--pydora/configure.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/pydora/configure.py b/pydora/configure.py
index 1124746..c1f69ae 100644
--- a/pydora/configure.py
+++ b/pydora/configure.py
@@ -32,13 +32,20 @@ class PandoraKeysConfigParser:
32 """ 32 """
33 33
34 KEYS_URL = ( 34 KEYS_URL = (
35 "http://6xq.net/git/lars/pandora-apidoc.git/plain/json/partners.rst" 35 "https://6xq.net/git/lars/pandora-apidoc.git/plain/json/partners.rst"
36 ) 36 )
37 37
38 FIELD_RE = re.compile( 38 FIELD_RE = re.compile(
39 ":(?P<key>[^:]+): (?:`{2})?(?P<value>[^`\n]+)(?:`{2})?$" 39 ":(?P<key>[^:]+): (?:`{2})?(?P<value>[^`\n]+)(?:`{2})?$"
40 ) 40 )
41 41
42 DEFAULT_TUNER = "tuner.pandora.com"
43
44 TUNERS = {
45 "desktop_air_widget": "internal-tuner.pandora.com",
46 "vista_widget": "internal-tuner.pandora.com",
47 }
48
42 def _fixup_key(self, key): 49 def _fixup_key(self, key):
43 key = key.lower() 50 key = key.lower()
44 51
@@ -51,7 +58,8 @@ class PandoraKeysConfigParser:
51 else: 58 else:
52 return key 59 return key
53 60
54 def _format_api_host(self, host): 61 def _get_api_url(self, host):
62 host = self.TUNERS.get(host, self.DEFAULT_TUNER)
55 return "{}/services/json/".format(host) 63 return "{}/services/json/".format(host)
56 64
57 def _clean_device_name(self, name): 65 def _clean_device_name(self, name):
@@ -69,28 +77,23 @@ class PandoraKeysConfigParser:
69 else: 77 else:
70 return None 78 return None
71 79
72 def _is_host_terminator(self, line):
73 return line.startswith("--")
74
75 def _is_device_terminator(self, line): 80 def _is_device_terminator(self, line):
76 return line.startswith("^^") 81 # Old android credential is delineated by an "Old:" line
82 return line.startswith("^^") or line == "Old:"
77 83
78 def load(self): 84 def load(self):
79 buffer = [] 85 buffer = []
80 current_partner = {} 86 current_partner = {}
81 api_host = None
82 partners = {} 87 partners = {}
83 88
84 for line in self._fetch_config(): 89 for line in self._fetch_config():
85 key_match = self._match_key(line) 90 key_match = self._match_key(line)
86 if key_match: 91 if key_match:
87 current_partner[key_match["key"]] = key_match["value"] 92 current_partner[key_match["key"]] = key_match["value"]
88 elif self._is_host_terminator(line):
89 api_host = buffer.pop()
90 elif self._is_device_terminator(line): 93 elif self._is_device_terminator(line):
91 key = self._clean_device_name(buffer.pop()) 94 key = self._clean_device_name(buffer.pop())
92 current_partner = partners[key] = { 95 current_partner = partners[key] = {
93 "api_host": self._format_api_host(api_host) 96 "api_host": self._get_api_url(key)
94 } 97 }
95 98
96 buffer.append(line.strip().lower()) 99 buffer.append(line.strip().lower())