示例#1
0
def upload_song(user, file_mp3_handle=None, file_source_handle=None, max_song_len=None, band=None, song_title=None, song_album="", song_comments="", filename_appendix=""):
    """
    inputs: 
        user:               the person uploading stuff
        file_mp3_handle:    the handle from the form
        file_source_handle: the handle from the form. need to also pass user if you want this to work.
        max_song_len:       how many seconds long a song can be. None means unlimited.
        band:               band model - who to attribute the song to.
        song_title:         id3 title to enforce upon the mp3
        song_album:         id3 album to enforce upon the mp3
        song_comments:      the author's own comments for the song.
        filename_appendix:  use this if you want to add something to the filename, before the extension.

    * uploads the mp3 and source file if applicable
    * creates the proper files and id3 tags
    * generates the waveform image

    outputs a dict:
        success:    boolean - whether it was successful or not
        reason:     string - what went wrong if success is False.
        song:       new song model. it will have been saved, but then more
                    things added to it so it needs to be saved again. it will
                    have the following fields properly populated:
            owner
            source_file
            waveform_img
            mp3_file
            band
            title
            album
            length
            studio
            samples
            effects
            generators
    """
    data = {
        'success': False,
        'song': None,
    }

    assert band != None, "Band parameter isn't optional."
    assert song_title != None, "Song title parameter isn't optional."

    song = Song()
    song.band = band
    song.owner = user
    song.title = song_title
    song.length = 0
    song.album = song_album

    # save so we can use relational fields
    song.save()
    
    # create the root node for song comments
    node = SongCommentNode()
    node.song = song
    node.owner = user
    node.content = song_comments
    node.save()

    song.comment_node = node

    if file_mp3_handle != None:
        result = handle_mp3_upload(file_mp3_handle, song, max_song_len, filename_appendix=filename_appendix)
        if not result['success']:
            song.delete()
            return result

    # upload the source file
    if file_source_handle != None:
        handle_project_upload(file_source_handle, user, song, filename_appendix=filename_appendix)

    # we incremented bytes_used in band, so save it now
    band.save()

    data['song'] = song
    data['success'] = True
    return data
示例#2
0
def upload_song(user,
                file_mp3_handle=None,
                file_source_handle=None,
                max_song_len=None,
                band=None,
                song_title=None,
                song_album="",
                song_comments="",
                filename_appendix=""):
    """
    inputs: 
        user:               the person uploading stuff
        file_mp3_handle:    the handle from the form
        file_source_handle: the handle from the form. need to also pass user if you want this to work.
        max_song_len:       how many seconds long a song can be. None means unlimited.
        band:               band model - who to attribute the song to.
        song_title:         id3 title to enforce upon the mp3
        song_album:         id3 album to enforce upon the mp3
        song_comments:      the author's own comments for the song.
        filename_appendix:  use this if you want to add something to the filename, before the extension.

    * uploads the mp3 and source file if applicable
    * creates the proper files and id3 tags
    * generates the waveform image

    outputs a dict:
        success:    boolean - whether it was successful or not
        reason:     string - what went wrong if success is False.
        song:       new song model. it will have been saved, but then more
                    things added to it so it needs to be saved again. it will
                    have the following fields properly populated:
            owner
            source_file
            waveform_img
            mp3_file
            band
            title
            album
            length
            studio
            samples
            effects
            generators
    """
    data = {
        'success': False,
        'song': None,
    }

    assert band != None, "Band parameter isn't optional."
    assert song_title != None, "Song title parameter isn't optional."

    song = Song()
    song.band = band
    song.owner = user
    song.title = song_title
    song.length = 0
    song.album = song_album

    # save so we can use relational fields
    song.save()

    # create the root node for song comments
    node = SongCommentNode()
    node.song = song
    node.owner = user
    node.content = song_comments
    node.save()

    song.comment_node = node

    if file_mp3_handle != None:
        result = handle_mp3_upload(file_mp3_handle,
                                   song,
                                   max_song_len,
                                   filename_appendix=filename_appendix)
        if not result['success']:
            song.delete()
            return result

    # upload the source file
    if file_source_handle != None:
        handle_project_upload(file_source_handle,
                              user,
                              song,
                              filename_appendix=filename_appendix)

    # we incremented bytes_used in band, so save it now
    band.save()

    data['song'] = song
    data['success'] = True
    return data