private void UpdateMetadata()
        {
            using (DvrmsMetadataEditor editor = new DvrmsMetadataEditor(Item.Path)) {
                var attribs = editor.GetAttributes();

                string name = attribs.GetValue <string>(MetadataEditor.Title);

                // australia ice tv adds MOVIE in front of movies
                if (name != null && name.StartsWith("MOVIE: "))
                {
                    name = name.Substring(7);
                }

                string subtitle = attribs.GetValue <string>(MetadataEditor.Subtitle);
                string overview = attribs.GetValue <string>(MetadataEditor.SubtitleDescription);

                Item.Name     = name;
                Item.SubTitle = subtitle;
                Item.Overview = overview;

                var image = editor.GetWMPicture();

                if (image != null)
                {
                    lock (typeof(BaseMetadataProvider)) {
                        var imagePath = Path.Combine(ApplicationPaths.AppImagePath, Item.Id.ToString() + ".png");
                        image.Picture.Save(imagePath, ImageFormat.Png);
                        Item.PrimaryImagePath = imagePath;
                    }
                }
            }
        }
        private void UpdateMetadata()
        {
            Logger.ReportInfo("Dvrms Metadata Provider: Getting Metadata for " + Item.Path);
            using (new MediaBrowser.Util.Profiler("Dvrms Metadata Provider: Metadata extraction"))
                using (DvrmsMetadataEditor editor = new DvrmsMetadataEditor(Item.Path)) {
                    var    attribs = editor.GetAttributes();
                    string name    = attribs.GetValue <string>(MetadataEditor.Title);

                    // australia ice tv adds MOVIE in front of movies
                    if (name != null && name.StartsWith("MOVIE: "))
                    {
                        name = name.Substring(7);
                    }

                    string subtitle = attribs.GetValue <string>(MetadataEditor.Subtitle);
                    string overview = attribs.GetValue <string>(MetadataEditor.SubtitleDescription);

                    Item.SubTitle = subtitle;
                    Item.Overview = overview;


                    var  MediaIsMovie = attribs["WM/MediaIsMovie"] as MetadataItem;
                    bool IsMovie      = MediaIsMovie.Value.ToString().Equals("True");


                    // Not used
                    //var HDContent = attribs["WM/WMRVHDContent"] as MetadataItem;
                    //bool IsHDContent = HDContent.Value.ToString().Equals("True");


                    // Get ReleaseYear
                    try {
                        string OriginalReleaseTime = attribs.GetValue <string>("WM/OriginalReleaseTime");
                        Logger.ReportVerbose("DMP: OriginalReleaseTime: " + OriginalReleaseTime);
                        int ReleaseYear = 0;

                        if (!string.IsNullOrEmpty(OriginalReleaseTime))
                        {
                            DateTime releaseDate;
                            int      releaseYear = DateTime.TryParse(OriginalReleaseTime, out releaseDate) ? releaseDate.Year : -1;
                            // Catch case where OriginalReleaseTime = DateTime.MinValue
                            if (releaseYear > 1)
                            {
                                ReleaseYear = releaseYear;
                            }
                            // Catch case where only the year is used for OriginalReleaseTime
                            else
                            {
                                int _releaseYear;
                                if (Int32.TryParse(OriginalReleaseTime, out _releaseYear) && _releaseYear > 1850 && _releaseYear < 2200)
                                {
                                    ReleaseYear = _releaseYear;
                                }
                            }
                        }


                        // Get OriginalBroadcastYear and OriginalBroadcastDate if item is not a movie
                        int    BroadcastYear = 0;
                        string BroadcastDate = "";

                        if ((!IsMovie))
                        {
                            string OriginalBroadcastDateTime = attribs.GetValue <string>("WM/MediaOriginalBroadcastDateTime");
                            Logger.ReportVerbose("DMP: OriginalBroadcastDateTime: " + OriginalBroadcastDateTime);

                            if (!string.IsNullOrEmpty(OriginalBroadcastDateTime))
                            {
                                DateTime broadcastDate;
                                int      broadcastYear = DateTime.TryParse(OriginalBroadcastDateTime, out broadcastDate) ? broadcastDate.Year : -1;
                                if (broadcastYear > 1)
                                {
                                    BroadcastYear = broadcastYear;
                                    BroadcastDate = broadcastDate.ToString("yyyy/MM/dd");
                                }
                                else
                                {
                                    int _broadcastYear;
                                    if (Int32.TryParse(OriginalBroadcastDateTime, out _broadcastYear) && _broadcastYear > 1850 && _broadcastYear < 2200)
                                    {
                                        BroadcastYear = _broadcastYear;
                                    }
                                }
                            }
                        }


                        // For ProductionYear use ReleaseYear if available else use OriginalBroadcastYear for non movie items
                        if (ReleaseYear != 0)
                        {
                            Show.ProductionYear = ReleaseYear;
                        }
                        else if (BroadcastYear != 0)
                        {
                            Show.ProductionYear = BroadcastYear;
                        }
                        Logger.ReportVerbose("DMP: ProductionYear: " + Show.ProductionYear);


                        // Get RecordedDate
                        var EncodeTime = attribs["WM/WMRVEncodeTime"] as MetadataItem;
                        Logger.ReportVerbose("DMP: EncodeTime: " + EncodeTime.Value.ToString());

                        string RecordedDate = "";
                        int    encodeYear   = 0;
                        Int64  encodeTime   = 0;

                        Int64.TryParse(EncodeTime.Value.ToString(), out encodeTime);
                        DateTime eTUtc   = new DateTime(encodeTime, DateTimeKind.Utc);
                        DateTime eTLocal = eTUtc.ToLocalTime();
                        encodeYear = eTLocal.Year;

                        // Check for FileTime value
                        if (encodeYear > 350 && encodeYear < 600)
                        {
                            RecordedDate = (DateTime.FromFileTime(encodeTime)).ToString("yyyy/MM/dd");
                        }
                        else if (encodeYear > 1950 && encodeYear < 2200)
                        {
                            RecordedDate = eTLocal.ToString("yyyy/MM/dd");
                        }
                        Logger.ReportVerbose("DMP: EncodeDate: " + RecordedDate);


                        // Option to avoid multiple identical names by appending RecordedDate or OriginalBroadcastDate to name of series item
                        string SeriesUID = attribs.GetValue <string>("WM/WMRVSeriesUID");
                        if ((!IsMovie) && (!string.IsNullOrEmpty(SeriesUID)))
                        {
                            if (Plugin.PluginOptions.Instance.AppendFirstAiredDate && BroadcastDate != "")
                            {
                                name = name + " " + BroadcastDate;
                                Logger.ReportInfo("Dvrms Metadata Provider: Modified Name: " + name);
                            }
                            else if (Plugin.PluginOptions.Instance.AppendRecordedDate && RecordedDate != "")
                            {
                                name = name + " " + RecordedDate;
                                Logger.ReportInfo("Dvrms Metadata Provider: Modified Name: " + name);
                            }
                        }
                    }
                    catch (Exception ex) {
                        Logger.ReportInfo("Dvrms Metadata Provider: Error getting DateTime data. " + ex.Message);
                    }

                    Item.Name = name;


                    // WM/ParentalRating: format can be ("***+;PG;TV-PG") OR ("***+" or "PG" or "TV-PG")
                    // Possible US parental rating values: G, PG, PG-13, R, NC-17, NR, TV-Y, TV-Y7, TV-Y7 FV, TV-G, TV-PG, TV-14, TV-MA, NR.
                    try {
                        string ParentalRating = attribs.GetValue <string>(MetadataEditor.ParentalRating);
                        Logger.ReportVerbose("DMP: ParentalRating: " + ParentalRating);
                        if (!string.IsNullOrEmpty(ParentalRating))
                        {
                            string starRating = "";
                            string mpaaRating = ""; {
                                if (ParentalRating.Contains(';'))
                                {
                                    string[] parentalRating = ParentalRating.Split(';');
                                    starRating = (parentalRating[0]);
                                    string movieRating = (parentalRating[1]);
                                    string tvRating    = (parentalRating[2]);

                                    if ((IsMovie) && movieRating != "")
                                    {
                                        mpaaRating = movieRating;
                                    }
                                    else if (tvRating != "")
                                    {
                                        mpaaRating = tvRating;
                                    }
                                    else if (movieRating != "")
                                    {
                                        mpaaRating = movieRating;
                                    }
                                }
                                else if ((ParentalRating.Contains('*')) || (ParentalRating.Contains('+')))
                                {
                                    starRating = ParentalRating;
                                }
                                else
                                {
                                    mpaaRating = ParentalRating;
                                }

                                if (mpaaRating == "TV-Y7 FV")
                                {
                                    Show.MpaaRating = "TV-Y7-FV";
                                }
                                else
                                {
                                    Show.MpaaRating = mpaaRating;
                                }
                                Logger.ReportVerbose("DMP: MpaaRating: " + Show.MpaaRating);

                                // Convert 4 star rating systen "***+" to decimal as used by IMDb and TMDb
                                char[] split     = starRating.ToCharArray();
                                int    starCount = 0;
                                int    plusCount = 0;
                                foreach (char c in split)
                                {
                                    if (c.Equals('*'))
                                    {
                                        starCount++;
                                    }
                                    if (c.Equals('+'))
                                    {
                                        plusCount++;
                                    }
                                }
                                double i = 0;
                                i = Math.Round(Convert.ToSingle((starCount * 2.5) + (plusCount * 1.25)), 1);
                                if (Plugin.PluginOptions.Instance.UseStarRatings && (i != 0))
                                {
                                    Show.ImdbRating = (float)i;
                                    Logger.ReportVerbose("DMP: ImdbRating: " + Show.ImdbRating);
                                }
                            }
                        }
                    }
                    catch (Exception ex) {
                        Logger.ReportInfo("Dvrms Metadata Provider: Error getting Ratings. " + ex.Message);
                    }


                    // WM/MediaCredits format: (Actor1/Actor2;Director1/Director2;Host1/Host2;OtherCredit1/OtherCredit2)
                    try {
                        string Credits = attribs.GetValue <string>(MetadataEditor.Credits);
                        Logger.ReportVerbose("DMP: Credits: " + Credits);

                        string[] credits      = Credits.Split(';');
                        string   cast         = (credits[0]);
                        string   directors    = (credits[1]);
                        string   hosts        = (credits[2]);
                        string   otherCredits = (credits[3]);

                        Logger.ReportVerbose("DMP: Directors: " + directors);
                        Logger.ReportVerbose("DMP: Actors: " + cast);
                        Logger.ReportVerbose("DMP: Hosts: " + hosts);

                        if (cast != "" || hosts != "")
                        {
                            Show.Actors = new List <Actor>();
                            foreach (string CastName in cast.Split('/'))
                            {
                                if (CastName != "")
                                {
                                    Show.Actors.Add(new Actor {
                                        Name = CastName.Trim()
                                    });
                                }
                            }
                            foreach (string HostsName in hosts.Split('/'))
                            {
                                string host = Kernel.Instance.StringData.GetString("HostDetail");
                                // Use host = "Host" unless localized in core
                                if (HostsName != "" && host != "")
                                {
                                    Show.Actors.Add(new Actor {
                                        Name = HostsName.Trim(), Role = host
                                    });
                                }
                                else if (HostsName != "")
                                {
                                    Show.Actors.Add(new Actor {
                                        Name = HostsName.Trim(), Role = "Host"
                                    });
                                }
                            }
                        }
                        if (directors != "")
                        {
                            Show.Directors = new List <string>(directors.Split('/'));
                        }
                    }
                    catch (Exception ex) {
                        Logger.ReportInfo("Dvrms Metadata Provider: Error getting Cast & Crew. " + ex.Message);
                    }


                    string studios = attribs.GetValue <string>("WM/MediaStationCallSign");
                    // Special case for UK channel "5*"
                    studios = studios.Replace("5*", "5star");
                    if (!string.IsNullOrEmpty(studios))
                    {
                        Show.Studios = new List <string>(studios.Split(';'));
                        Logger.ReportVerbose("DMP: Network: " + studios);
                    }


                    string genres = attribs.GetValue <string>(MetadataEditor.Genre);
                    if (Plugin.PluginOptions.Instance.UseGenres && (!string.IsNullOrEmpty(genres)))
                    {
                        Show.Genres = new List <string>(genres.Split(';'));
                        Logger.ReportVerbose("DMP: Genres: " + genres);
                    }


                    // Not used, allows option to remove certain Genres from list.
                    // We would need a list of genres used by broadcasters to filter or convert these properly
                    // plus they can be in different languages

                    /*List<string> badGenres = new List<string>();
                     * //badGenres.Add("shows");
                     * //badGenres.Add("film");
                     * string genres = attribs.GetValue<string>(MetadataEditor.Genre);
                     * if (Plugin.PluginOptions.Instance.UseGenres && (!string.IsNullOrEmpty(genres))) {
                     *  List<string> genresList = new List<string>(genres.Split(';'));
                     *  for(int i = 0; i <= genresList.Count -1; i++) {
                     *      string genre = genresList[i];
                     *      if (badGenres.Contains(genre.ToLower())) {
                     *          genresList.Remove(genre);
                     *          i -= 1;
                     *      }
                     *  }
                     *  if (genresList.Count > 0) Show.Genres = genresList;
                     * }*/


                    // Duration is the length of the file in minutes
                    var   Duration = attribs["Duration"] as MetadataItem;
                    Int64 runTime  = 0;
                    int   RunTime;
                    Int64.TryParse(Duration.Value.ToString(), out runTime);
                    // Show RunTime as 1 minute if less than 60 seconds as Media Center does
                    // Not used, due to Resume issue when watched item is less than 60 seconds
                    //if (runTime > 0 & runTime < 600000000) RunTime = 1;
                    //else
                    RunTime = Convert.ToInt32(runTime / 600000000);
                    if (runTime > 0)
                    {
                        Show.RunningTime = RunTime;
                        Logger.ReportVerbose("DMP: Duration: " + Show.RunningTime);
                    }


                    // Image processing
                    Logger.ReportVerbose("DMP: Process thumbnail started");
                    double defaultAspectRatio = 1.778;
                    double thumbAspectRatio   = 0;
                    try {
                        // Calculate correct aspect ratio of embedded thumbnail
                        var thumbAspectRatioX = attribs["WM/MediaThumbAspectRatioX"] as MetadataItem;
                        var thumbAspectRatioY = attribs["WM/MediaThumbAspectRatioY"] as MetadataItem;
                        thumbAspectRatio = Math.Round(Double.Parse(thumbAspectRatioX.Value.ToString()) / Double.Parse(thumbAspectRatioY.Value.ToString()), 3);
                        if ((Double.IsNaN(thumbAspectRatio)) || (Double.IsInfinity(thumbAspectRatio)) || thumbAspectRatio == 0)
                        {
                            thumbAspectRatio = defaultAspectRatio;
                            Logger.ReportInfo("Dvrms Metadata Provider: Failed to get thumbnail aspect ratio so using default value " + thumbAspectRatio);
                        }
                        else
                        {
                            Show.AspectRatio = Math.Round(thumbAspectRatio, 2).ToString();
                            Logger.ReportVerbose("DMP: AspectRatio " + Show.AspectRatio);
                        }
                    }
                    catch {
                        thumbAspectRatio = defaultAspectRatio;
                        Logger.ReportInfo("Dvrms Metadata Provider: Error getting thumbnail aspect ratio so using default value " + defaultAspectRatio);
                    }

                    var image = editor.GetWMPicture();
                    if (image != null)
                    {
                        lock (typeof(BaseMetadataProvider)) {
                            var imagePath = Path.Combine(ApplicationPaths.AppImagePath, Item.Id.ToString() + "-orig.png");
                            // Set aspect ratio of extracted image to be the same as thumbAspectRatio
                            ResizeImage(image.Picture, thumbAspectRatio).Save(imagePath, ImageFormat.Png);
                            Item.PrimaryImagePath = imagePath;
                            Logger.ReportVerbose("DMP: Process thumbnail finished");
                        }
                    }
                    else
                    {
                        Logger.ReportInfo("Dvrms Metadata Provider: No thumbnail image in video.. try viewing item in WMC Recorded TV library to create one");
                    }

                    //Logger.ReportInfo("Dvrms Metadata Provider: Metadata extraction complete");
                }
        }
