metadata

Check-in [a0023c3b13]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Tighten whitespace stripping. Test idle timeout.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:a0023c3b13b8bf305bfcc450c63cf1a55bf75822d4ca937b059d5142a3c91f4e
User & Date: vashon 2018-06-19 16:55:45
Context
2018-06-19
23:56
Get resumption after idle shut-off working. check-in: 61c081ac82 user: vashon tags: trunk
16:55
Tighten whitespace stripping. Test idle timeout. check-in: a0023c3b13 user: vashon tags: trunk
2018-06-18
23:53
Bringup; getting metadata from Radio Paradise out to clients check-in: 3d69813d77 user: vashon tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to stream.py.

8
9
10
11
12
13
14

15
16
17
18
19
20
21
...
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
...
207
208
209
210
211
212
213
214
215
216
217
218
219
220


221

222
223
224
225
226
227
228
Whitespace = string.whitespace + "\x00"

# How many seconds of non-use of a stream before we shut it down
IDLE=600.0

# HTTP headers to get Icecast metadata
Args = """Icy-Metadata: 1\r

User-Agent: mplayer-metadata\r
"""


# All the state for a given stream
class Stream(object):
    def __init__(self, sym, url):
................................................................................
	    except:
		return
	    if not c:
		sys.stderr.write("No metadata size byte\n")
		return
	    paksize = (ord(c) << 4)
	    if not paksize:
		sys.stderr.write(" no metadata update\n")
		continue

	    # No metadata update needed yet
	    if not paksize:
		continue
	    try:
		buf = s.recv(paksize)
	    except:
		return
	    if len(buf) != paksize:
		sys.stderr.write("metadata got %d\n" % (len(buf),))
		return
	    buf = buf.strip()

	    # Decode metadata into a dict for JSON purposes
	    sys.stderr.write(" metadata: %s\n" % (buf,))
	    res = {}
	    for p in buf.split(';'):
		p = p.strip(Whitespace)
		if not p:
		    continue
		if '=' not in p:
		    sys.stderr.write("Malformed %s from %s\n" %
			(p, self.host))
		    continue
		idx = p.index('=')
		k = p[:idx].strip()
		v = p[idx+1:].strip()
		if v[0] == "'":
		    v = v[1:]
		    if v[-1] == "'":
			v = v[:-1]
		res[k] = v
	    
	    if not res:
................................................................................
		continue

	    # Convert to a JSON string
	    res["err"] = None
	    res["gen"] = self.gen
	    self.gen += 1
	    self.json = json.dumps(res)
	    waiters = bool(self.waiters)
	    self.wakeups()

	    # Keep track of idleness
	    tm = time.time()
	    if waiters:
		self.idle = tm


	    elif (tm - self.idle) > IDLE:

		sys.stderr.write("idle reached for %s\n" % (self.host,))
		return

    # Our main worker is self.watch(), right above.  This wraps it,
    #  so that it can return here on network failure, and we can
    #  tear down this thread.
    def run_watch(self):







>







 







<












<













|
|







 







|






>
>
|
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
180
181
182

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
Whitespace = string.whitespace + "\x00"

# How many seconds of non-use of a stream before we shut it down
IDLE=600.0

# HTTP headers to get Icecast metadata
Args = """Icy-Metadata: 1\r
Access-Control-Allow-Origin: *\r
User-Agent: mplayer-metadata\r
"""


# All the state for a given stream
class Stream(object):
    def __init__(self, sym, url):
................................................................................
	    except:
		return
	    if not c:
		sys.stderr.write("No metadata size byte\n")
		return
	    paksize = (ord(c) << 4)
	    if not paksize:

		continue

	    # No metadata update needed yet
	    if not paksize:
		continue
	    try:
		buf = s.recv(paksize)
	    except:
		return
	    if len(buf) != paksize:
		sys.stderr.write("metadata got %d\n" % (len(buf),))
		return


	    # Decode metadata into a dict for JSON purposes
	    sys.stderr.write(" metadata: %s\n" % (buf,))
	    res = {}
	    for p in buf.split(';'):
		p = p.strip(Whitespace)
		if not p:
		    continue
		if '=' not in p:
		    sys.stderr.write("Malformed %s from %s\n" %
			(p, self.host))
		    continue
		idx = p.index('=')
		k = p[:idx].strip(Whitespace)
		v = p[idx+1:].strip(Whitespace)
		if v[0] == "'":
		    v = v[1:]
		    if v[-1] == "'":
			v = v[:-1]
		res[k] = v
	    
	    if not res:
................................................................................
		continue

	    # Convert to a JSON string
	    res["err"] = None
	    res["gen"] = self.gen
	    self.gen += 1
	    self.json = json.dumps(res)
	    waiters = len(self.waiters)
	    self.wakeups()

	    # Keep track of idleness
	    tm = time.time()
	    if waiters:
		self.idle = tm
		continue

	    tmid = tm - self.idle
	    if tmid > IDLE:
		sys.stderr.write("idle reached for %s\n" % (self.host,))
		return

    # Our main worker is self.watch(), right above.  This wraps it,
    #  so that it can return here on network failure, and we can
    #  tear down this thread.
    def run_watch(self):