Ejemplo n.º 1
0
def log_track(track_id, djset_id, request=False, vinyl=False, new=False, rotation=None):
    track = TrackLog(
        track_id,
        djset_id,
        request=request,
        vinyl=vinyl,
        new=new,
        rotation=rotation,
        listeners=stream_listeners(app.config["ICECAST_ADMIN"]),
    )
    db.session.add(track)
    db.session.commit()

    artist = track.track.artist
    title = track.track.title
    album = track.track.album
    played = localize_datetime(track.played)

    from wuvt.trackman import tasks

    tasks.update_stream.delay(artist, title)
    tasks.update_tunein.delay(artist, title)
    tasks.update_lastfm.delay(artist, title, album, played)

    # send server-sent event
    sse.send(json.dumps({"event": "track_change", "tracklog": track.full_serialize()}, cls=JSONEncoder))

    return track
Ejemplo n.º 2
0
def generate_playlist_cuesheet(djset, ext):
    cuesheet = """\
PERFORMER "{dj}"
TITLE "{date}"
""".format(
        dj=email.utils.quote(djset.dj.airname.encode("utf-8")), date=format_datetime(djset.dtstart, "%Y-%m-%d %H:%M")
    )

    delta = timedelta(hours=1)
    start = djset.dtstart.replace(minute=0, second=0, microsecond=0)
    end = djset.dtend.replace(minute=59, second=59, microsecond=0) + timedelta(seconds=1)
    offset = 0

    for loghour in perdelta(start, end, delta):
        tracks = (
            TrackLog.query.filter(
                db.and_(TrackLog.djset_id == djset.id, TrackLog.played >= loghour, TrackLog.played <= loghour + delta)
            )
            .order_by(TrackLog.played)
            .all()
        )

        if len(tracks) > 0:
            filename = datetime.strftime(localize_datetime(loghour), "%Y%m%d%H0001{}".format(ext))
            cuesheet += generate_cuesheet(filename, loghour, tracks, offset)
            offset += len(tracks)

    return cuesheet