Exemplo n.º 3
0
        private void SetDVRMSProperties()
        {
            IDictionary           idMetaData;
            IDictionaryEnumerator ideMetaData;

            sClosedCaptioningPresent = "No";
            sIsHDContent             = "No";
            sIsDTVContent            = "No";
            if (VideoCatagory.ToUpper().Equals("SERIES") ||
                VideoCatagory.ToUpper().Equals("SPECIALS"))
            {
                sSeries       = GetSeries(FullFileName, FileGenre);
                sSeason       = GetSeason(FullFileName);
                sEpisode      = GetEpisode(FullFileName);
                sEpisodeTitle = GetEpisodeTitle(FullFileName);
                if (sSeason == null)
                {
                    sSeason = "N/A";
                }

                if (sEpisodeTitle == null)
                {
                    sEpisodeTitle = Name;
                }

                if (sEpisode == null)
                {
                    sEpisode = "N/A";
                }
            }
            try
            {
                dmeFMp3File = new DvrmsMetadataEditor(FullFileName);
                idMetaData  = dmeFMp3File.GetAttributes();
                ideMetaData = idMetaData.GetEnumerator();

                while (ideMetaData.MoveNext())
                {
                    MetadataItem miData = (MetadataItem)ideMetaData.Value;
                    if (VideoCatagory.ToUpper().Equals("MOVIES"))
                    {
                        if (miData.Name.Equals("Title"))
                        {
                            sTitle = miData.Value.ToString();
                        }
                    }
                    if (VideoCatagory.ToUpper().Equals("SERIES") ||
                        VideoCatagory.ToUpper().Equals("SPECIALS"))
                    {
                        if (miData.Name.Equals("WM/SubTitle"))
                        {
                            if (miData.Value.ToString().Trim() == "")
                            {
                                if (sEpisode != "N/A")
                                {
                                    sTitle = sEpisodeTitle;
                                }
                            }
                            else
                            {
                                sTitle = miData.Value.ToString();
                            }
                        }
                    }
                    if (miData.Name.Equals("WM/SubTitleDescription"))
                    {
                        sDescription = miData.Value.ToString();
                    }
                    if (miData.Name.Equals("WM/Genre"))
                    {
                        String [] sGenreExclude = { "/Movies", "/Movies.", "Movies.", "Movies", "/Series", "/Series.", "Series.", "Series" };
                        sGenre = miData.Value.ToString();
                        for (int i = 0; i < sGenreExclude.Length; i++)
                        {
                            sGenre = sGenre.Replace(sGenreExclude[i], "");
                        }
                    }
                    if (miData.Name.Equals("WM/MediaNetworkAffiliation"))
                    {
                        sNetworkAffiliation = miData.Value.ToString();
                    }
                    if (miData.Name.Equals("WM/MediaOriginalChannel"))
                    {
                        sChannel = miData.Value.ToString();
                    }
                    if (miData.Name.Equals("WM/MediaStationCallSign"))
                    {
                        if (miData.Value.ToString().Equals("Edited with VideoReDo Plus"))
                        {
                            sStationCallSign = "TIVO";
                            sStationName     = "Tivo-Extract";
                        }
                        else
                        {
                            sStationCallSign = miData.Value.ToString();
                        }
                    }
                    if (miData.Name.Equals("WM/MediaStationName"))
                    {
                        sStationName = miData.Value.ToString();
                    }
                    if (miData.Name.Equals("WM/MediaCredits"))
                    {
                        sCredits = CleanupCredits(miData.Value.ToString());
                    }
                    if (miData.Name.Equals("WM/ParentalRating"))
                    {
                        sParentalRating = CleanupRatings(miData.Value.ToString());
                    }
                    if (miData.Name.Equals("WM/ParentalRatingReason"))
                    {
                        sParentalRatingReason = CleanupRatings(miData.Value.ToString());
                    }
                    if (miData.Name.Equals("WM/ProviderRating"))
                    {
                        sProviderRating = CleanupProviderRatings(miData.Value.ToString());
                    }
                    if (miData.Name.Equals("WM/Year"))
                    {
                        sMovieYear = miData.Value.ToString();
                    }
                    if (miData.Name.Equals("Duration"))
                    {
                        sPlayTime          = pdamxUtility.FormatNanoseconds(miData.Value.ToString());
                        sUFPlayTime        = miData.Value.ToString();
                        nDurationInSeconds = (int)(Convert.ToDouble(miData.Value.ToString()) / 10000000);
                    }
                    if (miData.Name.Equals("WM/WMRVHDContent"))
                    {
                        if (miData.Value.ToString().ToUpper().Trim().Equals("TRUE"))
                        {
                            sIsHDContent = "Yes";
                        }
                        else
                        {
                            sIsHDContent = "No";
                        }
                    }
                    if (FullFileName.ToUpper().Trim().Contains("(HD-TP)"))
                    {
                        sIsHDContent = "Yes";
                    }
                    if (miData.Name.Equals("WM/WMRVDTVContent"))
                    {
                        if (miData.Value.ToString().ToUpper().Trim().Equals("TRUE"))
                        {
                            sIsDTVContent = "Yes";
                        }
                        else
                        {
                            sIsDTVContent = "No";
                        }
                    }
                    if (FullFileName.ToUpper().Trim().Contains("(HD)"))
                    {
                        sIsDTVContent = "Yes";
                    }
                    if (sStationName.ToUpper().Contains(" HD") || sStationName.ToUpper().Contains("-DT"))
                    {
                        sIsDTVContent = "Yes";
                    }
                    if (miData.Name.Equals("WM/VideoClosedCaptioning"))
                    {
                        sClosedCaptioningPresent = "Yes";
                    }
                }
                if (VideoCatagory.ToUpper().Equals("SPECIALS"))
                {
                    sGenre = FileGenre;
                }
                if (sGenre.Trim().Length == 0)
                {
                    sGenre = FileGenre;
                }
            }
            catch (Exception)
            {
                sGenre = FileGenre;
                if (VideoCatagory.ToUpper().Equals("MOVIES"))
                {
                    sTitle = Name;
                }
                if (VideoCatagory.ToUpper().Equals("SERIES") ||
                    VideoCatagory.ToUpper().Equals("SPECIALS"))
                {
                    if (sEpisodeTitle.Trim().Length > 0)
                    {
                        sTitle = sEpisodeTitle;
                    }
                    else
                    {
                        sEpisodeTitle = Name;
                    }
                }
            }
            if (VideoCatagory.ToUpper().Equals("SERIES") ||
                VideoCatagory.ToUpper().Equals("SPECIALS"))
            {
                if (sTitle == null)
                {
                    sTitle = sEpisodeTitle;
                }
                if (sTitle.Trim().Length == 0)
                {
                    sTitle = sEpisodeTitle;
                }
                if (sTitle.Trim().Length == 0)
                {
                    sTitle = Name;
                }
            }
        }
Exemplo n.º 4
0
        // 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);
        }
Exemplo n.º 5
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");
            }
        }
Exemplo n.º 6
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);
        }