def add_artist(self, **kwargs):
        artist_name = kwargs['title'][0]
        artist = Artist.objects(name=artist_name)
        if artist.count():
            Log(type_added='artist', name_added=artist_name).save()
            return False

        self.download(kwargs.get('img'))
        artist = Artist(name=artist_name)

        if artist:
            Log(type_added='artist', name_added=artist_name, added=True).save()
            with open(TEMP_FILE, 'rb') as binary_file:
                artist.image.put(binary_file)
            shutil.rmtree(TEMP)

            artist.save()
            return True
        Log(type_added='artist', name_added=artist_name).save()
        return False
Exemple #2
0
def signUp():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = NewArtistForm()
    if form.validate_on_submit():
        # make new artist
        location = Location.objects(city=form.city.data, state=form.state.data).first()
        if location is None:
            location = Location(city=form.city.data, state=form.state.data, zip_code=form.zip.data)
            location.save(cascade=True)
        mediaLinks = []
        if form.facebook.data != "":
            mediaLinks.append(form.facebook.data)
        if form.youtube.data != "":
            mediaLinks.append(form.youtube.data)
        if form.spotify.data != "":
            mediaLinks.append(form.spotify.data)
        newArtist = Artist(email=form.email.data, name=form.bandName.data, description=form.description.data,
                           media_links=mediaLinks, location=location, genre=form.genre.data, image=form.image.data)
        newArtist.set_password(form.password.data)
        newArtist.save(cascade=True)
        return redirect(url_for('logIn'))  # probably want to send to artist page once that exists
    return render_template('signUp.html', form=form)
Exemple #3
0
def create_artist():
    form = CreateArtistForm()
    form.location.choices = [(location.id,
                              location.city + ', ' + location.state)
                             for location in Location.objects()]
    form.genre.choices = [(genre.id, genre.name)
                          for genre in Genre.objects.order_by('name')]
    if form.validate_on_submit():
        user = User.objects(username=current_user.username).first()
        location = Location.objects(id=form.location.data).first()
        genres = []
        for genre_id in form.genre.data:
            genres.append(Genre.objects(id=genre_id).first())
        artist = Artist(name=form.name.data,
                        description=form.description.data,
                        location=location,
                        genre=genres)
        artist.save(cascade=True)
        add_member(user, artist)
        flash('Artist {} was created'.format(artist.name))
        return redirect(url_for('main.artist', artist_name=artist.name))
    return render_template('create_artist.html',
                           form=form,
                           title='Create Artist')
Exemple #4
0
def updateDBInfo(response, track):
    tags = Information()
    # Changing tags in the database
    if 'TITLE' in response and response['TITLE'] != '':
        tags.trackTitle = strip_tags(response['TITLE']).lstrip().rstrip()
        track.title = tags.trackTitle

    if 'ARTISTS' in response and response['ARTISTS'] != '':
        tags.trackArtist = strip_tags(
            response['ARTISTS']).lstrip().rstrip().split(',')
        artists = []
        for artist in tags.trackArtist:
            if Artist.objects.filter(name=artist).count() == 0:
                newArtist = Artist()
                newArtist.name = artist
                newArtist.save()
            artists.append(Artist.objects.get(name=artist))
        track.artist.clear()
        for artist in artists:
            track.artist.add(artist)

    if 'PERFORMER' in response and response['PERFORMER'] != '':
        tags.trackPerformer = strip_tags(
            response['PERFORMER']).lstrip().rstrip()
        track.performer = tags.trackPerformer

    if 'COMPOSER' in response and response['COMPOSER'] != '':
        tags.trackComposer = strip_tags(response['COMPOSER']).lstrip().rstrip()
        track.composer = tags.trackComposer

    if 'YEAR' in response and response['YEAR'] != '':
        tags.trackYear = checkIntValueError(response['YEAR'])
        track.year = tags.trackYear

    if 'TRACK_NUMBER' in response and response['TRACK_NUMBER'] != '':
        tags.trackNumber = checkIntValueError(response['TRACK_NUMBER'])
        track.number = tags.trackNumber

    if 'BPM' in response and response['BPM'] != '':
        track.bpm = checkIntValueError(response['BPM'])

    if 'LYRICS' in response and response['LYRICS'] != '':
        tags.lyrics = strip_tags(response['LYRICS']).lstrip().rstrip()
        track.lyrics = tags.lyrics

    if 'COMMENT' in response and response['COMMENT'] != '':
        tags.comment = strip_tags(response['COMMENT']).lstrip().rstrip()
        track.comment = tags.comment

    if 'GENRE' in response and response['GENRE'] != '':
        tags.trackGenre = strip_tags(response['GENRE']).lstrip().rstrip()
        if Genre.objects.filter(name=tags.trackGenre).count() == 0:
            genre = Genre()
            genre.name = tags.trackGenre
            genre.save()
        genre = Genre.objects.get(name=tags.trackGenre)
        track.genre = genre

    if 'COVER' in response:
        md5Name = hashlib.md5()
        if str(response['COVER'].split(",")[0]) == "image/png":
            extension = "png"
        else:
            extension = "jpg"
        md5Name.update(base64.b64decode(str(response['COVER'].split(",")[1])))
        # Check if the folder exists
        filePath = "/ManaZeak/static/img/covers/"
        if not os.path.isdir(filePath):
            os.mkdir(filePath)  # Create the folder
        filePath += +md5Name.hexdigest() + extension

        # if the filePath is the same, then the md5 hash of the image is
        # the same, therefore the images are the same, therefore do nothing
        if not os.path.isfile(filePath):
            with open(filePath, 'wb+') as destination:
                # Split the header with MIME type
                tags.cover = base64.b64decode(
                    str(response['COVER'].split(",")[1]))
                destination.write(tags.cover)
                track.coverLocation = md5Name.hexdigest() + extension

    if 'ALBUM_TITLE' in response and 'ALBUM_ARTISTS' in response and response['ALBUM_TITLE'] != '' \
            and response['ALBUM_ARTISTS'] != '':
        tags.albumTitle = strip_tags(response['ALBUM_TITLE']).lstrip().rstrip()
        tags.albumArtist = strip_tags(
            response['ALBUM_ARTISTS']).lstrip().rstrip().split(',')
        if Album.objects.filter(title=tags.albumTitle).count() == 0:
            album = Album()
            album.title = tags.albumTitle
            album.save()
        album = Album.objects.get(title=tags.albumTitle)
        album.artist.clear()
        for artist in tags.albumArtist:
            if Artist.objects.filter(name=artist).count() == 0:
                newArtist = Artist()
                newArtist.name = artist
                newArtist.save()
            album.artist.add(Artist.objects.get(name=artist))

        if 'ALBUM_TOTAL_DISC' in response and response[
                'ALBUM_TOTAL_DISC'] != '':
            tags.albumTotalDisc = checkIntValueError(
                response['ALBUM_TOTAL_DISC'])
            album.totalDisc = tags.albumTotalDisc

        if 'DISC_NUMBER' in response and response['DISC_NUMBER'] != '':
            tags.albumDiscNumber = checkIntValueError(response['DISC_NUMBER'])
            track.discNumber = tags.albumDiscNumber

        if 'ALBUM_TOTAL_TRACK' in response and response[
                'ALBUM_TOTAL_TRACK'] != '':
            tags.albumTotalTrack = checkIntValueError(
                response['ALBUM_TOTAL_TRACK'])
            album.totalTrack = tags.albumTotalTrack
        album.save()
        track.album = album
    track.save()
    return tags