Exemple #1
0
def add_song():
    url_image = None
    url_song = None
    if "image_url" in request.files:
        image = request.files["image_url"]
        image.filename = get_unique_filename(image.filename)
        upload = upload_file_to_s3(image)
        url_image = upload["url"]
    else:
        url_image = 'https://i.stack.imgur.com/l60Hf.png'
    if "song" in request.files:
        song_file = request.files["song"]
        song_file.filename = get_unique_filename(song_file.filename)
        upload = upload_file_to_s3(song_file)
        url_song = upload["url"]
        print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
        print(url_song)

    form = SongForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    new_song = Song(
        artist_id=request.form['artist_id'],
        name=request.form['name'],
        description=request.form['description'],
        category=request.form['category'],
        album=request.form['album'],
        image_url=url_image,
        song=url_song,
        # public=request.form['public'],
    )

    db.session.add(new_song)
    db.session.commit()
    data = new_song.to_dict()
    return data
Exemple #2
0
def add_song():
    url_image = None
    url_song = None
    if "image" in request.files:
        image = request.files["image"]
        image.filename = get_unique_filename(image.filename)
        upload = upload_file_to_s3(image)
        url_image = upload["url"]
    if "audio" in request.files:
        song_file = request.files["audio"]
        # content = request.files["audio"].read()
        song_file.filename = get_unique_filename(song_file.filename)
        upload = upload_file_to_s3(song_file)
        url_song = upload["url"]
        print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
        print(url_song)
        # Convert song file to binary
        # audio_binary = convertToBinaryData(content)
        # print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
        # print(audio_binary)
        # Convert audio file into Numpy array
        # AudioNumpyArray = read(song_file, normalized=False)
        # numpyData = {"array": AudioNumpyArray}

        # # Serialization
        # numpyData = {"array": AudioNumpyArray}
        # # use dump() to write array into file
        # encodedNumpyData = json.dumps(numpyData, cls=NumpyArrayEncoder)
    form = UploadForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    new_song = Song(
        user_id=request.form['id'],
        title=request.form['title'],
        description=request.form['description'],
        image_url=url_image,
        audio_file=url_song,
        artist=request.form['artist'],
        genre_id=1,
    )

    db.session.add(new_song)
    db.session.commit()
    data = new_song.to_dict()
    return data
Exemple #3
0
def add_song():
    data = request.json
    token = request.headers.get('Authorization')
    req = requests.get('https://dev-c-4o8wnx.auth0.com/userinfo',
                       headers={
                           'Authorization': token
                       }).content
    userInfo = json.loads(req)
    userId = User.query.filter_by(email=userInfo['email']).first().id
    song = Song(
        title=data['title'],
        genre=data['genre'],
        description=data['description'],
        image_url=data['image_url'],
        song_url=data['song_url'],
        user_id=userId,
        created_at=data['created_at'],
    )

    db.session.add(song)
    db.session.commit()
    return song.to_dict(), 201
Exemple #4
0
def add_song():
    song = Song(user_Id=current_user.id, **request.json)
    db.session.add(song)
    db.session.commit()
    return song.to_dict()