def add_artist(request, artist_name): what_client = get_what_client(request) response = what_client.request('artist', artistname=artist_name)['response'] added = 0 for group in response['torrentgroup']: if filter_group(response['name'], group): artist = html_unescape(response['name']) title = html_unescape(group['groupName']) release_type = group['releaseType'] for torrent in group['torrent']: id = torrent['id'] priority = filter_torrent(group, torrent) if priority and not is_existing(id): format = torrent['format'] encoding = torrent['encoding'] torrent_size = torrent['size'] queue_item = QueueItem( what_id=id, priority=priority, artist=artist, title=title, release_type=release_type, format=format, encoding=encoding, torrent_size=torrent_size ) queue_item.save() added += 1 return { 'success': True, 'added': added }
def add(request): item = QueueItem(text=request.POST["text"]) item.save() # Update cache -- have to hit DB. cache.set(QUEUE_KEY, db_get_queue()) # ....^.............^ # We may be tempted to use the `append` memcache method here instead of # retrieving the queue again. However, we are using pythons serialization of # the QueueItem data structure, so `append` would not nessecarily work. We # could use append though if we used our own serialization method. # return HttpResponse("%s" % item.text)
def add_collage(request, collage_id): what_client = get_what_client(request) response = what_client.request('collage', id=collage_id)['response'] added = 0 torrent_group_count = 0 torrent_count = 0 for group in response['torrentgroups']: if group['categoryId'] not in [1, '1']: continue artist = get_artists(group) title = html_unescape(group['name']) release_type = group['releaseType'] for torrent in group['torrents']: what_id = torrent['torrentid'] priority = filter_torrent(group, torrent) if priority and not is_existing(what_id): torrent_format = torrent['format'] encoding = torrent['encoding'] torrent_size = torrent['size'] queue_item = QueueItem( what_id=what_id, priority=priority, artist=artist, title=title, release_type=release_type, format=torrent_format, encoding=encoding, torrent_size=torrent_size ) queue_item.save() added += 1 torrent_count += 1 torrent_group_count += 1 return { 'success': True, 'added': added, 'groups': torrent_group_count, 'torrents': torrent_count }