Ejemplo n.º 1
0
def spotify_get_track_features():
    from powersong.tasks import spotify_task
    songs = Song.objects.exclude(spotify_id=None)

    songs_to_sync = []
    track_ids = []
    for song in songs:
        if song.bpm == -1:
            track_ids.append(song.spotify_id)
            if len(track_ids) == 50:
                songs_to_sync.append(
                    spotify_task.s('spotify_multi_track_get_stats',
                                   (track_ids, )))
                track_ids = []

    if track_ids:
        songs_to_sync.append(
            spotify_task.s('spotify_multi_track_get_stats', (track_ids, )))

    if len(songs_to_sync) > 1:
        promise = group(*songs_to_sync)
        job_result = promise.delay()
        job_result.save()
    else:
        promise = songs_to_sync[0]
        job_result = promise.delay()

    return job_result.id, len(songs_to_sync)
Ejemplo n.º 2
0
def resync_activity_spotify(activity_id, athlete_id):
    ath = strava_get_user_info(id=athlete_id)

    client = stravalib.client.Client()
    client.access_token = ath.strava_token
    client.refresh_token = ath.strava_refresh_token
    client.token_expires_at = ath.strava_token_expires_at

    if not ath.strava_token_expires_at:
        return "00000000-0000-0000-0000-000000000000", 0

    activity = strava_get_activity_by_id(activity_id)

    if athlete_id != activity.athlete.athlete_id:
        return None, None

    efforts_to_delete = Effort.objects.filter(
        activity__activity_id=activity_id)
    efforts_to_delete.delete()
    act_p = {}
    act_p['id'] = activity_id
    act_p['athlete_id'] = athlete_id
    download_chain = chain(
        strava_task.si('strava_download_activity', (act_p, )),
        spotify_task.s('spotify_download_activity_tracks', (True, )),
        activity_to_efforts.s())
    job_result = download_chain.delay()

    return job_result.id, 1
Ejemplo n.º 3
0
def spotify_sync_ids():
    from powersong.tasks import spotify_task
    songs = Song.objects.all()

    poweruser = PowerUser.objects.all()[0]

    code = poweruser.listener_spotify.spotify_code
    token = poweruser.listener_spotify.spotify_token
    reftoken = poweruser.listener_spotify.spotify_refresh_token

    songs_to_sync = []
    for song in songs:
        if not song.spotify_id:
            songs_to_sync.append(
                spotify_task.s('spotify_get_spotify_ids',
                               (code, token, reftoken, song.id)))

    if len(songs_to_sync) > 1:
        promise = group(*songs_to_sync)
        job_result = promise.delay()
        job_result.save()
    else:
        promise = songs_to_sync[0]
        job_result = promise.delay()

    return job_result.id, len(songs_to_sync)
Ejemplo n.º 4
0
def spotify_sync_artists():
    from powersong.tasks import spotify_task
    artists = Artist.objects.all()
    artists_to_sync = []
    for artist in artists:
        if artist.spotify_id:
            artists_to_sync.append(
                spotify_task.s('spotify_update_artist', (artist.id, )))
    if len(artists_to_sync) > 1:
        promise = group(*artists_to_sync)
        job_result = promise.delay()
        job_result.save()
    else:
        promise = artists_to_sync[0]
        job_result = promise.delay()

    return job_result.id, len(artists_to_sync)
Ejemplo n.º 5
0
def spotify_sync_tracks():
    from powersong.tasks import spotify_task
    songs = Song.objects.all()
    songs_to_sync = []
    for song in songs:
        if song.spotify_id:
            songs_to_sync.append(
                spotify_task.s('spotify_update_track', (song.id, )))
    if len(songs_to_sync) > 1:
        promise = group(*songs_to_sync)
        job_result = promise.delay()
        job_result.save()
    else:
        promise = songs_to_sync[0]
        job_result = promise.delay()

    return job_result.id, len(songs_to_sync)
Ejemplo n.º 6
0
def sync_one_activity_spotify(activity_id, athlete_id, delay=0):
    athlete = strava_get_user_info(id=athlete_id)

    client = stravalib.client.Client()
    client.access_token = athlete.strava_token
    client.refresh_token = athlete.strava_refresh_token
    client.token_expires_at = athlete.strava_token_expires_at

    if not athlete.strava_token_expires_at:
        return "00000000-0000-0000-0000-000000000000", 0

    act_p = strava_parse_base_activity(client.get_activity(activity_id))
    download_chain = chain(
        strava_task.si('strava_download_activity', (act_p, )),
        spotify_task.s('spotify_download_activity_tracks', (True, )),
        activity_to_efforts.s(),
        strava_task.s('strava_send_song_activities', ()))
    job_result = download_chain.apply_async(countdown=delay)

    return job_result.id, 1