Пример #1
0
def set_song_fave(song_id, user_id, fave):
    db.c.start_transaction()
    exists = db.c.fetch_row("SELECT * FROM r4_song_ratings WHERE song_id = %s AND user_id = %s", (song_id, user_id))
    rating = None
    if not exists:
        if (
            db.c.update(
                "INSERT INTO r4_song_ratings (song_id, user_id, song_fave) VALUES (%s, %s, %s)",
                (song_id, user_id, fave),
            )
            == 0
        ):
            log.debug("rating", "Failed to insert record for song fave %s, fave is: %s." % (song_id, fave))
            return False
    else:
        rating = exists["song_rating_user"]
        if (
            db.c.update(
                "UPDATE r4_song_ratings SET song_fave = %s WHERE song_id = %s AND user_id = %s",
                (fave, song_id, user_id),
            )
            == 0
        ):
            log.debug("rating", "Failed to update record for fave song %s, fave is: %s." % (song_id, fave))
            return False
    if (not exists and fave) or (not exists["song_fave"] and fave):
        db.c.update("UPDATE r4_songs SET song_fave_count = song_fave_count + 1 WHERE song_id = %s", (song_id,))
    elif exists and exists["song_fave"] and not fave:
        db.c.update("UPDATE r4_songs SET song_fave_count = song_fave_count - 1 WHERE song_id = %s", (song_id,))
    cache.set_song_rating(song_id, user_id, {"rating_user": rating, "fave": fave})
    db.c.commit()
    return True
Пример #2
0
def set_song_rating(song_id, user_id, rating = None, fave = None):
	existing_rating = db.c.fetch_row("SELECT song_rating_user, song_fave FROM r4_song_ratings WHERE song_id = %s AND user_id = %s", (song_id, user_id))
	count = db.c.fetch_var("SELECT COUNT(*) FROM r4_song_ratings WHERE user_id = %s", (user_id,))
	if not existing_rating:
		count += 1
	rank = db.c.fetch_var("SELECT COUNT(*) FROM phpbb_users WHERE radio_totalratings > %s", (count,))
	if existing_rating:
		if not rating:
			rating = existing_rating["song_rating_user"]
		if not fave:
			fave = existing_rating["song_fave"]
		db.c.update("UPDATE r4_song_ratings "
			"SET song_rating_user = %s, song_fave = %s, song_rated_at = %s, song_rated_at_rank = %s, song_rated_at_count = %s "
			"WHERE user_id = %s AND song_id = %s",
			(rating, fave, time.time(), rank, count, user_id, song_id))
	else:
		if not rating:
			rating = None
		if not fave:
			fave = None
		db.c.update("INSERT INTO r4_song_ratings "
					"(song_rating_user, song_fave, song_rated_at, song_rated_at_rank, song_rated_at_count, user_id, song_id) "
					"VALUES (%s, %s, %s, %s, %s, %s, %s)",
					(rating, fave, time.time(), rank, count, user_id, song_id))

	db.c.update("UPDATE phpbb_users SET radio_totalratings = %s WHERE user_id = %s", (count, user_id))
	cache.set_song_rating(song_id, user_id, { "rating_user": rating, "fave": fave })

	return update_album_ratings(song_id, user_id)
Пример #3
0
def set_album_fave(sid, album_id, user_id, fave):
	db.c.start_transaction()
	exists = db.c.fetch_row("SELECT * FROM r4_album_ratings WHERE album_id = %s AND user_id = %s AND sid = %s", (album_id, user_id, sid))
	rating = None
	rating_complete = None
	if not exists:
		if db.c.update("INSERT INTO r4_album_ratings (album_id, user_id, album_fave, sid) VALUES (%s, %s, %s, %s)", (album_id, user_id, fave, sid)) == 0:
			log.debug("rating", "Failed to insert record for fave %s %s, fave is: %s." % ("album", album_id, fave))
			return False
	else:
		rating = exists["album" + "_rating_user"]
		rating_complete = exists['album_rating_complete']
		if db.c.update("UPDATE r4_album_ratings SET album_fave = %s WHERE album_id = %s AND user_id = %s AND sid = %s", (fave, album_id, user_id, sid)) == 0:
			log.debug("rating", "Failed to update record for fave %s %s, fave is: %s." % ("album", album_id, fave))
			return False
	if (not exists and fave) or (not exists["album" + "_fave"] and fave):
		db.c.update("UPDATE r4_album_sid SET album_fave_count = album_fave_count + 1 WHERE album_id = %s AND sid = %s", (album_id, sid))
	elif (exists and exists["album" + "_fave"] and not fave):
		db.c.update("UPDATE r4_album_sid SET album_fave_count = album_fave_count - 1 WHERE album_id = %s AND sid = %s", (album_id, sid))
	if "album" == "album":
		cache.set_album_rating(sid, album_id, user_id, { "rating_user": rating, "fave": fave, "rating_complete": rating_complete })
	elif "album" == "song":
		cache.set_song_rating(album_id, user_id, { "rating_user": rating, "fave": fave })
	return True
	db.c.commit()
