Example #1
0
def download_torrent_group(request, group_id):
    if not request.user.has_perm('home.add_whattorrent'):
        return {
            'success': False,
            'error': 'You don\'t have permission to add torrents. Talk to the administrator.',
        }
    try:
        torrent_group = WhatTorrentGroup.objects.get(id=group_id)
    except WhatTorrentGroup.DoesNotExist:
        torrent_group = WhatTorrentGroup.update_from_what(get_what_client(request), group_id)
    if torrent_group.torrents_json is None:
        torrent_group = WhatTorrentGroup.update_from_what(get_what_client(request), group_id)
    ids = get_ids_to_download(torrent_group)
    try:
        instance = ReplicaSet.get_what_master().get_preferred_instance()
        download_location = DownloadLocation.get_what_preferred()
        for torrent_id in ids:
            add_torrent(request, instance, download_location, torrent_id)
    except Exception as ex:
        return {
            'success': False,
            'error': unicode(ex),
            'traceback': traceback.format_exc(),
        }
    return {
        'success': True,
        'added': len(ids),
    }
Example #2
0
def get_torrent_group(request, group_id):
    try:
        if 'HTTP_X_REFRESH' in request.META:
            raise WhatTorrentGroup.DoesNotExist()
        torrent_group = WhatTorrentGroup.objects.get(id=group_id)
    except WhatTorrentGroup.DoesNotExist:
        what_client = get_what_client(request)
        torrent_group = WhatTorrentGroup.update_from_what(what_client, group_id)
    data = get_torrent_group_dict(torrent_group)
    data.update(get_torrent_groups_have([torrent_group.id], True)[torrent_group.id])
    return data
Example #3
0
 def save(self, *args, **kwargs):
     with transaction.atomic():
         try:
             if int(self.info_category_id) == 1:
                 self.torrent_group = WhatTorrentGroup.update_if_newer(
                     self.info_loads['group']['id'], self.retrieved, self.info_loads['group'])
         except Exception:
             pass
         super(WhatTorrent, self).save(*args, **kwargs)
     try:
         what_fulltext = WhatFulltext.objects.get(id=self.id)
         if not what_fulltext.match(self):
             what_fulltext.update(self)
     except WhatFulltext.DoesNotExist:
         what_fulltext = WhatFulltext(id=self.id)
         what_fulltext.update(self)
Example #4
0
 def save(self, *args, **kwargs):
     with transaction.atomic():
         try:
             if int(self.info_category_id) == 1:
                 self.torrent_group = WhatTorrentGroup.update_if_newer(
                     self.info_loads['group']['id'], self.retrieved,
                     self.info_loads['group'])
         except Exception:
             pass
         super(WhatTorrent, self).save(*args, **kwargs)
     try:
         what_fulltext = WhatFulltext.objects.get(id=self.id)
         if not what_fulltext.match(self):
             what_fulltext.update(self)
     except WhatFulltext.DoesNotExist:
         what_fulltext = WhatFulltext(id=self.id)
         what_fulltext.update(self)