示例#1
0
def handle_mp3_upload(file_mp3_handle, song, max_song_len=None, filename_appendix=""):
    data = {'success': False}

    # upload mp3 file to temp folder
    mp3_tmp_handle = tempfile.NamedTemporaryFile(suffix='.mp3', delete=False)
    upload_file_h(file_mp3_handle, mp3_tmp_handle)
    mp3_tmp_handle.close()

    # read the length tag
    try:
        audio = MP3(mp3_tmp_handle.name, ID3=EasyID3)
        song.length = audio.info.length
    except:
        data['reason'] = design.invalid_mp3_file
        return data

    # reject if invalid
    if audio.info.sketchy:
        data['reason'] = design.sketchy_mp3_file
        return data

    # reject if too long
    if max_song_len != None:
        if audio.info.length > max_song_len:
            data['reason'] = design.song_too_long
            return data

    # enforce ID3 tags
    try:
        audio.add_tags(ID3=EasyID3)
    except MutagenID3Error:
        pass

    audio['artist'] = song.band.title
    if song.title != None:
        audio['title'] = song.title
    if song.album != None:
        audio['album'] = song.album

    try:
        audio.save()
    except:
        data['reason'] = design.unable_to_save_id3_tags
        return data

    # pick a path for the mp3 file. obscure the URL so that people can't steal songs
    song.mp3_file = os.path.join(obfuscated_url(song.band), clean_filename(song.displayString() + filename_appendix + '.mp3'))

    generate_waveform(song, mp3_tmp_handle.name, filename_appendix)

    # count mp3 against the band's size quota
    song.band.used_space += os.path.getsize(mp3_tmp_handle.name)

    # move mp3 file to storage
    move_to_storage(mp3_tmp_handle.name, song.mp3_file)

    song.band.save()
    data = {'success': True}
    return data
示例#2
0
def handle_project_upload(file_source_handle, user, song, filename_appendix=""):
    # upload project file to temp file
    _source_prefix, source_ext = os.path.splitext(file_source_handle.name)
    handle = tempfile.NamedTemporaryFile(suffix=source_ext, delete=False)
    upload_file_h(file_source_handle, handle)
    handle.close()

    handle_project_file(handle.name, user, song, filename_appendix=filename_appendix)
示例#3
0
def handle_sample_upload(fileHandle, user, band, callback=None):
    """
    uploads fileHandle, and runs handle_sample_file.
    """
    # copy it to temp file
    _name, ext = os.path.splitext(fileHandle.name)

    handle = tempfile.NamedTemporaryFile(suffix=ext, delete=False)
    upload_file_h(fileHandle, handle)
    handle.close()

    _path, title = os.path.split(fileHandle.name)
    handle_sample_file(handle.name, title, user, band, callback=callback)
示例#4
0
def handle_sample_upload(fileHandle, user, band, callback=None):
    """
    uploads fileHandle, and runs handle_sample_file.
    """
    # copy it to temp file
    _name, ext = os.path.splitext(fileHandle.name)

    handle = tempfile.NamedTemporaryFile(suffix=ext, delete=False)
    upload_file_h(fileHandle, handle)
    handle.close()

    _path, title = os.path.split(fileHandle.name)
    handle_sample_file(handle.name, title, user, band, callback=callback)
示例#5
0
def handle_project_upload(file_source_handle,
                          user,
                          song,
                          filename_appendix=""):
    # upload project file to temp file
    _source_prefix, source_ext = os.path.splitext(file_source_handle.name)
    handle = tempfile.NamedTemporaryFile(suffix=source_ext, delete=False)
    upload_file_h(file_source_handle, handle)
    handle.close()

    handle_project_file(handle.name,
                        user,
                        song,
                        filename_appendix=filename_appendix)
示例#6
0
def handle_mp3_upload(file_mp3_handle,
                      song,
                      max_song_len=None,
                      filename_appendix=""):
    data = {'success': False}

    # upload mp3 file to temp folder
    mp3_tmp_handle = tempfile.NamedTemporaryFile(suffix='.mp3', delete=False)
    upload_file_h(file_mp3_handle, mp3_tmp_handle)
    mp3_tmp_handle.close()

    # read the length tag
    try:
        audio = MP3(mp3_tmp_handle.name, ID3=EasyID3)
        song.length = audio.info.length
    except:
        data['reason'] = design.invalid_mp3_file
        return data

    # reject if invalid
    if audio.info.sketchy:
        data['reason'] = design.sketchy_mp3_file
        return data

    # reject if too long
    if max_song_len != None:
        if audio.info.length > max_song_len:
            data['reason'] = design.song_too_long
            return data

    # enforce ID3 tags
    try:
        audio.add_tags(ID3=EasyID3)
    except MutagenID3Error:
        pass

    audio['artist'] = song.band.title
    if song.title != None:
        audio['title'] = song.title
    if song.album != None:
        audio['album'] = song.album

    try:
        audio.save()
    except:
        data['reason'] = design.unable_to_save_id3_tags
        return data

    # pick a path for the mp3 file. obscure the URL so that people can't steal songs
    song.mp3_file = os.path.join(
        obfuscated_url(song.band),
        clean_filename(song.displayString() + filename_appendix + '.mp3'))

    generate_waveform(song, mp3_tmp_handle.name, filename_appendix)

    # count mp3 against the band's size quota
    song.band.used_space += os.path.getsize(mp3_tmp_handle.name)

    # move mp3 file to storage
    move_to_storage(mp3_tmp_handle.name, song.mp3_file)

    song.band.save()
    data = {'success': True}
    return data