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 StartAsync(CancellationToken cancellationToken) { if (!Configuration.Dlna.IsEnabled) { Logger.LogInformation("DLNA service disabled."); return; } var server = new HttpServer(LoggerFactory.CreateLogger("HttpServer"), Configuration.Dlna.Port ?? 0); _authorizer = new HttpAuthorizer(server); if (Configuration.Dlna.AllowedIps.Any()) { _authorizer.AddMethod(new IPAddressAuthorizer(Configuration.Dlna.AllowedIps)); } if (Configuration.Dlna.AllowedUserAgents.Any()) { _authorizer.AddMethod(new UserAgentAuthorizer(Configuration.Dlna.AllowedUserAgents)); } DbContext = DbContextFactory.Create(Configuration); var defaultNotFoundImages = new DefaultNotFoundImages(LoggerFactory.CreateLogger("DefaultNotFoundImages"), Configuration); var imageService = new ImageService(Configuration, DbContext, CacheManager, LoggerFactory.CreateLogger("ImageService"), defaultNotFoundImages); var trackService = new TrackService(Configuration, DbContext, CacheManager, LoggerFactory.CreateLogger("TrackService")); var roadieScrobbler = new RoadieScrobbler(Configuration, LoggerFactory.CreateLogger("RoadieScrobbler"), DbContext, CacheManager); var scrobbleHandler = new ScrobbleHandler(Configuration, LoggerFactory.CreateLogger("ScrobbleHandler"), DbContext, CacheManager, roadieScrobbler); var playActivityService = new PlayActivityService(Configuration, DbContext, CacheManager, LoggerFactory.CreateLogger("PlayActivityService"), scrobbleHandler); var rs = new DlnaService(Configuration, DbContext, CacheManager, LoggerFactory.CreateLogger("DlnaService"), imageService, trackService, playActivityService); rs.Preload(); server.RegisterMediaServer(Configuration, LoggerFactory.CreateLogger("MediaMount"), rs); while (!cancellationToken.IsCancellationRequested) { await Task.Delay(5000, cancellationToken); } }
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() })); }