public SavedAlbums() { logger = new DebugLogger(); mediaFactory = new MediaFactory(logger); securityContext = new SecurityContext(mediaFactory); mediaType = mediaFactory.GetMediaType("application/vnd.gnosis.album"); album1 = new Album(new IdentityInfo(Guid.NewGuid().ToUrn(), mediaType, "OK Computer", string.Empty, new DateTime(1997, 9, 22), new DateTime(1997, 9, 22), 0), SizeInfo.Default, new CreatorInfo(new Uri(radioheadUrn), "Radiohead"), CatalogInfo.Default, TargetInfo.Default, UserInfo.Default, new ThumbnailInfo(new Uri("http://example.com/image1.jpg"), new byte[0])); album2 = new Album(new IdentityInfo(Guid.NewGuid().ToUrn(), mediaType, "Undertow", string.Empty, new DateTime(1992, 3, 28), new DateTime(1992, 3, 28), 0), SizeInfo.Default, new CreatorInfo(Guid.NewGuid().ToUrn(), "Tool"), CatalogInfo.Default, TargetInfo.Default, UserInfo.Default, new ThumbnailInfo(new Uri("http://example.com/image2.jpg"), new byte[0])); album3 = new Album(new IdentityInfo(Guid.NewGuid().ToUrn(), mediaType, "Free", string.Empty, new DateTime(2002, 7, 9), new DateTime(2002, 7, 9), 0), SizeInfo.Default, new CreatorInfo(Guid.NewGuid().ToUrn(), "Cat Power"), CatalogInfo.Default, TargetInfo.Default, UserInfo.Default, new ThumbnailInfo(new Uri("http://example.com/image3.jpg"), new byte[0])); album4 = new Album(new IdentityInfo(Guid.NewGuid().ToUrn(), mediaType, "White Chalk", string.Empty, new DateTime(2008, 4, 30), new DateTime(2008, 4, 30), 0), SizeInfo.Default, new CreatorInfo(Guid.NewGuid().ToUrn(), "PJ Harvey"), CatalogInfo.Default, TargetInfo.Default, UserInfo.Default, new ThumbnailInfo(new Uri("http://example.com/image4.jpg"), new byte[0])); album5 = new Album(new IdentityInfo(Guid.NewGuid().ToUrn(), mediaType, "Pablo Honey", string.Empty, new DateTime(1993, 4, 4), new DateTime(1993, 4, 4), 0), SizeInfo.Default, new CreatorInfo(new Uri(radioheadUrn), "Radiohead"), CatalogInfo.Default, TargetInfo.Default, UserInfo.Default, new ThumbnailInfo(new Uri("http://example.com/image5.jpg"), new byte[0])); connection = connectionFactory.Create(connectionString); connection.Open(); repository = new SQLiteMetadataRepository(logger, securityContext, mediaFactory, connection); repository.Initialize(); repository.Save(new List<IAlbum> { album1, album2, album5 }); }
private void SaveMediaItems(IVideo video) { try { var artist = video.GetArtist(securityContext, mediaFactory, mediaItemRepository); mediaItemRepository.Save(new List<IArtist> { artist }); tagRepository.Save(artist.GetTags()); var album = video.GetAlbum(securityContext, mediaFactory, mediaItemRepository, artist); mediaItemRepository.Save(new List<IAlbum> { album }); tagRepository.Save(album.GetTags()); var clip = video.GetClip(securityContext, mediaFactory, mediaItemRepository, artist, album); mediaItemRepository.Save(new List<IClip> { clip }); tagRepository.Save(clip.GetTags()); var clipDate = clip.FromDate > DateTime.MinValue ? clip.FromDate : clip.ToDate; if (album.FromDate == DateTime.MinValue && clipDate != DateTime.MinValue) { var identityInfo = new IdentityInfo(album.Location, album.Type, album.Name, album.Summary, clipDate, clipDate, album.Number); var sizeInfo = new SizeInfo(album.Duration, album.Height, album.Width); var creatorInfo = new CreatorInfo(album.Creator, album.CreatorName); var catalogInfo = new CatalogInfo(album.Catalog, album.CatalogName); var targetInfo = new TargetInfo(album.Target, album.TargetType); var userInfo = new UserInfo(album.User, album.UserName); var thumbnailInfo = new ThumbnailInfo(album.Thumbnail, album.ThumbnailData); album = new Album(identityInfo, sizeInfo, creatorInfo, catalogInfo, targetInfo, userInfo, thumbnailInfo); mediaItemRepository.Save(new List<IAlbum> { album }); } } catch (Exception ex) { logger.Error(" CatalogSpider.SaveMediaItems", ex); } }
private void SaveMediaItems(IAudio audio) { try { var artist = audio.GetArtist(securityContext, mediaFactory, mediaItemRepository); mediaItemRepository.Save(new List<IArtist> { artist }); tagRepository.Save(artist.GetTags()); var album = audio.GetAlbum(securityContext, mediaFactory, mediaItemRepository, artist); mediaItemRepository.Save(new List<IAlbum> { album }); tagRepository.Save(album.GetTags()); var track = audio.GetTrack(securityContext, mediaFactory, mediaItemRepository, audioStreamFactory, artist, album); mediaItemRepository.Save(new List<ITrack> { track }); tagRepository.Save(track.GetTags()); var trackDate = track.FromDate > DateTime.MinValue ? track.FromDate : track.ToDate; if (album.FromDate == DateTime.MinValue && trackDate != DateTime.MinValue) { var identityInfo = new IdentityInfo(album.Location, album.Type, album.Name, album.Summary, trackDate, trackDate, album.Number); var sizeInfo = new SizeInfo(album.Duration, album.Height, album.Width); var creatorInfo = new CreatorInfo(album.Creator, album.CreatorName); var catalogInfo = new CatalogInfo(album.Catalog, album.CatalogName); var targetInfo = new TargetInfo(album.Target, album.TargetType); var userInfo = new UserInfo(album.User, album.UserName); var thumbnailInfo = new ThumbnailInfo(album.Thumbnail, album.ThumbnailData); album = new Album(identityInfo, sizeInfo, creatorInfo, catalogInfo, targetInfo, userInfo, thumbnailInfo); mediaItemRepository.Save(new List<IAlbum> { album }); } //if (album.ToDate == DateTime.MinValue && track.ToDate != DateTime. if (!HasDefaultThumbnail(track)) { if (HasDefaultThumbnail(album)) { //var fromDate = album.FromDate; //if (album.FromDate == DateTime.MinValue || album.FromDate == DateTime.MaxValue) //{ // fromDate = track.ToDate != DateTime.MinValue && track.ToDate != DateTime.MaxValue ? // track.ToDate // : track.FromDate; //} var number = album.Number; if (album.Name.Contains("#") && !album.Name.EndsWith("#")) { var suffix = album.Name.Substring(album.Name.LastIndexOf('#') + 1).Trim(); uint.TryParse(suffix, out number); } else if (album.Name.Contains("(") && !album.Name.EndsWith("(")) { var suffix = album.Name.Substring(album.Name.LastIndexOf("(") + 1); var cleaned = System.Text.RegularExpressions.Regex.Replace(suffix, "[^0-9]", string.Empty); uint.TryParse(cleaned, out number); } var identityInfo = new IdentityInfo(album.Location, album.Type, album.Name, album.Summary, album.FromDate, album.ToDate, number); var sizeInfo = new SizeInfo(album.Duration, album.Height, album.Width); var creatorInfo = new CreatorInfo(album.Creator, album.CreatorName); var catalogInfo = new CatalogInfo(album.Catalog, album.CatalogName); var targetInfo = new TargetInfo(album.Target, album.TargetType); var userInfo = new UserInfo(album.User, album.UserName); var thumbnailInfo = new ThumbnailInfo(track.Thumbnail, track.ThumbnailData); var updated = new Album(identityInfo, sizeInfo, creatorInfo, catalogInfo, targetInfo, userInfo, thumbnailInfo); mediaItemRepository.Save(new List<IAlbum> { updated }); } } } catch (Exception ex) { logger.Error(" SaveMediaItems", ex); } }