public static void Index() { using (IDataSession session = new SongSearchDataSession()) { var contents = session.All<Content>().Where(x => x.Lyrics != null); foreach (var content in contents) { content.LyricsIndex = content.Lyrics.MakeIndexValue(); } session.CommitChanges(); } }
public static void UpdateMediaRemoteStatus() { using (_amazon = new AmazonCloudService()) { using (var session = new SongSearchDataSession()) { var contents = session.All<Content>().Where(c => c.HasMediaFullVersion).ToList(); var remoteContents = _amazon.GetContentList(MediaVersion.Full); foreach (var content in contents) { string key = _amazon.GetContentKey(content.ContentMedia.FullVersion()); var remoteObject = remoteContents.FirstOrDefault(x => x.Key == key); if (remoteObject == null) { content.IsMediaOnRemoteServer = false; Console.WriteLine(String.Format("{0} '{1}' - {2}", content.ContentId, content.Title, "----------------------> missing")); } else { content.IsMediaOnRemoteServer = true; } //Console.WriteLine(String.Format("{0} '{1}' - {2}", content.ContentId, // content.Title, // remoteObject != null ? "synced!" : "----------------------> missing")); if (remoteObject != null) { } else { } } session.CommitChanges(); Console.WriteLine("Done sync'ing"); } } }
public static void CleanID3() { using (var session = new SongSearchDataSession()) { var contents = session.GetObjectQuery<Content>() .Include("ContentMedia").ToList(); foreach (var content in contents.AsParallel()) { foreach (var media in content.ContentMedia.AsParallel()) { string mediaFile = MediaService.GetContentMediaPathLocal(media); // Path.Combine(previewPath, String.Concat(content.ContentId, ".mp3")); var file = new FileInfo(mediaFile); if (file.Exists) { var tag = ID3v2Helper.CreateID3v2(file.FullName); ID3v2Helper.RemoveTag(file.FullName); var newTag = ID3v2Helper.CreateID3v2(); newTag.Title = content.Title; newTag.Artist = content.Artist; newTag.OriginalArtist = content.Artist; newTag.Year = content.ReleaseYear.HasValue ? content.ReleaseYear.Value.ToString() : ""; newTag.OriginalReleaseYear = newTag.Year; newTag.LengthMilliseconds = tag.LengthMilliseconds ?? (int?)media.MediaLength; newTag.Save(file.FullName); file.Refresh(); var dbMedia = session.Single<ContentMedia>(x => x.ContentId == media.ContentId && x.MediaVersion == (int)media.MediaVersion); dbMedia.MediaSize = file.Length; dbMedia.MediaLength = newTag.LengthMilliseconds; session.CommitChanges(); } } } } }
//public static void MakeTags() { // //_session = new SongSearchDataSession(); // var ctx = new SongSearchContext(); // var import = ctx.Import_SongData; // foreach (var row in import) { // MakeATag(row.SongID, row.SoundsLike, TagType.SoundsLike); // MakeATag(row.SongID, row.Instrumentation, TagType.Instrument); // //_session.CommitChanges(); // } //} public static void ConvertTextTags() { using (var session = new SongSearchDataSession()) { var contents = session.All<Content>(); var tags = session.All<Tag>(); foreach (var content in contents) { var instruments = content.Tags.Where(t => t.TagTypeId == (int)TagType.Instrument); var soundsLike = content.Tags.Where(t => t.TagTypeId == (int)TagType.SoundsLike); content.Instruments = instruments.Count() > 0 ? String.Join(";", instruments.Select(t => t.TagName).ToArray()) : null; content.SoundsLike = soundsLike.Count() > 0 ? String.Join(";", soundsLike.Select(t => t.TagName).ToArray()) : null; } session.CommitChanges(); } }
public static void Upload(MediaVersion version) { using (_amazon = new AmazonCloudService()) { using (var session = new SongSearchDataSession()) { var contents = session.All<Content>().ToList(); var remoteContents = _amazon.GetContentList(version); var remoteFolder = _amazon.GetContentPrefix(version); foreach (var content in contents) { var dbContent = session.Single<Content>(c => c.ContentId == content.ContentId); var key = _amazon.GetContentKey(content.Media(version)); var filePath = Path.Combine(version == MediaVersion.Full ? SystemConfig.MediaPathFull : SystemConfig.MediaPathPreview, String.Concat(content.ContentId,SystemConfig.MediaDefaultExtension) ); var file = new FileInfo(filePath); if (file.Exists) { var remoteFile = remoteContents.SingleOrDefault(x => x.Key == key && x.Size == file.Length); if (remoteFile == null) { try { Console.WriteLine("Uploading " + file.Name + " to " + remoteFolder); _amazon.PutContentMedia(file.FullName, content.Media(version)); dbContent.IsMediaOnRemoteServer = true; } catch (Exception ex){ Console.WriteLine("FAILED: " + file.Name + "-------------------"); Console.WriteLine("ERROR: " + ex.Message); dbContent.IsMediaOnRemoteServer = false; } } else { dbContent.IsMediaOnRemoteServer = true; } } else { dbContent.IsMediaOnRemoteServer = false; } session.CommitChanges(); } Console.WriteLine("Done uploading"); } } }
//private static IQueryable<Tag> _tags; //private static IDataSession _session; public static void GetID3() { string fullpath = @"D:\Inetpub\wwwroot\Assets\Music\Full"; string previewPath = @"D:\Inetpub\wwwroot\Assets\Music\Previews"; using (var session = new SongSearchDataSession()) { var contents = session.All<Content>(); foreach (var content in contents) { string full = Path.Combine(fullpath, String.Concat(content.ContentId, ".mp3")); var file = new FileInfo(full); if (file.Exists) { var tag = ID3v2Helper.CreateID3v2(full); //content.HasMediaFullVersion = true; //content.MediaSize = file.Length; //content.MediaLength = tag.LengthMilliseconds; //content.MediaDate = file.LastWriteTime > DateTime.MinValue ? file.LastWriteTime : DateTime.Now; //if (!content.MediaDate.HasValue) { content.MediaDate = DateTime.Now; } //content.MediaType = tag.FileType ?? content.MediaType; //content.MediaBitRate = tag.LengthMilliseconds != null ? // ((long)tag.LengthMilliseconds).ToBitRate(content.MediaSize.GetValueOrDefault()) : 0; //if (content.MediaBitRate >= 160) { // System.Diagnostics.Debug.WriteLine(content.MediaBitRate); //} } else { //content.HasMediaFullVersion = false; } if (File.Exists(Path.Combine(previewPath, String.Concat(content.ContentId, ".mp3")))) { content.HasMediaPreviewVersion = true; } else { content.HasMediaPreviewVersion = false; } } session.CommitChanges(); } }