Пример #1
0
def search_torrents(request):
    query = request.POST.get('query') or request.GET.get('query')
    query = ' '.join('+' + i for i in query.split())

    w_fulltext = WhatFulltext.objects.filter(info__search=query).only('id')
    w_fulltext = w_fulltext.extra(select={'score': 'MATCH(`info`) AGAINST (%s)'},
                                  select_params=[query])
    w_fulltext = w_fulltext.extra(order_by=['-score'])

    w_torrents_dict = WhatTorrent.objects.in_bulk([w.id for w in w_fulltext])
    w_torrents = list()
    for i in w_fulltext:
        w_torrent = w_torrents_dict[i.id]
        w_torrent.score = i.score
        w_torrents.append(w_torrent)

    b_torrents = bibliotik.utils.search_torrents(query)

    for t in w_torrents:
        t.playlist_name = 'what/{0}'.format(t.id)

    torrents = w_torrents + b_torrents
    torrents.sort(key=lambda torrent: torrent.score, reverse=True)

    data = {
        'token': get_user_token(request.user),
        'torrents': torrents,
    }
    res = render(request, 'home/part_ui/search_torrents.html', data)
    return res
Пример #2
0
def recently_downloaded(request):
    count = 40
    recent = []
    for instance in ReplicaSet.get_what_master().transinstance_set.all():
        torrents = instance.transtorrent_set.filter(torrent_done=1)
        torrents = torrents.order_by('-torrent_date_added')[:count]
        for t in torrents:
            t.playlist_name = 'what/{0}'.format(t.what_torrent_id)
        recent.extend(torrents)
    for instance in ReplicaSet.get_bibliotik_master().transinstance_set.all():
        bibliotik_torrents = instance.bibliotiktranstorrent_set.filter(torrent_done=1)
        bibliotik_torrents = bibliotik_torrents.order_by('-torrent_date_added')[:count]
        recent.extend(bibliotik_torrents)
    recent.sort(key=lambda lt: lt.torrent_date_added, reverse=True)
    recent = recent[:count]

    data = {
        'token': get_user_token(request.user),
        'torrents': recent,
    }
    return render(request, 'home/part_ui/recently_downloaded.html', data)
Пример #3
0
def download_pls(request, playlist_path):
    files = []
    playlist_name, cache_entries = get_playlist_files(playlist_path)
    for f in cache_entries:
        file_data = f.easy
        file_data['path'] = request.build_absolute_uri(build_url('player.views.get_file', get={
            'path': f.path,
            'username': request.user.username,
            'token': get_user_token(request.user),
        }))
        files.append(file_data)

    data = {
        'files': files
    }

    response = render(request, 'download/pls.txt', data)
    response['Content-Disposition'] = ('attachment; filename="[' +
                                       playlist_path.replace('/', '-') + '] ' +
                                       playlist_name + '.pls"')
    response['Content-Type'] = 'audio/x-scpls'
    return response
Пример #4
0
def download_pls(request, playlist_path):
    files = []
    playlist_name, cache_entries = get_playlist_files(playlist_path)
    for f in cache_entries:
        file_data = f.easy
        file_data['path'] = request.build_absolute_uri(
            build_url('player.views.get_file',
                      get={
                          'path': f.path,
                          'username': request.user.username,
                          'token': get_user_token(request.user),
                      }))
        files.append(file_data)

    data = {'files': files}

    response = render(request, 'download/pls.txt', data)
    response['Content-Disposition'] = ('attachment; filename="[' +
                                       playlist_path.replace('/', '-') + '] ' +
                                       playlist_name + '.pls"')
    response['Content-Type'] = 'audio/x-scpls'
    return response
Пример #5
0
def view_token(request):
    return HttpResponse(get_user_token(request.user))
Пример #6
0
def view_token(request):
    return HttpResponse(get_user_token(request.user))