Пример #4
0
def set_song_rating(sid, song_id, user_id, rating=None, fave=None):
    db.c.start_transaction()
    try:
        existing_rating = db.c.fetch_row(
            "SELECT song_rating_user, song_fave FROM r4_song_ratings WHERE song_id = %s AND user_id = %s",
            (song_id, user_id),
        )
        count = db.c.fetch_var(
            "SELECT COUNT(*) FROM r4_song_ratings WHERE user_id = %s",
            (user_id, ))
        if not existing_rating:
            count += 1
        rank = db.c.fetch_var(
            "SELECT COUNT(*) FROM phpbb_users WHERE radio_totalratings > %s",
            (count, ))
        if existing_rating:
            if not rating:
                rating = existing_rating["song_rating_user"]
            if not fave:
                fave = existing_rating["song_fave"]
            db.c.update(
                "UPDATE r4_song_ratings "
                "SET song_rating_user = %s, song_fave = %s, song_rated_at = %s, song_rated_at_rank = %s, song_rated_at_count = %s "
                "WHERE user_id = %s AND song_id = %s",
                (rating, fave, timestamp(), rank, count, user_id, song_id),
            )
            db.c.update(
                "UPDATE phpbb_users SET radio_totalmindchange = radio_totalmindchange + 1, radio_inactive = FALSE, radio_last_active = %s WHERE user_id = %s",
                (
                    timestamp(),
                    user_id,
                ),
            )
        else:
            if not rating:
                rating = None
            if not fave:
                fave = None
            db.c.update(
                "INSERT INTO r4_song_ratings "
                "(song_rating_user, song_fave, song_rated_at, song_rated_at_rank, song_rated_at_count, user_id, song_id) "
                "VALUES (%s, %s, %s, %s, %s, %s, %s)",
                (rating, fave, timestamp(), rank, count, user_id, song_id),
            )

        db.c.update(
            "UPDATE phpbb_users SET radio_totalratings = %s, radio_inactive = FALSE, radio_last_active = %s WHERE user_id = %s",
            (count, timestamp(), user_id),
        )

        albums = update_album_ratings(sid, song_id, user_id)
        db.c.commit()
        cache.set_song_rating(song_id, user_id, {
            "rating_user": rating,
            "fave": fave
        })
        return albums
    except:
        db.c.rollback()
        raise
Пример #5
0
def get_song_rating(song_id, user_id):
	rating = cache.get_song_rating(song_id, user_id)
	if not rating:
		rating = db.c.fetch_row("SELECT song_rating_user AS rating_user, song_fave AS fave FROM r4_song_ratings WHERE user_id = %s AND song_id = %s", (user_id, song_id))
		if not rating:
			rating = { "rating_user": 0, "fave": None }
	cache.set_song_rating(song_id, user_id, rating)
	return rating
Пример #6
0
def get_song_rating(song_id, user_id):
    rating = cache.get_song_rating(song_id, user_id)
    if not rating:
        rating = db.c.fetch_row(
            "SELECT song_rating_user AS rating_user, song_fave AS fave FROM r4_song_ratings WHERE user_id = %s AND song_id = %s",
            (user_id, song_id))
        if not rating:
            rating = {"rating_user": 0, "fave": None}
    cache.set_song_rating(song_id, user_id, rating)
    return rating
Пример #7
0
def set_song_fave(song_id, user_id, fave):
    db.c.start_transaction()
    exists = db.c.fetch_row(
        "SELECT * FROM r4_song_ratings WHERE song_id = %s AND user_id = %s",
        (song_id, user_id),
    )
    rating = None
    if not exists and fave:
        if (
            db.c.update(
                "INSERT INTO r4_song_ratings (song_id, user_id, song_fave) VALUES (%s, %s, %s)",
                (song_id, user_id, fave),
            )
            == 0
        ):
            log.debug(
                "rating",
                "Failed to insert record for song fave %s, fave is: %s."
                % (song_id, fave),
            )
            return False
    elif not exists and not fave:
        # Nothing to do!
        return True
    else:
        rating = exists["song_rating_user"]
        if (
            db.c.update(
                "UPDATE r4_song_ratings SET song_fave = %s WHERE song_id = %s AND user_id = %s",
                (fave, song_id, user_id),
            )
            == 0
        ):
            log.debug(
                "rating",
                "Failed to update record for fave song %s, fave is: %s."
                % (song_id, fave),
            )
            return False
    if (not exists and fave) or (not exists["song_fave"] and fave):
        db.c.update(
            "UPDATE r4_songs SET song_fave_count = song_fave_count + 1 WHERE song_id = %s",
            (song_id,),
        )
    elif exists and exists["song_fave"] and not fave:
        db.c.update(
            "UPDATE r4_songs SET song_fave_count = song_fave_count - 1 WHERE song_id = %s",
            (song_id,),
        )
    cache.set_song_rating(song_id, user_id, {"rating_user": rating, "fave": fave})
    db.c.commit()
    return True
