Beispiel #1
0
        // Extension methods to link records:
        public static TVService TVService(this TVProgramme tvp) // TVProgramme => TVService
        {
            string svcID = null;

            // If it's a fake, generated TV Programme...
            if (tvp.isGeneratedFromFile)
            {
                // Attempt to match the callsign to one of our channels
                svcID = ServiceIDFromCallsign(tvp.WTVCallsign);

                // If there's no match, generate a dummy TV service with the correct callsign
                if (string.IsNullOrEmpty(svcID))
                {
                    TVService tvs = new TVService();
                    tvs.Callsign = tvp.WTVCallsign;
                    tvs.UniqueId = "0";
                    return(tvs);
                }
            }
            else
            {
                svcID = tvp.ServiceID;  // Normal service retrieval
            }
            if (string.IsNullOrEmpty(svcID))
            {
                return(null);
            }

            try
            {
                return(AllTVChannels[tvp.ServiceID]);
            }
            catch { }
            return(null);
        }
Beispiel #2
0
        public static List <RPRecording> AllRecordingsRunningInTimeFrame(DateRange dr, bool NewLiveTV)
        {
            Functions.WriteLineToLogFile("reloading all recordings....");
            if (NewLiveTV)
            {
                ReloadAllRecordingsForLiveTV();
            }
            else
            {
                ReloadAllRecordings();
            }
            List <RPRecording> output = new List <RPRecording>();

            foreach (RPRecording rec in AllRecordings.Values)
            {
                TVProgramme tvp = rec.TVProgramme();
                if (tvp == null)
                {
                    Functions.WriteLineToLogFile("Could not find a TV Programme for the recording: " + rec.Title);
                    continue;
                }
                Functions.WriteLineToLogFile("found: " + rec.Title);
                if (rec.TVProgramme().StartTimeDT().ToUniversalTime().CompareTo(dr.StopTime) <= 0 && rec.TVProgramme().StopTimeDT().ToUniversalTime().CompareTo(dr.StartTime) >= 0)
                {
                    output.Add(rec);
                }
            }

            // Sort by start time ascending
            Functions.WriteLineToLogFile("sorting the recordings within time frame....");
            output.Sort(new RPRecordingStartTimeComparer());

            return(output);
        }
Beispiel #3
0
        public static List <RPRecording> AllRecordingsTodayRemaining()
        {
            List <RPRecording> output = new List <RPRecording>();

            foreach (RPRecording rec in AllRecordings.Values)
            {
                TVProgramme tvp = rec.TVProgramme();
                if (tvp == null)
                {
                    Functions.WriteLineToLogFile("Could not find a TV Programme for the recording: " + rec.Title);
                    continue;
                }

                if (
                    (tvp.StartTimeDT().ToLocalTime().Date == DateTime.Now.Date) &&
                    (tvp.StartTimeDT().ToLocalTime() > DateTime.Now)
                    )
                {
                    output.Add(rec);
                }
            }

            // Sort by start time ascending
            output.Sort(new RPRecordingStartTimeComparer());

            return(output);
        }
Beispiel #4
0
        private static void AddToMovieCache(TVProgramme tvp)
        {
            int     newInt = CachedMovies.Count + 1;
            TVMovie tvm    = new TVMovie(newInt, tvp);

            CachedMovies.Add(tvp.Title, tvm);
        }
Beispiel #5
0
            public int Compare(RPRecording rec1, RPRecording rec2)
            {
                try
                {
                    TVProgramme tvp1 = rec1.TVProgramme();
                    TVProgramme tvp2 = rec2.TVProgramme();
                    if (
                        (tvp1 == null) || (tvp2 == null)
                        )
                    {
                        return(0);
                    }


                    if (rec1.TVProgramme().StartTime > rec2.TVProgramme().StartTime)
                    {
                        return(1);
                    }
                    if (rec1.TVProgramme().StartTime < rec2.TVProgramme().StartTime)
                    {
                        return(-1);
                    }
                }
                catch { }
                return(0);
            }
