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)
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)
def parse(self, values, conn): super(TrackListByPUIDHandlerParams, self).parse(values, conn) self.puid = values.get('puid') if not self.puid: raise errors.MissingParameterError('puid') if not is_uuid(self.puid): raise errors.InvalidUUIDError('puid')
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)
def parse(self, values, conn): super(TrackListByMBIDHandlerParams, self).parse(values, conn) self.disabled = values.get('disabled', type=int) self.batch = values.get('batch', type=int) self.mbids = values.getlist('mbid') if not self.mbids: raise errors.MissingParameterError('mbid') if not all(map(is_uuid, self.mbids)): raise errors.InvalidUUIDError('mbid' + suffix)
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)