コード例 #1
0
ファイル: RecTV.cs プロジェクト: jchappo/remotepotato
        // 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;
        }
コード例 #2
0
        /// <summary>Splices together all of the spans.</summary>
        /// <returns></returns>
        protected override object DoWork()
        {
            IStreamBufferRecComp recComp = null;
            Timer timer = null;
            try
            {
                // Timer used for updating progress
                timer = new Timer(new TimerCallback(HandleProgressUpdate), null, PollFrequency, PollFrequency);

                // Create the RecComp and initialize it
                recComp = (IStreamBufferRecComp)ClassId.CoCreateInstance(ClassId.RecComp);
                if (File.Exists(_target.FullName)) File.Delete(_target.FullName);
                recComp.Initialize(_target.FullName, _spans[0].File.FullName);
                _recComp = recComp; // only valid during this call

                // Add each span to the output file
                FileInfo dvrTarget = _target;
                for(int i=0; i<_spans.Count; i++)
                {
                    // If the user has requested cancellation, stop processing
                    if (CancellationPending) break;

                    // Do the append
                    VideoSpan span = _spans[i];
                    ulong start = VideoSpan.SecondsToHundredNanoseconds(span.StartPosition);
                    ulong stop = VideoSpan.SecondsToHundredNanoseconds(span.StopPosition);
                    recComp.AppendEx(span.File.FullName, start, stop);
                }
            }
            finally
            {
                // Clean up after the RecComp object and the timer
                if (timer != null) timer.Dispose();
                if (recComp != null) recComp.Close();
                while(Marshal.ReleaseComObject(recComp) > 0);
            }

            // Copy the metadata if requested... use that from the first span.
            if (_copyMetadata)
            {

                using(MetadataEditor sourceEditor = new DvrmsMetadataEditor(_spans[0].File.FullName))
                {
                    using(MetadataEditor destEditor = new AsfMetadataEditor(_target.FullName))
                    {
                        MetadataEditor.MigrateMetadata(sourceEditor, destEditor);
                    }
                }
            }

            // Notify that we're done
            OnProgressChanged(100);
            return null;
        }