Beispiel #6
0
 private static void AddOrMergeToMovieCache(TVProgramme tvp)
 {
     if (CachedMovies.ContainsKey(tvp.Title))
     {
         MergeToMovieCache(tvp);
     }
     else
     {
         AddToMovieCache(tvp);
     }
 }
Beispiel #7
0
        public playSchedule(TVProgramme prog)
        {
            mTitle       = prog.Title;
            mDescription = prog.Description;
            mStartTime   = prog.StartTime;
//			mStartTime=DateTime.Now;
            mShowOccurrences = ERecurranceTypes.OneTimeOnly;
            mAlreadyNotified = false;
            mProgramme       = prog;
            mIndex           = 0;
        }
Beispiel #8
0
        // Conversion
        public static TVProgramme VideoFileToTVProgramme(string FN)
        {
            TVProgramme tvp = new TVProgramme();

            tvp.Description = "Video file from " + FN;
            tvp.Title       = Path.GetFileNameWithoutExtension(FN);

            tvp.Filename            = FN;
            tvp.isGeneratedFromFile = true;

            tvp.WTVCallsign = "Remote Potato";

            return(tvp);
        }
Beispiel #9
0
        public static RPRequest SeriesRequest(this TVProgramme tvp)
        {
            if (tvp.SeriesID < 1)
            {
                return(null);
            }

            foreach (RPRequest rpreq in AllRequests.Values)
            {
                if (rpreq.SeriesID == tvp.SeriesID)
                {
                    return(rpreq);
                }
            }
            return(null);
        }
