/// <summary> /// Creates a media object. /// </summary> /// <param name="title">The title of the object.</param> /// <param name="file">The full path to the file.</param> /// <returns>Media object.</returns> private static IDvMedia CreateObject(string title, string file) { var fi = new FileInfo(file); var media = DvMediaBuilder.CreateItem(new MediaBuilder.item(title)); string mime, mediaClass; MimeTypes.ExtensionToMimeType(fi.Extension, out mime, out mediaClass); var resInfo = new ResourceBuilder.VideoItem { contentUri = MediaResource.AUTOMAPFILE + fi.FullName, protocolInfo = new ProtocolInfoString("http-get:*:" + mime + ":*"), size = new _ULong((ulong)fi.Length) }; var res = DvResourceBuilder.CreateResource(resInfo, true); res.Tag = fi; media.AddResource(res); if (_mimes.Contains(mime) == false) { _mimes.Add(mime); var ps = new ProtocolInfoString[_mimes.Count]; var i = 0; foreach (var mime2 in _mimes) { ps[i++] = new ProtocolInfoString("http-get:*:" + mime2 + ":*"); } _ms.SourceProtocolInfoSet = ps; } return(media); }
/// <summary> /// Resets the hierarchy from the root. /// </summary> public static void RebuildList() { if (!Signature.IsActivated && IsRunning) { Stop(); return; } var st = DateTime.Now; Log.Debug("Rebuilding UPnP/DLNA library..."); MediaBuilder.SetNextID(0); var allEps = DvMediaBuilder.CreateContainer(new MediaBuilder.container("-- All Episodes --") { IsRestricted = true }); var unwEps = DvMediaBuilder.CreateContainer(new MediaBuilder.container("-- Unwatched Episodes --") { IsRestricted = true }); _ms.Root.AddObject(allEps, true); _ms.Root.AddObject(unwEps, true); var shows = new Dictionary <int, DvMediaContainer>(); foreach (var tvs in Database.TVShows.OrderBy(t => t.Value.Title)) { shows[tvs.Key] = DvMediaBuilder.CreateContainer(new MediaBuilder.container(tvs.Value.Title) { IsRestricted = true }); } foreach (var item in Library.Files) { var sid = (int)Math.Floor((double)item.Key / 1000 / 1000); TVShow show; if (!Database.TVShows.TryGetValue(sid, out show)) { continue; } Episode ep; if (!show.EpisodeByID.TryGetValue(item.Key - (sid * 1000 * 1000), out ep)) { continue; } var txt = string.Format("S{0:00}E{1:00}: {2}", ep.Season, ep.Number, ep.Title); foreach (var file in Library.Files[item.Key]) { if (OpenArchiveTaskDialog.SupportedArchives.Contains(Path.GetExtension(file).ToLower())) { continue; } var ltxt = txt; var q = FileNames.Parser.ParseQuality(file); if (q != Qualities.Unknown) { ltxt += " [" + q.GetAttribute <DescriptionAttribute>().Description + "]"; } else { var ed = FileNames.Parser.ParseEdition(file); if (ed != Editions.Unknown) { ltxt += " [" + ed.GetAttribute <DescriptionAttribute>().Description + "]"; } else { ltxt += " [" + Path.GetExtension(file) + "]"; } } allEps.AddBranch(CreateObject(show.Title + " " + ltxt, file)); if (!ep.Watched) { unwEps.AddBranch(CreateObject(show.Title + " " + ltxt, file)); } shows[sid].AddBranch(CreateObject(ltxt, file)); } } foreach (var tvs in shows) { if (tvs.Value.ChildCount != 0) { _ms.Root.AddObject(tvs.Value, true); } } Log.Debug("Rebuilt UPnP/DLNA library in " + (DateTime.Now - st).TotalSeconds + "s, all episodes menu has " + allEps.ChildCount + " entries."); }