Exemplo n.º 1
0
 def _parse_query(self, values, suffix):
     # type: (MultiDict, str) -> Union[TrackLookupQuery, FingerprintLookupQuery]
     index = int(suffix[1:]) if suffix else None
     track_gid = values.get('trackid' + suffix)
     if track_gid:
         if not is_uuid(track_gid):
             raise errors.InvalidUUIDError('trackid' + suffix)
         return TrackLookupQuery(index=index, track_gid=track_gid)
     else:
         duration = values.get(self.duration_name + suffix,
                               type=int,
                               default=0)
         if not duration:
             raise errors.MissingParameterError(self.duration_name + suffix)
         fingerprint_string = values.get('fingerprint' + suffix)
         if not fingerprint_string:
             raise errors.MissingParameterError('fingerprint' + suffix)
         fingerprint = decode_fingerprint(
             fingerprint_string.encode('ascii', 'ignore'))
         if not fingerprint:
             logger.info('Got invalid fingerprint %r', fingerprint_string)
             raise errors.InvalidFingerprintError()
         return FingerprintLookupQuery(index=index,
                                       duration=duration,
                                       fingerprint=fingerprint)
Exemplo n.º 2
0
 def _parse_submission(self, values, suffix):
     # type: (MultiDict, str) -> None
     p = {}  # type: Dict[str, Any]
     p['index'] = (suffix or '')[1:]
     p['puid'] = values.get('puid' + suffix)
     if p['puid'] and not is_uuid(p['puid']):
         raise errors.InvalidUUIDError('puid' + suffix)
     p['foreignid'] = values.get('foreignid' + suffix)
     if p['foreignid'] and not is_foreignid(p['foreignid']):
         raise errors.InvalidForeignIDError('foreignid' + suffix)
     p['mbids'] = values.getlist('mbid' + suffix)
     if p['mbids'] and not all(map(is_uuid, p['mbids'])):
         raise errors.InvalidUUIDError('mbid' + suffix)
     self._parse_duration_and_format(p, values, suffix)
     fingerprint_string = values.get('fingerprint' + suffix)
     if not fingerprint_string:
         raise errors.MissingParameterError('fingerprint' + suffix)
     p['fingerprint'] = decode_fingerprint(
         fingerprint_string.encode('ascii', 'ignore'))
     if not p['fingerprint']:
         logger.info('Got invalid fingerprint %r', fingerprint_string)
         raise errors.InvalidFingerprintError()
     p['bitrate'] = values.get('bitrate' + suffix, type=int) or None
     if p['bitrate'] is not None and p['bitrate'] <= 0:
         raise errors.InvalidBitrateError('bitrate' + suffix)
     p['track'] = values.get('track' + suffix)
     p['artist'] = values.get('artist' + suffix)
     p['album'] = values.get('album' + suffix)
     p['album_artist'] = values.get('albumartist' + suffix)
     p['track_no'] = values.get('trackno' + suffix, type=int)
     p['disc_no'] = values.get('discno' + suffix, type=int)
     p['year'] = values.get('year' + suffix, type=int)
     self.submissions.append(p)
Exemplo n.º 3
0
 def _parse_submission(self, values, suffix):
     p = {}
     p['puid'] = values.get('puid' + suffix)
     if p['puid'] and not is_uuid(p['puid']):
         raise errors.InvalidUUIDError('puid' + suffix)
     p['foreignid'] = values.get('foreignid' + suffix)
     if p['foreignid'] and not is_foreignid(p['foreignid']):
         raise errors.InvalidForeignIDError('foreignid' + suffix)
     p['mbids'] = values.getlist('mbid' + suffix)
     if p['mbids'] and not all(map(is_uuid, p['mbids'])):
         raise errors.InvalidUUIDError('mbid' + suffix)
     self._parse_duration_and_format(p, values, suffix)
     fingerprint_string = values.get('fingerprint' + suffix)
     if not fingerprint_string:
         raise errors.MissingParameterError('fingerprint' + suffix)
     p['fingerprint'] = decode_fingerprint(fingerprint_string)
     if not p['fingerprint']:
         raise errors.InvalidFingerprintError()
     p['bitrate'] = values.get('bitrate' + suffix, type=int) or None
     if p['bitrate'] is not None and p['bitrate'] <= 0:
         raise errors.InvalidBitrateError('bitrate' + suffix)
     p['track'] = values.get('track' + suffix)
     p['artist'] = values.get('artist' + suffix)
     p['album'] = values.get('album' + suffix)
     p['album_artist'] = values.get('albumartist' + suffix)
     p['track_no'] = values.get('trackno' + suffix, type=int)
     p['disc_no'] = values.get('discno' + suffix, type=int)
     p['year'] = values.get('year' + suffix, type=int)
     self.submissions.append(p)
