public static MusicDirectoryLayout CreateDownloadLayoutMusic(PlexMusic track, ApplicationOptions settings, int layout) { var dirLayout = new MusicDirectoryLayout(); if (layout == MF_PLEX_STANDARD_LAYOUT) { var basePath = settings.Generic.DownloadDirectory + @"\Music\"; var album = track.Album; var artist = track.Artist.ToClean(); var albumPath = basePath + artist + @"\" + album; var artistPath = basePath + artist; if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } if (!Directory.Exists(artistPath)) { Directory.CreateDirectory(artistPath); } if (!Directory.Exists(albumPath)) { Directory.CreateDirectory(albumPath); } dirLayout.ArtistPath = artistPath; dirLayout.AlbumPath = albumPath; dirLayout.BasePath = basePath; } return(dirLayout); }
public static DataTable MusicAttributesFromObject(PlexMusic content, bool silent = false) { var table = new DataTable("MusicAttributes"); var columnAttributeName = new DataColumn("Name", typeof(string)); var columnAttributeValue = new DataColumn("Value"); table.Columns.AddRange( new[] { columnAttributeName, columnAttributeValue }); try { var artist = new[] { "Artist", content.Artist }; var album = new[] { "Album", content.Album }; var genre = new[] { "Genre", content.ContentGenre }; var duration = new[] { "Duration", Methods.CalculateTime(content.StreamInformation.ContentDuration) }; var size = new[] { "File size", Methods.FormatBytes(content.StreamInformation.ByteLength) }; var container = new[] { "Container", content.StreamInformation.Container }; var newRows = new[] { artist, album, genre, duration, size, container }; foreach (object[] row in newRows) { table.Rows.Add(row); } } catch (Exception ex) { LoggingHelpers.RecordException(ex.Message, "AttributeTableError"); if (!silent) { UIMessages.Error("Error occurred whilst building content attribute table:\n\n" + ex, @"Data Error"); } } return(table); }
//MUSIC OBJECT BUILDER public static PlexMusic GetMusicObjectFromIndex(int index, bool waitWindow = true) { try { if (waitWindow) { return((PlexMusic)WaitWindow.WaitWindow.Show(GetMusicObjectFromIndex_Callback, @"Getting metadata", index)); } var obj = new PlexMusic(); LoggingHelpers.RecordGeneralEntry(@"Content Parse Started"); LoggingHelpers.RecordGeneralEntry(@"Grabbing Titles"); var metadata = XmlMetadataContent.GetTrackMetadata(index); LoggingHelpers.RecordGeneralEntry(@"Checking XML validity"); if (Methods.PlexXmlValid(metadata.Xml)) { LoggingHelpers.RecordGeneralEntry(@"XML Valid"); //UIMessages.Info(ObjectProvider.CurrentContentType.ToString()); var dlInfo = DownloadInfoGatherers.GetContentDownloadInfo(metadata.Xml); if (dlInfo != null) { LoggingHelpers.RecordGeneralEntry(@"Assembling Object"); obj.ApiUri = metadata.ApiUri; obj.ContentGenre = XmlMetadataStrings.GetContentGenre(metadata.Xml); obj.StreamInformation = dlInfo; obj.StreamResolution = new Resolution(); //audio doesn't have video-type resolution obj.Actors = new List <PlexActor>(); //Plex audio does not contain the "<Role>" tag obj.StreamIndex = index; obj.Album = XmlMetadataStrings.GetParentTitle(metadata.Xml); obj.Artist = XmlMetadataStrings.GetGrandparentTitle(metadata.Xml); obj.Synopsis = "Auditory Content"; //Plex audio does not contain the "summary" attribute //apply the raw metadata to the object (it won't get serialised) obj.RawMetadata = metadata.Xml; } else { UIMessages.Error( @"Failed to get contextual information; an unknown error occurred. Check the exception log for more information.", @"Data Error"); LoggingHelpers.RecordException( @"DownloadInfo invalid. This may be an internal error; please report this issue on GitHub.", @"ContextDownloadInfoNull"); LoggingHelpers.RecordGeneralEntry("DownloadInfo is invalid (no stream contextual information)"); } } else { LoggingHelpers.RecordGeneralEntry("XML Invalid"); } LoggingHelpers.RecordGeneralEntry("Returned assembled Music object"); return(obj); } catch (ThreadAbortException) { //literally nothing; this gets raised when a cancellation happens. return(null); } catch (Exception ex) { UIMessages.Error("Content metadata error:\n\n" + ex, @"Data Error"); LoggingHelpers.RecordException(ex.Message, @"MusicObjectError"); return(null); } }