private async Task <byte[]> TrackBytesAndMarkPlayed(int releaseId, data.Track track, string trackToken) { var results = await TrackService.TrackStreamInfo(track.RoadieId, 0, SafeParser.ToNumber <long>(track.FileSize), null).ConfigureAwait(false); // Some DLNA clients call for the track file several times for each play if (ShouldMakeScrobble(trackToken)) { await PlayActivityService.Scrobble(null, new Library.Scrobble.ScrobbleInfo { TrackId = track.RoadieId, TimePlayed = DateTime.UtcNow }).ConfigureAwait(false); } return(results.Data.Bytes); }
public async Task <IActionResult> Scrobble(Guid id, string startedPlaying, bool isRandom) { var result = await PlayActivityService.Scrobble(await CurrentUserModel().ConfigureAwait(false), new ScrobbleInfo { TrackId = id, TimePlayed = SafeParser.ToDateTime(startedPlaying) ?? DateTime.UtcNow, IsRandomizedScrobble = isRandom }).ConfigureAwait(false); if (result?.IsNotFoundResult != false) { return(NotFound()); } if (!result.IsSuccess) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } return(Ok(result)); }
public async Task <IActionResult> Scrobble(SubsonicRequest request) { var authResult = await AuthenticateUser(request).ConfigureAwait(false); if (authResult != null) { return(authResult); } var timePlayed = string.IsNullOrEmpty(request.time) ? DateTime.UtcNow.AddDays(-1) : SafeParser.ToNumber <long>(request.time).FromUnixTime(); var scrobblerResponse = await PlayActivityService.Scrobble(SubsonicUser, new ScrobbleInfo { TrackId = request.TrackId.Value, TimePlayed = timePlayed }).ConfigureAwait(false); return(BuildResponse(request, new SubsonicOperationResult <Response> { IsSuccess = scrobblerResponse.IsSuccess, Data = new Response() })); }