Exemplo n.º 4
0
 def _parse_submission(self, values, suffix):
     p = {}
     p["puid"] = values.get("puid" + suffix)
     if p["puid"] and not is_uuid(p["puid"]):
         raise errors.InvalidUUIDError("puid" + suffix)
     p["foreignid"] = values.get("foreignid" + suffix)
     if p["foreignid"] and not is_foreignid(p["foreignid"]):
         raise errors.InvalidForeignIDError("foreignid" + suffix)
     p["mbids"] = values.getlist("mbid" + suffix)
     if p["mbids"] and not all(map(is_uuid, p["mbids"])):
         raise errors.InvalidUUIDError("mbid" + suffix)
     self._parse_duration_and_format(p, values, suffix)
     fingerprint_string = values.get("fingerprint" + suffix)
     if not fingerprint_string:
         raise errors.MissingParameterError("fingerprint" + suffix)
     p["fingerprint"] = decode_fingerprint(fingerprint_string)
     if not p["fingerprint"]:
         raise errors.InvalidFingerprintError()
     p["bitrate"] = values.get("bitrate" + suffix, type=int) or None
     if p["bitrate"] is not None and p["bitrate"] <= 0:
         raise errors.InvalidBitrateError("bitrate" + suffix)
     p["track"] = values.get("track" + suffix)
     p["artist"] = values.get("artist" + suffix)
     p["album"] = values.get("album" + suffix)
     p["album_artist"] = values.get("albumartist" + suffix)
     p["track_no"] = values.get("trackno" + suffix, type=int)
     p["disc_no"] = values.get("discno" + suffix, type=int)
     p["year"] = values.get("year" + suffix, type=int)
     self.submissions.append(p)
Exemplo n.º 5
0
 def parse(self, values, conn):
     super(LookupHandlerParams, self).parse(values, conn)
     self._parse_client(values, conn)
     self.meta = values.get('meta', type=int)
     self.duration = values.get('duration', type=int)
     if not self.duration:
         raise errors.MissingParameterError('duration')
     fingerprint_string = values.get('fingerprint')
     if not fingerprint_string:
         raise errors.MissingParameterError('fingerprint')
     self.fingerprint = decode_fingerprint(fingerprint_string)
     if not self.fingerprint:
         raise errors.InvalidFingerprintError()
Exemplo n.º 6
0
 def _parse_submission(self, values, suffix):
     p = {}
     p['puid'] = values.get('puid' + suffix)
     if p['puid'] and not is_uuid(p['puid']):
         raise errors.InvalidUUIDError('puid' + suffix)
     p['mbids'] = values.getlist('mbid' + suffix)
     if p['mbids'] and not all(map(is_uuid, p['mbids'])):
         raise errors.InvalidUUIDError('mbid' + suffix)
     self._parse_duration_and_format(p, values, suffix)
     fingerprint_string = values.get('fingerprint' + suffix)
     if not fingerprint_string:
         raise errors.MissingParameterError('fingerprint' + suffix)
     p['fingerprint'] = decode_fingerprint(fingerprint_string)
     if not p['fingerprint']:
         raise errors.InvalidFingerprintError()
     p['bitrate'] = values.get('bitrate' + suffix, type=int)
     self.submissions.append(p)
Exemplo n.º 7
0
 def _parse_query(self, values, suffix):
     p = {}
     p['index'] = (suffix or '')[1:]
     p['track_gid'] = values.get('trackid' + suffix)
     if p['track_gid'] and not is_uuid(p['track_gid']):
         raise errors.InvalidUUIDError('trackid' + suffix)
     if not p['track_gid']:
         p['duration'] = values.get(self.duration_name + suffix, type=int)
         if not p['duration']:
             raise errors.MissingParameterError(self.duration_name + suffix)
         fingerprint_string = values.get('fingerprint' + suffix)
         if not fingerprint_string:
             raise errors.MissingParameterError('fingerprint' + suffix)
         p['fingerprint'] = decode_fingerprint(fingerprint_string)
         if not p['fingerprint']:
             raise errors.InvalidFingerprintError()
     self.fingerprints.append(p)
Exemplo n.º 8
0
 def _parse_query(self, values, suffix):
     p = {}
     p["index"] = (suffix or "")[1:]
     p["track_gid"] = values.get("trackid" + suffix)
     if p["track_gid"] and not is_uuid(p["track_gid"]):
         raise errors.InvalidUUIDError("trackid" + suffix)
     if not p["track_gid"]:
         p["duration"] = values.get(self.duration_name + suffix, type=int)
         if not p["duration"]:
             raise errors.MissingParameterError(self.duration_name + suffix)
         fingerprint_string = values.get("fingerprint" + suffix)
         if not fingerprint_string:
             raise errors.MissingParameterError("fingerprint" + suffix)
         p["fingerprint"] = decode_fingerprint(fingerprint_string)
         if not p["fingerprint"]:
             raise errors.InvalidFingerprintError()
     self.fingerprints.append(p)
Exemplo n.º 9
0
 def _parse_query(self, values, suffix):
     p = {}
     p['index'] = (suffix or '')[1:]
     p['track_gid'] = values.get('trackid' + suffix)
     if p['track_gid'] and not is_uuid(p['track_gid']):
         raise errors.InvalidUUIDError('trackid' + suffix)
     if not p['track_gid']:
         p['duration'] = values.get(self.duration_name + suffix, type=int)
         if not p['duration']:
             raise errors.MissingParameterError(self.duration_name + suffix)
         fingerprint_string = values.get('fingerprint' + suffix)
         if not fingerprint_string:
             raise errors.MissingParameterError('fingerprint' + suffix)
         p['fingerprint'] = decode_fingerprint(
             fingerprint_string.encode('ascii', 'ignore'))
         if not p['fingerprint']:
             raise errors.InvalidFingerprintError()
     self.fingerprints.append(p)