Пример #8
0
def set_song_rating(sid, song_id, user_id, rating=None, fave=None):
    db.c.start_transaction()
    try:
        existing_rating = db.c.fetch_row(
            "SELECT song_rating_user, song_fave FROM r4_song_ratings WHERE song_id = %s AND user_id = %s",
            (song_id, user_id),
        )
        count = db.c.fetch_var("SELECT COUNT(*) FROM r4_song_ratings WHERE user_id = %s", (user_id,))
        if not existing_rating:
            count += 1
        rank = db.c.fetch_var("SELECT COUNT(*) FROM phpbb_users WHERE radio_totalratings > %s", (count,))
        if existing_rating:
            if not rating:
                rating = existing_rating["song_rating_user"]
            if not fave:
                fave = existing_rating["song_fave"]
            db.c.update(
                "UPDATE r4_song_ratings "
                "SET song_rating_user = %s, song_fave = %s, song_rated_at = %s, song_rated_at_rank = %s, song_rated_at_count = %s "
                "WHERE user_id = %s AND song_id = %s",
                (rating, fave, timestamp(), rank, count, user_id, song_id),
            )
            db.c.update(
                "UPDATE phpbb_users SET radio_totalmindchange = radio_totalmindchange + 1, radio_inactive = FALSE, radio_last_active = %s WHERE user_id = %s",
                (timestamp(), user_id),
            )
        else:
            if not rating:
                rating = None
            if not fave:
                fave = None
            db.c.update(
                "INSERT INTO r4_song_ratings "
                "(song_rating_user, song_fave, song_rated_at, song_rated_at_rank, song_rated_at_count, user_id, song_id) "
                "VALUES (%s, %s, %s, %s, %s, %s, %s)",
                (rating, fave, timestamp(), rank, count, user_id, song_id),
            )

        db.c.update(
            "UPDATE phpbb_users SET radio_totalratings = %s, radio_inactive = FALSE, radio_last_active = %s WHERE user_id = %s",
            (count, timestamp(), user_id),
        )

        albums = update_album_ratings(sid, song_id, user_id)
        db.c.commit()
        cache.set_song_rating(song_id, user_id, {"rating_user": rating, "fave": fave})
        return albums
    except:
        db.c.rollback()
        raise
Пример #9
0
def set_album_fave(sid, album_id, user_id, fave):
    db.c.start_transaction()
    exists = db.c.fetch_row(
        "SELECT * FROM r4_album_ratings WHERE album_id = %s AND user_id = %s AND sid = %s",
        (album_id, user_id, sid))
    rating = None
    rating_complete = False
    if not exists:
        if db.c.update(
                "INSERT INTO r4_album_ratings (album_id, user_id, album_fave, sid) VALUES (%s, %s, %s, %s)",
            (album_id, user_id, fave, sid)) == 0:
            log.debug(
                "rating",
                "Failed to insert record for fave %s %s, fave is: %s." %
                ("album", album_id, fave))
            return False
    else:
        rating = exists["album" + "_rating_user"]
        rating_complete = exists['album_rating_complete']
        if db.c.update(
                "UPDATE r4_album_ratings SET album_fave = %s WHERE album_id = %s AND user_id = %s AND sid = %s",
            (fave, album_id, user_id, sid)) == 0:
            log.debug(
                "rating",
                "Failed to update record for fave %s %s, fave is: %s." %
                ("album", album_id, fave))
            return False
    if (not exists and fave) or (not exists["album" + "_fave"] and fave):
        db.c.update(
            "UPDATE r4_album_sid SET album_fave_count = album_fave_count + 1 WHERE album_id = %s AND sid = %s",
            (album_id, sid))
    elif (exists and exists["album" + "_fave"] and not fave):
        db.c.update(
            "UPDATE r4_album_sid SET album_fave_count = album_fave_count - 1 WHERE album_id = %s AND sid = %s",
            (album_id, sid))
    if "album" == "album":
        cache.set_album_rating(
            sid, album_id, user_id, {
                "rating_user": rating,
                "fave": fave,
                "rating_complete": rating_complete
            })
    elif "album" == "song":
        cache.set_song_rating(album_id, user_id, {
            "rating_user": rating,
            "fave": fave
        })
    db.c.commit()
    return True