コード例 #3
0
        public override void ProcessFile(string file)
        {
            OMLSDKTitle newTitle = new OMLSDKTitle();
            String fPath = Path.GetDirectoryName(file);
            newTitle.Name = Path.GetFileNameWithoutExtension(file);
            IDictionary meta;
            DvrmsMetadataEditor editor = new DvrmsMetadataEditor(file);
            meta = editor.GetAttributes();
            foreach (string item in meta.Keys)
            {
                MetadataItem attr = (MetadataItem)meta[item];
                switch (item)
                {
                    case DvrmsMetadataEditor.Title:
                        string sTitle = (string)attr.Value;
                        sTitle = sTitle.Trim();
                        if (!String.IsNullOrEmpty(sTitle))
                        {
                            newTitle.Name = sTitle;
                        }
                        newTitle.ImporterSource = @"DVRMSImporter";
                        newTitle.MetadataSourceName = @"DVR-MS";
                        OMLSDKDisk disk = new OMLSDKDisk();
                        string ext = Path.GetExtension(file).Substring(1).Replace(@"-", @"");
                        disk.Format = (OMLSDKVideoFormat)Enum.Parse(typeof(OMLSDKVideoFormat), ext, true);
                        SDKUtilities.DebugLine("[DVRMSPlugin] Adding file: " + Path.GetFullPath(file));
                        disk.Path = Path.GetFullPath(file);
                        disk.Name = @"Disk 1";
                        newTitle.AddDisk(disk);
                        //newTitle.FileLocation = file;
                        if (!String.IsNullOrEmpty(newTitle.AspectRatio))
                        {
                            newTitle.AspectRatio = @"Widescreen";
                        }
                        //string ext = Path.GetExtension(file).Substring(1).Replace(@"-", @"");
                        //newTitle.VideoFormat = (VideoFormat)Enum.Parse(typeof(VideoFormat), ext, true);
                        string cover = fPath + @"\" + Path.GetFileNameWithoutExtension(file) + @".jpg";
                        if (File.Exists(cover))
                        {
                            SDKUtilities.DebugLine("[DVRMSPlugin] Setting CoverArt: " + Path.GetFullPath(cover));
                            newTitle.FrontCoverPath = Path.GetFullPath(cover);
                            //newTitle.FrontCoverPath = cover;
                        }
                        else
                        {
                            SDKUtilities.DebugLine("[DVRMSPlugin] No coverart found");
                        }
                        break;
                    case DvrmsMetadataEditor.MediaOriginalBroadcastDateTime:
                        string sDT = (string)attr.Value;
                        if (!String.IsNullOrEmpty(sDT))
                        {
                            DateTime dt;
                            if (DateTime.TryParse(sDT, out dt))
                            {
                                newTitle.ReleaseDate = dt;
                            }
                        }
                        break;
                    case DvrmsMetadataEditor.Genre:
                        if (!String.IsNullOrEmpty((string)attr.Value))
                        {
                            string sGenre = (string)attr.Value;
                            string[] gen = sGenre.Split(',');
                            newTitle.Genres.Clear();
                            foreach (string genre in gen)
                            {
                                string uGenre = genre.ToUpper().Trim();
                                if (String.IsNullOrEmpty(uGenre)) continue;
                                if (uGenre.StartsWith(@"MOVIE")) continue;
                                uGenre = genre.Trim();
                                newTitle.AddGenre(uGenre);
                            }
                        }
                        break;
                    case DvrmsMetadataEditor.Duration:
                        Int64 rTime = (long)attr.Value;
                        rTime = rTime / 600 / 1000000;
                        newTitle.Runtime = (int)rTime;
                        break;
                    case DvrmsMetadataEditor.ParentalRating:
                        if (!String.IsNullOrEmpty((string)attr.Value))
                        {
                            newTitle.ParentalRating = (string)attr.Value;
                        }
                        break;
                    case DvrmsMetadataEditor.Credits:
                        string persona = (string)attr.Value;
                        persona += @";;;;";
                        string[] credits = persona.Split(';');
                        string[] cast = credits[0].Split('/');
                        foreach (string nm in cast)
                        {
                            if (!String.IsNullOrEmpty(nm)) newTitle.AddActingRole(nm, "");
                        }
                        string[] dirs = credits[1].Split('/');
                        if (dirs.Length > 0)
                        {
                            if (!String.IsNullOrEmpty(dirs[0]))
                            {
                                string nm = dirs[0];
                                newTitle.AddDirector(new OMLSDKPerson(nm));
                            }
                        }

                        break;
                    case DvrmsMetadataEditor.SubtitleDescription:
                        newTitle.Synopsis = (string)attr.Value;
                        break;
                }
                attr = null;
            }

            if (ValidateTitle(newTitle))
            {
                try
                {
                    if (String.IsNullOrEmpty(newTitle.Name))
                    {
                        newTitle.Name = Path.GetFileNameWithoutExtension(file);
                        newTitle.ImporterSource = @"DVRMSImporter";
                        newTitle.MetadataSourceName = @"DVR-MS";
                        OMLSDKDisk disk = new OMLSDKDisk();
                        disk.Name = @"Disk 1";
                        disk.Path = file;
                        //newTitle.FileLocation = file;
                        string ext = Path.GetExtension(file).Substring(1).Replace(@"-", @"");
                        //newTitle.VideoFormat = (VideoFormat)Enum.Parse(typeof(VideoFormat), ext, true);
                        disk.Format = (OMLSDKVideoFormat)Enum.Parse(typeof(OMLSDKVideoFormat), ext, true);
                        newTitle.AddDisk(disk);
                        string cover = fPath + @"\" + Path.GetFileNameWithoutExtension(file) + @".jpg";
                        if (File.Exists(Path.GetFullPath(cover)))
                        {
                            SDKUtilities.DebugLine("[DVRMSPlugin] Setting CoverArt: " + Path.GetFullPath(cover));
                            newTitle.FrontCoverPath = cover;
                        }
                        else
                        {
                            SDKUtilities.DebugLine("[DVRMSPlugin] No coverart found");
                        }
                    }
                    if (String.IsNullOrEmpty(newTitle.AspectRatio))
                    {
                        newTitle.AspectRatio = @"Widescreen";
                    }
                    if (String.IsNullOrEmpty(newTitle.ParentalRating))
                    {
                        newTitle.ParentalRating = @"--";
                    }
                    AddTitle(newTitle);
                }
                catch (Exception e)
                {
                    Trace.WriteLine("[DVRMSPlugin] Error adding row: " + e.Message);
                }
            }
            else
            {
                Trace.WriteLine("[DVRMSPlugin] Error saving row");
            }
        }