public static string CalculateWithSubfolders(string folder, ILocalFileSystem localFileSystem) { IEnumerable <string> allFiles = localFileSystem.ListFiles(folder); var sb = new StringBuilder(); foreach (string file in allFiles.OrderBy(identity)) { sb.Append(file); sb.Append(localFileSystem.GetLastWriteTime(file).Ticks); } foreach (string subfolder in localFileSystem.ListSubdirectories(folder).OrderBy(identity)) { sb.Append(subfolder); sb.Append(Calculate(subfolder, localFileSystem)); } var hash = new StringBuilder(); byte[] bytes = Crypto.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString())); foreach (byte t in bytes) { hash.Append(t.ToString("x2")); } return(hash.ToString()); }
private async Task <Either <BaseError, MediaItemScanResult <Song> > > UpdateMetadata( MediaItemScanResult <Song> result, string ffprobePath) { try { Song song = result.Item; string path = song.GetHeadVersion().MediaFiles.Head().Path; bool shouldUpdate = Optional(song.SongMetadata).Flatten().HeadOrNone().Match( m => m.MetadataKind == MetadataKind.Fallback || m.DateUpdated != _localFileSystem.GetLastWriteTime(path), true); if (shouldUpdate) { song.SongMetadata ??= new List <SongMetadata>(); _logger.LogDebug("Refreshing {Attribute} for {Path}", "Metadata", path); if (await _localMetadataProvider.RefreshTagMetadata(song, ffprobePath)) { result.IsUpdated = true; } } return(result); } catch (Exception ex) { _client.Notify(ex); return(BaseError.New(ex.ToString())); } }
private async Task <Either <BaseError, MediaItemScanResult <Show> > > UpdateMetadataForShow( MediaItemScanResult <Show> result, string showFolder) { try { Show show = result.Item; Option <string> maybeNfo = LocateNfoFileForShow(showFolder); if (maybeNfo.IsNone) { if (!Optional(show.ShowMetadata).Flatten().Any()) { _logger.LogDebug("Refreshing {Attribute} for {Path}", "Fallback Metadata", showFolder); if (await _localMetadataProvider.RefreshFallbackMetadata(show, showFolder)) { result.IsUpdated = true; } } } foreach (string nfoFile in maybeNfo) { bool shouldUpdate = Optional(show.ShowMetadata).Flatten().HeadOrNone().Match( m => m.MetadataKind == MetadataKind.Fallback || m.DateUpdated != _localFileSystem.GetLastWriteTime(nfoFile), true); if (shouldUpdate) { _logger.LogDebug("Refreshing {Attribute} from {Path}", "Sidecar Metadata", nfoFile); if (await _localMetadataProvider.RefreshSidecarMetadata(show, nfoFile)) { result.IsUpdated = true; } } } return(result); } catch (Exception ex) { _client.Notify(ex); return(BaseError.New(ex.ToString())); } }
private async Task <Either <BaseError, MediaItemScanResult <Artist> > > UpdateMetadataForArtist( MediaItemScanResult <Artist> result, string artistFolder) { try { Artist artist = result.Item; await LocateNfoFileForArtist(artistFolder).Match( async nfoFile => { bool shouldUpdate = Optional(artist.ArtistMetadata).Flatten().HeadOrNone().Match( m => m.MetadataKind == MetadataKind.Fallback || m.DateUpdated != _localFileSystem.GetLastWriteTime(nfoFile), true); if (shouldUpdate) { _logger.LogDebug("Refreshing {Attribute} from {Path}", "Sidecar Metadata", nfoFile); if (await _localMetadataProvider.RefreshSidecarMetadata(artist, nfoFile)) { result.IsUpdated = true; } } }, async() => { if (!Optional(artist.ArtistMetadata).Flatten().Any()) { _logger.LogDebug("Refreshing {Attribute} for {Path}", "Fallback Metadata", artistFolder); if (await _localMetadataProvider.RefreshFallbackMetadata(artist, artistFolder)) { result.IsUpdated = true; } } }); return(result); } catch (Exception ex) { _client.Notify(ex); return(BaseError.New(ex.ToString())); } }
private async Task <bool> ApplyVersionUpdate(MediaItem mediaItem, MediaVersion version, string filePath) { MediaVersion mediaItemVersion = mediaItem.GetHeadVersion(); bool durationChange = mediaItemVersion.Duration != version.Duration; version.DateUpdated = _localFileSystem.GetLastWriteTime(filePath); return(await _metadataRepository.UpdateLocalStatistics(mediaItem, version) && durationChange); }
private async Task <Either <BaseError, MediaItemScanResult <Movie> > > UpdateMetadata( MediaItemScanResult <Movie> result) { try { Movie movie = result.Item; Option <string> maybeNfoFile = LocateNfoFile(movie); if (maybeNfoFile.IsNone) { if (!Optional(movie.MovieMetadata).Flatten().Any()) { string path = movie.MediaVersions.Head().MediaFiles.Head().Path; _logger.LogDebug("Refreshing {Attribute} for {Path}", "Fallback Metadata", path); if (await _localMetadataProvider.RefreshFallbackMetadata(movie)) { result.IsUpdated = true; } } } foreach (string nfoFile in maybeNfoFile) { bool shouldUpdate = Optional(movie.MovieMetadata).Flatten().HeadOrNone().Match( m => m.MetadataKind == MetadataKind.Fallback || m.DateUpdated != _localFileSystem.GetLastWriteTime(nfoFile), true); if (shouldUpdate) { _logger.LogDebug("Refreshing {Attribute} from {Path}", "Sidecar Metadata", nfoFile); if (await _localMetadataProvider.RefreshSidecarMetadata(movie, nfoFile)) { result.IsUpdated = true; } } } return(result); } catch (Exception ex) { _client.Notify(ex); return(BaseError.New(ex.ToString())); } }
private async Task <bool> ApplyVersionUpdate(MediaItem mediaItem, MediaVersion version, string filePath) { MediaVersion mediaItemVersion = mediaItem switch { Movie m => m.MediaVersions.Head(), Episode e => e.MediaVersions.Head(), _ => throw new ArgumentOutOfRangeException(nameof(mediaItem)) }; bool durationChange = mediaItemVersion.Duration != version.Duration; mediaItemVersion.DateUpdated = _localFileSystem.GetLastWriteTime(filePath); mediaItemVersion.Duration = version.Duration; mediaItemVersion.AudioCodec = version.AudioCodec; mediaItemVersion.SampleAspectRatio = version.SampleAspectRatio; mediaItemVersion.DisplayAspectRatio = version.DisplayAspectRatio; mediaItemVersion.Width = version.Width; mediaItemVersion.Height = version.Height; mediaItemVersion.VideoCodec = version.VideoCodec; mediaItemVersion.VideoProfile = version.VideoProfile; mediaItemVersion.VideoScanKind = version.VideoScanKind; return(await _metadataRepository.UpdateLocalStatistics(mediaItemVersion) && durationChange); }