Esempio n. 1
0
def prepare(request, upload_id):
    qobuz_upload = QobuzUpload.objects.get(id=upload_id)
    qiller = qobuz_upload.upload
    qiller.prepare(get_temp_dir(qiller.metadata.id))
    qobuz_upload.set_upload(qiller)
    qobuz_upload.save()
    return redirect(edit_upload, upload_id)
Esempio n. 2
0
def make_torrent(request, upload_id):
    qobuz_upload = QobuzUpload.objects.get(id=upload_id)
    qiller = qobuz_upload.upload
    qiller.make_torrent(get_temp_dir(qiller.metadata.id), WHAT_ANNOUNCE)
    qobuz_upload.set_upload(qiller)
    qobuz_upload.save()
    return redirect(edit_upload, upload_id)
Esempio n. 3
0
def new_upload(request):
    if request.method == 'POST':
        form = NewUploadForm(request.POST)
        if form.is_valid():
            album_id = form.cleaned_data['album_id']
            try:
                QobuzUpload.objects.get(qobuz_album_id=album_id)
                form.add_error('album_id', 'Already in the upload database')
            except QobuzUpload.DoesNotExist:
                try:
                    temp_dir = get_temp_dir(album_id)
                    qiller = QillerUpload(temp_dir)
                    if 'Qobuz' in request.POST:
                        qobuz = get_qobuz_client(request)
                        qiller.load_from_qobuz(qobuz, temp_dir, album_id)
                    elif 'Tidal' in request.POST:
                        tidal = get_tidal_client(request)
                        qiller.load_from_tidal(tidal, temp_dir, album_id)
                    upload = QobuzUpload(state=qiller.state)
                    upload.set_upload(qiller)
                    upload.save()
                    os.chmod(temp_dir, 0777)
                    return redirect(edit_upload, upload.id)
                except RequestException:
                    form.add_error('album_id', 'Cannot fetch Qobuz album')
    else:
        form = NewUploadForm(initial={
            'album_id': request.GET.get('id', '')
        })
    data = {
        'form': form,
    }
    return render(request, 'qobuz2/new_upload.html', data)
Esempio n. 4
0
def view_cover(request, upload_id):
    try:
        qobuz_upload = QobuzUpload.objects.get(id=upload_id)
        dest_path = os.path.join(get_temp_dir(qobuz_upload.upload.metadata.id),
                                 os.path.basename(request.GET['path']))
        f = open(wm_str(dest_path), 'rb')
        return HttpResponse(f, content_type='image/jpeg')
    except Exception:
        return HttpResponseNotFound()
Esempio n. 5
0
 def inner(request, upload_id):
     try:
         qobuz_upload = QobuzUpload.objects.get(id=upload_id)
         dest_path = os.path.join(get_temp_dir(qobuz_upload.upload.metadata.id), subpath,
                                  os.path.basename(request.GET['path']))
         s = os.path.getmtime(wm_str(dest_path))
         return datetime.datetime.utcfromtimestamp(s)
     except Exception:
         raise
         return None
Esempio n. 6
0
def edit_upload_whatcd(request, upload):
    if request.method == 'POST':
        what_client = get_what_client(request)
        temp_dir = get_temp_dir(upload.upload.metadata.id)
        if request.GET['type'] == 'existing':
            group_id = request.POST['group_id']
            assert group_id
            if 'subgroup' in request.POST:
                upload.upload.upload_to_what(what_client, temp_dir, 'upload_in_subgroup',
                                             [group_id, None])
            elif 'original' in request.POST:
                upload.upload.upload_to_what(what_client, temp_dir, 'upload_in_original_release',
                                             [group_id])
            elif 'with_torrent' in request.POST:
                with_id = request.POST['with_id']
                assert with_id
                upload.upload.upload_to_what(
                    what_client, temp_dir, 'upload_in_subgroup', [group_id, with_id])
            else:
                raise Exception('Unknown button clicked')
        elif request.GET['type'] == 'new':
            release_type_id = request.POST['release_type']
            release_tags = request.POST['tags']
            assert release_type_id
            assert release_tags
            qiller = upload.upload

            def do_upload():
                kwargs = dict()
                if 'force_artists' in request.POST:
                    kwargs['force_artists'] = True
                if request.POST['original_year']:
                    kwargs['remaster'] = True
                    kwargs['original_year'] = request.POST['original_year']
                qiller.upload_to_what(
                    what_client, temp_dir, 'upload_new_group',
                    [release_type_id, release_tags], kwargs
                )
                upload.set_upload(qiller)
                upload.save()

            try:
                do_upload()
            except MissingImageException:
                do_upload_cover(upload, temp_dir, qiller)
                do_upload()
        else:
            raise Exception('Unknown type')
        return redirect(seed_upload, upload.id)
    data = {
        'upload': upload,
        'spectrals': get_spectral_files(upload.upload),
        'release_types': WHAT_RELEASE_TYPES,
    }
    return render(request, 'qobuz2/upload_whatcd.html', data)
Esempio n. 7
0
def qiller_download(celery_task, qobuz_album_id):
    try:
        upload = QobuzUpload.objects.get(id=qobuz_album_id)
        qiller = upload.upload
        temp_dir = get_temp_dir(qiller.metadata.id)
        qiller.download(temp_dir, True)
        upload.set_upload(qiller)
        for item in os.listdir(temp_dir):
            recursive_chmod(os.path.join(temp_dir, item), 0777)
        upload.save()
    finally:
        connection.close()
Esempio n. 8
0
def seed_upload(request, upload_id):
    qobuz_upload = QobuzUpload.objects.get(id=upload_id)
    temp_dir = get_temp_dir(qobuz_upload.upload.metadata.id)
    torrent_path = os.path.join(temp_dir, qobuz_upload.upload.metadata.torrent_name + '.torrent')
    assert os.path.isfile(wm_str(torrent_path))
    info_hash = get_info_hash(torrent_path)
    what_torrent = WhatTorrent.get_or_create(request, info_hash=info_hash)
    command = import_external_what_torrent.Command()
    command.handle(wm_str(temp_dir), wm_str(torrent_path), base_dir=False)
    try:
        run_request_transcode(request, what_torrent.id)
    except Exception:
        pass
    qiller = qobuz_upload.upload
    qiller.state = STATE_DONE
    qobuz_upload.set_upload(qiller)
    qobuz_upload.save()
    return redirect(edit_upload, upload_id)
Esempio n. 9
0
def get_spectral_files(qiller):
    spectrals_dir = os.path.join(get_temp_dir(qiller.metadata.id), 'spectrals')
    try:
        return os.listdir(spectrals_dir)
    except OSError:
        return []
Esempio n. 10
0
def upload_cover(request, upload_id):
    upload = QobuzUpload.objects.get(id=upload_id)
    temp_dir = get_temp_dir(upload.upload.metadata.id)
    qiller = upload.upload
    do_upload_cover(upload, temp_dir, qiller)
    return redirect(edit_upload, upload_id)