Exemple #1
0
def redownload(request_id):
    song_request = song_request_dao.get_song_request_by_id(request_id)
    song_request.song.percent_complete = "0%"
    song_request.song.completed = False
    song_request_dao.update_song_request(song_request)
    d = Downloader()
    d.download(song_request.song.youtube_id)
    flash('Attempting background download again', 'success')
    return redirect(url_for('song.view', event_id=song_request.event_id))
Exemple #2
0
def add(event_id):
    form = AddSongForm(request.form)
    d = Downloader()
    if form.validate_on_submit():

        youtube_info = d.check_youtube(form.url.data)

        # If the video exists on youtube then save the details to DB
        if youtube_info:

            song_from_db = song_file_dao.get_song_file_by_youtube_id(youtube_info['id'])
            # If it's not already in the db, then create it
            if song_from_db is None:
                song_file = SongFile(
                    url=form.url.data,
                    title=youtube_info['title'],
                    youtube_id=youtube_info['id']
                )
                song_file_dao.create_song_file(song_file)
                song_from_db = song_file

            # attempt a download
            d.download(youtube_info['id'])

            # do this last - with the file ID
            song_request = SongRequest(
                requester=form.requester.data,
                delay=form.delay.data,
                song_file_id=song_from_db.id,
                event_id=event_id
            )
            song_request_dao.create_song_request(song_request)
            flash('Thank you for adding a song. Attempting background download.', 'success')
            return redirect(url_for("song.view", event_id=event_id))
        else:
            flash('There was an error finding the YouTube video, please try another URL.', 'danger')

    return render_template('songs/add.html', form=form)