Пример #10
0
def set_song_rating(song_id, user_id, rating=None, fave=None):
    existing_rating = db.c.fetch_row(
        "SELECT song_rating_user, song_fave FROM r4_song_ratings WHERE song_id = %s AND user_id = %s",
        (song_id, user_id))
    count = db.c.fetch_var(
        "SELECT COUNT(*) FROM r4_song_ratings WHERE user_id = %s", (user_id, ))
    if not existing_rating:
        count += 1
    rank = db.c.fetch_var(
        "SELECT COUNT(*) FROM phpbb_users WHERE radio_totalratings > %s",
        (count, ))
    if existing_rating:
        if not rating:
            rating = existing_rating["song_rating_user"]
        if not fave:
            fave = existing_rating["song_fave"]
        db.c.update(
            "UPDATE r4_song_ratings "
            "SET song_rating_user = %s, song_fave = %s, song_rated_at = %s, song_rated_at_rank = %s, song_rated_at_count = %s "
            "WHERE user_id = %s AND song_id = %s",
            (rating, fave, time.time(), rank, count, user_id, song_id))
    else:
        if not rating:
            rating = None
        if not fave:
            fave = None
        db.c.update(
            "INSERT INTO r4_song_ratings "
            "(song_rating_user, song_fave, song_rated_at, song_rated_at_rank, song_rated_at_count, user_id, song_id) "
            "VALUES (%s, %s, %s, %s, %s, %s, %s)",
            (rating, fave, time.time(), rank, count, user_id, song_id))

    db.c.update(
        "UPDATE phpbb_users SET radio_totalratings = %s WHERE user_id = %s",
        (count, user_id))
    cache.set_song_rating(song_id, user_id, {
        "rating_user": rating,
        "fave": fave
    })

    return update_album_ratings(song_id, user_id)
Пример #11
0
def _set_fave(category, object_id, user_id, fave):
	if category != "album" and category != "song":
		raise Exception("Invalid favourite category.")

	exists = db.c.fetch_row("SELECT * FROM r4_" + category + "_ratings WHERE " + category + "_id = %s AND user_id = %s", (object_id, user_id))
	rating = None
	rating_complete = None
	if not exists:
		if db.c.update("INSERT INTO r4_" + category + "_ratings (" + category + "_id, user_id, " + category + "_fave) VALUES (%s, %s, %s)", (object_id, user_id, fave)) == 0:
			return False
	else:
		rating = exists[category + "_rating_user"]
		if "album_rating_complete" in exists:
			rating_complete = exists['album_rating_complete']
		if db.c.update("UPDATE r4_" + category + "_ratings SET " + category + "_fave = %s WHERE " + category + "_id = %s AND user_id = %s", (fave, object_id, user_id)) == 0:
			return False
	if category == "album":
		cache.set_album_rating(object_id, user_id, { "rating_user": rating, "fave": fave, "rating_complete": rating_complete })
	elif category == "song":
		cache.set_song_rating(object_id, user_id, { "rating_user": rating, "fave": fave })
	return True
Пример #12
0
def _set_fave(category, object_id, user_id, fave):
    if category != "album" and category != "song":
        raise Exception("Invalid favourite category.")

    exists = db.c.fetch_row(
        "SELECT * FROM r4_" + category + "_ratings WHERE " + category +
        "_id = %s AND user_id = %s", (object_id, user_id))
    rating = None
    rating_complete = None
    if not exists:
        if db.c.update(
                "INSERT INTO r4_" + category + "_ratings (" + category +
                "_id, user_id, " + category + "_fave) VALUES (%s, %s, %s)",
            (object_id, user_id, fave)) == 0:
            return False
    else:
        rating = exists[category + "_rating_user"]
        if "album_rating_complete" in exists:
            rating_complete = exists['album_rating_complete']
        if db.c.update(
                "UPDATE r4_" + category + "_ratings SET " + category +
                "_fave = %s WHERE " + category + "_id = %s AND user_id = %s",
            (fave, object_id, user_id)) == 0:
            return False
    if category == "album":
        cache.set_album_rating(
            object_id, user_id, {
                "rating_user": rating,
                "fave": fave,
                "rating_complete": rating_complete
            })
    elif category == "song":
        cache.set_song_rating(object_id, user_id, {
            "rating_user": rating,
            "fave": fave
        })
    return True