Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use regex for extracting gmusic id from URL

  • Loading branch information...
commit 48db862e82eb6c5c38a9d304257c73f878576f4f 1 parent 9f4ff43
@crabmanX authored
Showing with 20 additions and 13 deletions.
  1. +20 −13 gmusic_resolver/gmusic_resolver.py
View
33 gmusic_resolver/gmusic_resolver.py
@@ -58,19 +58,26 @@
api = gmusicapi.Api()
class getHandler(BaseHTTPRequestHandler):
- def do_GET(self):
- id = self.path[1:]
- logger.debug("forwarding stream for id: %s"%id)
- global api
- try:
- url = api.get_stream_url(id)
- self.send_response(301)
- self.send_header('Location', url)
- self.end_headers()
- except:
- logger.exception("URL retrieval for id %s failed"%id)
- self.send_response(404)
- self.end_headers()
+ def do_GET(self):
+ pattern = re.compile(r'/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})')
+ reg = re.search(pattern, self.path)
+ if not reg:
+ logger.exception('invalid id requested: %s'%self.path)
+ self.send_response(404)
+ self.end_headers()
+
+ id = reg.group(1)
+ logger.debug("forwarding stream for id: %s"%id)
+ global api
+ try:
+ url = api.get_stream_url(id)
+ self.send_response(301)
+ self.send_header('Location', url)
+ self.end_headers()
+ except:
+ logger.exception("URL retrieval for id %s failed"%id)
+ self.send_response(404)
+ self.end_headers()
def serveOnPort(port):
Please sign in to comment.
Something went wrong with that request. Please try again.