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 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"); } } }