// Helper TVProgramme TVProgrammeFromWtvFile(string filename) { TVProgramme tvp = new TVProgramme(); tvp.isGeneratedFromFile = true; DvrmsMetadataEditor MetaEd = new DvrmsMetadataEditor(filename); try { tvp.Filename = filename; Dictionary<string, MetadataItem> attributes = new Dictionary<string, MetadataItem>(); if (!MetaEd.GetMetaData(ref attributes)) return null; // Title if (attributes.ContainsKey("Title")) { MetadataItem Mtitle = attributes["Title"]; tvp.Title = (string)Mtitle.Value; } else tvp.Title = "Untitled Show"; /* if (attributes.ContainsKey("WM/WMRVProgramID")) { // Use the file ID as it will persist MetadataItem Mid = attributes["WM/WMRVProgramID"]; string strID = (string)Mid.Value; // Strip any !! bit int locExcl = strID.LastIndexOf("!"); if (locExcl > 0) tvp.Id = strID.Substring(locExcl + 1); else tvp.Id = strID; } else */ // THIS WAS CAUSING SD AND HD SHOWS TO MERGE { // Make up an ID Random r = new Random(); int iRan = r.Next(100000000, 900000000); string addendum = ""; if ((tvp.Title != null) && (tvp.Title.Length > 4)) addendum += tvp.Title.Substring(0, 3); tvp.Id = iRan.ToString() + addendum; } // Episode Title if (attributes.ContainsKey("WM/SubTitle")) { MetadataItem Msubtitle = attributes["WM/SubTitle"]; if (Msubtitle.Value != null) tvp.EpisodeTitle = (string)Msubtitle.Value; } else tvp.EpisodeTitle = ""; // Description if (attributes.ContainsKey("WM/SubTitleDescription")) { MetadataItem Mdesc = attributes["WM/SubTitleDescription"]; if (Mdesc.Value != null) tvp.Description = (string)Mdesc.Value; } if (attributes.ContainsKey("WM/MediaIsSport")) { MetadataItem Msport = attributes["WM/MediaIsSport"]; if (Msport.Value != null) { bool isSport = (bool)Msport.Value; if (isSport) tvp.ProgramType = TVProgrammeType.Sport; } } if (attributes.ContainsKey("WM/MediaIsMovie")) { MetadataItem MisMovie = attributes["WM/MediaIsMovie"]; if (MisMovie.Value != null) { bool isMovie = (bool)MisMovie.Value; if (isMovie) tvp.ProgramType = TVProgrammeType.Movie; } } if (attributes.ContainsKey("WM/WMRVEncodeTime")) { MetadataItem Mdate = attributes["WM/WMRVEncodeTime"]; if (Mdate.Value != null) { try { long tickTime = (long)Mdate.Value; DateTime TheStartTime = new DateTime(tickTime, DateTimeKind.Utc); tvp.StartTime = TheStartTime.Ticks; } catch (Exception ex) { Functions.WriteLineToLogFile("Error setting start time from WTV metadata for file " + filename); Functions.WriteExceptionToLogFile(ex); } } } else { Functions.WriteLineToLogFile("No start time in WTV metadata for file " + filename + " - using current time."); tvp.StartTime = DateTime.Now.ToUniversalTime().Ticks; } if (attributes.ContainsKey("WM/WMRVEndTime")) { MetadataItem Menddate = attributes["WM/WMRVEndTime"]; if (Menddate.Value != null) { long tickTime = (long)Menddate.Value; DateTime TheEndTime = new DateTime(tickTime, DateTimeKind.Utc); tvp.StopTime = TheEndTime.Ticks; } } else { Functions.WriteLineToLogFile("No end time in WTV metadata for file " + filename + " - using current time plus 5 seconds."); tvp.StopTime = DateTime.Now.AddMinutes(5).ToUniversalTime().Ticks; } if (attributes.ContainsKey("WM/WMRVContentProtectedPercent")) { MetadataItem Mprotected = attributes["WM/WMRVContentProtectedPercent"]; if (Mprotected.Value != null) { int percentProtected = (int)Mprotected.Value; if (percentProtected > 0) tvp.IsDRMProtected = true; } } if (attributes.ContainsKey("WM/MediaStationCallSign")) { MetadataItem Mchannel = attributes["WM/MediaStationCallSign"]; if (Mchannel.Value != null) { tvp.WTVCallsign = (string)Mchannel.Value; } } // Only populate if we don't already have a callsign if (string.IsNullOrEmpty(tvp.WTVCallsign)) { if (attributes.ContainsKey("WM/MediaStationName")) // Added by request: also use station name { MetadataItem Mchanname = attributes["WM/MediaStationName"]; if (Mchanname.Value != null) tvp.WTVCallsign = (string)Mchanname.Value; } else { tvp.WTVCallsign = "Unknown channel."; } } if (attributes.ContainsKey("WM/WMRVSeriesUID")) { MetadataItem MSeriesUID = attributes["WM/WMRVSeriesUID"]; if (MSeriesUID.Value != null) tvp.IsSeries = !String.IsNullOrEmpty((string)MSeriesUID.Value); } if (attributes.ContainsKey("WM/WMRVHDContent")) { MetadataItem MisHD = attributes["WM/WMRVHDContent"]; if (MisHD.Value != null) tvp.IsHD = (bool)MisHD.Value; } if (attributes.ContainsKey("WM/MediaIsSubtitled")) { MetadataItem MisSubT = attributes["WM/MediaIsSubtitled"]; if (MisSubT.Value != null) tvp.HasSubtitles = (bool)MisSubT.Value; } // Original date if (attributes.ContainsKey("WM/MediaOriginalBroadcastDateTime")) { MetadataItem Morigdate = attributes["WM/MediaOriginalBroadcastDateTime"]; if (Morigdate.Value != null) { string strOrigDate = (string)Morigdate.Value; if (!string.IsNullOrWhiteSpace(strOrigDate)) { DateTime dtOrigDate; if (DateTime.TryParse(strOrigDate, out dtOrigDate)) { tvp.OriginalAirDate = dtOrigDate.ToUniversalTime().Ticks; } else { if (Settings.Default.DebugAdvanced) Functions.WriteLineToLogFile("Couldn't parse WTV original broadcast date for " + filename + ": [" + strOrigDate + "]"); } } } } if (attributes.ContainsKey("WM/MediaIsRepeat")) { MetadataItem MisRepeat = attributes["WM/MediaIsRepeat"]; if (MisRepeat.Value != null) { bool isRepeat = (bool)MisRepeat.Value; tvp.IsFirstShowing = !isRepeat; } } } catch (Exception ex) { if (Settings.Default.DebugAdvanced) { Functions.WriteLineToLogFile("Couldn't get WTV metadata for " + filename + ":"); Functions.WriteExceptionToLogFile(ex); } return null; } finally { MetaEd.ReleaseResources(); MetaEd = null; } return tvp; }