Beispiel #10
0
        public static bool HasSeriesRequest(this TVProgramme tvp)  // For TVProgs not recording, but possibly part of a series, so we know whether to offer a 'record series' option
        {
            if (tvp.SeriesID < 1)
            {
                return(false);
            }

            foreach (RPRequest rpreq in AllRequests.Values)
            {
                if (rpreq.SeriesID == tvp.SeriesID)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #11
0
        public static TVProgramme TVProgramme(this RPRecording rpr)
        {
            if (rpr.RequestType != RPRequestTypes.Manual)
            {
                return(mcData.GetTVProgramme(rpr.TVProgrammeID.ToString()));
            }

            // Manual recording is a special case
            TVProgramme tvp = new TVProgramme();

            tvp.Title     = rpr.Title;
            tvp.ServiceID = rpr.ManualRecordingServiceID.ToString();
            tvp.StartTime = rpr.ManualRecordingStartTime.Ticks;
            tvp.StopTime  = tvp.StartTime + (TimeSpan.FromSeconds(rpr.ManualRecordingDuration).Ticks);
            tvp.Id        = "-10";
            return(tvp);
        } // Recording => TV Programme
Beispiel #12
0
        public static RPRecording Recording(this TVProgramme tvp)  // TV Programme => any recording (if known)
        {
            // This actually iterates through all the recordings to find matches, there is no stored ID linking them
            foreach (RPRecording rpr in AllRecordings.Values)
            {
                try
                {
                    long tvpID = long.Parse(tvp.Id);

                    if (rpr.TVProgrammeID == tvpID)
                    {
                        return(rpr);
                    }
                }
                catch { }
            }

            return(null);
        }
Beispiel #13
0
        } // Recording => TV Programme

        public static List <TVProgramme> TVProgrammes(this RPRequest rq)
        {
            List <TVProgramme> output = new List <TVProgramme>();

            foreach (RPRecording rec in AllRecordings.Values)
            {
                if (rec.RPRequestID != rq.ID)
                {
                    continue;
                }

                TVProgramme tvp = rec.TVProgramme();
                if (tvp != null)
                {
                    output.Add(tvp);
                }
            }

            return(output);
        }  // Request => TV Programmes  (not really used, better to get recordings as more info and you can then get the tv progs for each recording)
Beispiel #14
0
        /// <summary>
        /// Returns a recordings blob object with all recording requests and recordings inside.
        /// </summary>
        /// <returns></returns>
        public static string RecordingsBlobAsXML()
        {
            List <RPRequest>   allRequests   = EPGManager.AllRequests.Values.ToList();
            List <RPRecording> allRecordings = EPGManager.AllRecordings.Values.ToList();

            // Pull up all the relevant TV programmes that will record too.
            List <TVProgramme> progsToRecord = new List <TVProgramme>();

            foreach (RPRecording rec in allRecordings)
            {
                TVProgramme tvp = rec.TVProgramme();
                if (tvp != null)
                {
                    progsToRecord.Add(tvp);
                }
            }

            RPRecordingsBlob newBlob = new RPRecordingsBlob(allRequests, allRecordings, progsToRecord);

            return(XMLHelper.Serialize <RPRecordingsBlob>(newBlob));
        }
Beispiel #15
0
        void fw_Renamed(object sender, RenamedEventArgs e)
        {
            if (!fileIsRecordedTVFile(e.OldFullPath))
            {
                return;
            }

            // Is this file in the DB (under its old filename)?  (if not, might be in 'filesinuse' awaiting release)
            string ID = "";

            if (!TryGetProgrammeIdFromFilePath(e.OldFullPath, ref ID))
            {
                return;
            }

            // Yes, replace with newer name
            TVProgramme tvp = RecordedTVProgrammes[ID];

            RecordedTVProgrammes.Remove(ID);
            tvp.Filename = e.FullPath;
            RecordedTVProgrammes.Add(tvp.Id, tvp);
        }
Beispiel #16
0
        public bool IsStarting()
        {
            bool        ShowStarting = false;
            DateTime    Now          = System.DateTime.Now;
            TVProgramme prog         = mProgramme;

            switch (mShowOccurrences)
            {
            case ERecurranceTypes.OneTimeOnly:
                if (mStartTime.Hour == Now.Hour && mStartTime.Minute == Now.Minute && mStartTime.Date == Now.Date)
                {
                    ShowStarting = true;
                }
                else
                {
                    ShowStarting = false;
                }
                break;

            case ERecurranceTypes.Daily:
                if (mStartTime.TimeOfDay.Hours == Now.TimeOfDay.Hours && mStartTime.TimeOfDay.Minutes == Now.TimeOfDay.Minutes)
                {
                    ShowStarting = true;
                }
                else
                {
                    ShowStarting = false;
                }
                break;

            case ERecurranceTypes.Weekly:
                if (mStartTime.Hour == Now.Hour && mStartTime.Minute == Now.Minute && mStartTime.DayOfWeek == Now.DayOfWeek)
                {
                    ShowStarting = true;
                }
                else
                {
                    ShowStarting = false;
                }
                break;

            case ERecurranceTypes.Monthly:
                if (mStartTime.Hour == Now.Hour && mStartTime.Minute == Now.Minute && mStartTime.Day == Now.Day)
                {
                    ShowStarting = true;
                }
                else
                {
                    ShowStarting = false;
                }
                break;

            case ERecurranceTypes.Yearly:
                if (mStartTime.Hour == Now.Hour && mStartTime.Minute == Now.Minute && mStartTime.DayOfYear == Now.DayOfYear)
                {
                    ShowStarting = true;
                }
                else
                {
                    ShowStarting = false;
                }
                break;
            }
            EventLog.WriteEntry("sctv", "show starting " + ShowStarting.ToString());
            return(ShowStarting);
        }
Beispiel #17
0
 public static string imgTagRecordedTVProgramme(TVProgramme tvp)
 {
     return("<img src=\"/rectvthumbnail?filename=" + HttpUtility.UrlEncode(tvp.Filename) + "\" class=\"showthumbnail\"/>");
 }
Beispiel #18
0
        // Schedule Recordings
        /// <summary>
        /// Schedule a recording - this examines the request and populates Service ID, etc.
        /// The MCDATA.Schedule... method should never be called directly outside this method
        /// </summary>
        public static RecordingResult ScheduleRecording(RecordingRequest rr)
        {
            // Populate defaults, e.g. quality, if not set
            PopulateDefaultsIfUnset(ref rr);

            RecordingResult failedResult = new RecordingResult();

            failedResult.Completed = false;

            if (rr.RequestType != RecordingRequestType.Manual)  // manual recordings already have a service ID specified
            {
                if (rr.TVProgrammeID < 1)
                {
                    failedResult.ErrorMessage = "No TV Programme ID was specified.";
                    return(failedResult);
                }

                // Populate the Service ID if not already populated
                TVProgramme tvp = mcData.GetTVProgramme(rr.TVProgrammeID.ToString());
                if (tvp == null)
                {
                    failedResult.ErrorMessage = "No TV Programme with the specified ID could be found.";
                    return(failedResult);
                }

                rr.ServiceID = long.Parse(tvp.ServiceID);  // could fail
            }

            // Get the channel ID from the service ID
            TVService tvs = TVServiceWithIDOrNull(rr.ServiceID.ToString());

            if (tvs == null)
            {
                failedResult.ErrorMessage = "No TV Channel with the retrieved ID could be found.";
                return(failedResult);
            }
            rr.MCChannelID = tvs.MCChannelID;


            // ************** SCHEDULE THE RECORDING ************************
            RPRequest       generatedRequest;
            RecordingResult earlyRecResult;

            if (!mcData.ScheduleRecording(rr, out generatedRequest, out earlyRecResult))
            {
                bool debug2 = (Settings.Default.DebugAdvanced);
                Functions.WriteLineToLogFileIfSetting(debug2, "Failed already - return the early result");
                return(earlyRecResult);
            }


            RecordingResult recResult = mcData.DetermineRecordingResultForRequest(generatedRequest);
            bool            debug     = (Settings.Default.DebugAdvanced);

            Functions.WriteLineToLogFileIfSetting(debug, "recResult.Success=" + recResult.Success);

            // Success?
            if (recResult.Success)
            {
                // Wait a moment so Scheduler can catch up and associate our request with our recordings...
                System.Threading.Thread.Sleep(600);

                Functions.WriteLineToLogFileIfSetting(debug, "// Now refresh and get the generated recordings...");
                EPGManager.ReloadAllRecordings();

                try
                {
                    RPRequest req = recResult.GeneratedRecordingsBlob.RPRequests[0];
                    Functions.WriteLineToLogFileIfSetting(debug, "req.Title=" + req.Title);

                    // Add recordings
                    recResult.GeneratedRecordingsBlob.RPRecordings = req.Recordings();
                    Functions.WriteLineToLogFileIfSetting(debug, "recordings added");

                    // Add programs linked to these recordings
                    foreach (RPRecording rec in recResult.GeneratedRecordingsBlob.RPRecordings)
                    {
                        TVProgramme tvp = rec.TVProgramme();
                        if (tvp != null)
                        {
                            recResult.GeneratedRecordingsBlob.TVProgrammes.Add(tvp);
                            Functions.WriteLineToLogFileIfSetting(debug, tvp.Filename + " added");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Functions.WriteLineToLogFile("ScheduleRecording(): Error retrieving recordings:");
                    Functions.WriteExceptionToLogFile(ex);
                    recResult.Success      = false;
                    recResult.ErrorMessage = "Exception occured while retrieving recordings - the recording may have been scheduled.";
                }
            }

            return(recResult);
        }
Beispiel #19
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);
        }
Beispiel #20
0
        private static void MergeToMovieCache(TVProgramme tvp)
        {
            TVMovie existingMovie = CachedMovies[tvp.Title];

            existingMovie.Showings.Add(tvp);
        }