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 append_to_queue(request): dd = {} try: queue_name = request.POST['queue_name'] username = request.POST['username'] special_requests = request.POST['special_requests'] user = User.objects.get(username=username) queue = Queue.objects.get(name=queue_name) status = Status.objects.get(name="Pending") max_pos = QueueItem.objects.filter(queue__name=queue_name, active=True).aggregate(models.Max('position')) if max_pos['position__max'] > -1: new_pos = max_pos['position__max'] + 1 else: new_pos = 0 qi = QueueItem() qi.position = new_pos qi.queue = queue qi.user = user qi.special_requirements = special_requests qi.status = status qi.active = True qi.save() msg = " Queue item added to %s queue." % queue_name dd.update({ "status": msg }) except Exception: dd.update({ "status": " Could not append to this queue." }) raise return render_to_response('append_to_queue.js', dd, context_instance=RequestContext(request))
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 auto_pop(request): front = QueueItem.get_front() if not front: LogEntry.add(request.user, u'info', 'Auto pop: queue is empty.') return { 'success': False, 'error': 'Queue is empty.' } try: ratio_delta = get_auto_pop_ratio_delta(WhatUserSnapshot.get_last()) except WhatUserSnapshot.DoesNotExist: LogEntry.add(request.user, u'info', 'Auto pop: User profile not updated, skipping pop.') return { 'success': False, 'error': u'User profile not updated, skipping pop.' } if ratio_delta >= front.torrent_size: return do_pop(request) else: message = u'Auto pop: ratio delta {0} < {1}, skipping pop.'.format( filesizeformat(ratio_delta), filesizeformat(front.torrent_size) ) LogEntry.add(request.user, u'info', message) return { 'success': False, 'error': u'Buffer is {0}, skipping pop.'.format(message) }
def pop_remove(request): front = QueueItem.get_front() if not front: return { 'success': False, 'message': 'Queue is empty.' } front.delete() return { 'success': True }
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 }
def do_pop(request): download_location = DownloadLocation.get_what_preferred() if download_location.free_space_percent < MIN_FREE_DISK_SPACE: LogEntry.add(request.user, u'error', u'Failed to add torrent. Not enough disk space.') return { 'success': False, 'error': u'Not enough free space on disk.' } front = QueueItem.get_front() if not front: return { 'success': False, 'message': 'Queue is empty.' } instance = ReplicaSet.get_what_master().get_preferred_instance() if WhatTorrent.is_downloaded(request, what_id=front.what_id): front.delete() return { 'success': True, 'message': 'Already added.' } try: m_torrent = manage_torrent.add_torrent(request, instance, download_location, front.what_id) m_torrent.what_torrent.added_by = request.user m_torrent.what_torrent.tags = 'seed project' m_torrent.what_torrent.save() front.delete() LogEntry.add(request.user, u'action', u'Popped {0} from queue.'.format(m_torrent)) except Exception as ex: tb = traceback.format_exc() LogEntry.add(request.user, u'error', u'Tried popping what_id={0} from queue. Error: {1}'.format(front.what_id, unicode(ex)), tb) return { 'success': False, 'error': unicode(ex), 'traceback': tb } return { 'success': True }
def queue_pop(request): data = { 'front': QueueItem.get_front() } return render(request, 'queue/part_ui/queue_pop.html', data)
def add(request): item = QueueItem(text=request.POST["text"]) item.save() cache.delete(QUEUE_KEY, _get_queue()) return HttpResponse("<li>%s</li>" % item.text)