示例#1
0
        public static sdUserStatusResponse sdGetStatus()
        {
            var sr = sdGetRequestResponse(METHODS.GET, "status");

            if (sr == null)
            {
                Logger.WriteError("Did not receive a response from Schedules Direct for a status request.");
                return(null);
            }

            try
            {
                sdUserStatusResponse ret = JsonConvert.DeserializeObject <sdUserStatusResponse>(sr);
                switch (ret.Code)
                {
                case 0:
                    Logger.WriteVerbose(string.Format("Status request successful. account expires: {0} , lineups: {1}/{2} , lastDataUpdate: {3}",
                                                      ret.Account.Expires, ret.Lineups.Count, ret.Account.MaxLineups, ret.LastDataUpdate));
                    Logger.WriteVerbose(string.Format("system status: {0} , message: {1}", ret.SystemStatus[0].Status, ret.SystemStatus[0].Message));
                    maxLineups = ret.Account.MaxLineups;

                    TimeSpan expires = DateTime.Parse(ret.Account.Expires) - DateTime.Now;
                    if (expires < TimeSpan.FromDays(7.0))
                    {
                        Logger.WriteWarning(string.Format("Your Schedules Direct account expires in {0:D2} days {1:D2} hours {2:D2} minutes.",
                                                          expires.Days, expires.Hours, expires.Minutes));
                    }
                    return(ret);

                default:
                    break;
                }
                Logger.WriteError(string.Format("Failed to get account status. code: {0} , message: {1}", ret.Code, sdErrorLookup(ret.Code)));
            }
            catch (Exception ex)
            {
                Logger.WriteError(string.Format("sdUserStatusResponse() Unknown exception thrown. Message: {0}", ex.Message));
            }
            return(null);
        }
示例#2
0
        public static void Build(epgConfig configuration)
        {
            string errString = string.Empty;

            // initialize schedules direct API
            sdAPI.Initialize("EPG123", epg123Version);

            // copy configuration to local variable
            config = configuration;

            // initialize event buffer
            Logger.WriteInformation(string.Format("Beginning EPG123 update execution. {0:u}", DateTime.Now.ToUniversalTime()));
            Logger.WriteVerbose(string.Format("DaysToDownload: {0} , TheTVDBNumbers : {1} , PrefixEpisodeTitle: {2} , PrefixEpisodeDescription : {3} , AppendEpisodeDesc: {4} , OADOverride : {5} , TMDbCoverArt: {6} , IncludeSDLogos : {7} , AutoAddNew: {8} , CreateXmltv: {9} , ModernMediaUiPlusSupport: {10}",
                                              config.DaysToDownload, config.TheTVDBNumbers, config.PrefixEpisodeTitle, config.PrefixEpisodeDescription, config.AppendEpisodeDesc, config.OADOverride, config.TMDbCoverArt, config.IncludeSDLogos, config.AutoAddNew, config.CreateXmltv, config.ModernMediaUiPlusSupport));

            // populate station prefixes to suppress
            if (config.SuppressStationEmptyWarnings == null)
            {
                suppressedPrefixes = new List <string>(defaultSuppressedPrefixes.Split(','));
            }
            else
            {
                suppressedPrefixes = new List <string>(config.SuppressStationEmptyWarnings.Split(','));
            }

            // login to Schedules Direct and build the mxf file
            if (sdAPI.sdGetToken(config.UserAccount.LoginName, config.UserAccount.PasswordHash, ref errString))
            {
                // check server status
                sdUserStatusResponse susr = sdAPI.sdGetStatus();
                if (susr == null)
                {
                    return;
                }
                else if (susr.SystemStatus[0].Status.ToLower().Equals("offline"))
                {
                    Logger.WriteError("Schedules Direct server is offline. Aborting update.");
                    return;
                }

                // check for latest version and update the display name that shows in About Guide
                sdClientVersionResponse scvr = sdAPI.sdCheckVersion();
                if ((scvr != null) && !string.IsNullOrEmpty(scvr.Version))
                {
                    sdMxf.Providers[0].DisplayName += " v" + epg123Version;
                    if (epg123Version != scvr.Version)
                    {
                        sdMxf.Providers[0].DisplayName += string.Format(" (v{0} Available)", scvr.Version);
                        BrandLogo.updateAvailable       = true;
                    }
                }

                // make sure cache directory exists
                if (!Directory.Exists(Helper.Epg123CacheFolder))
                {
                    Directory.CreateDirectory(Helper.Epg123CacheFolder);
                }

                // initialize tmdb api
                tmdbAPI.Initialize(false);

                // prepopulate keyword groups
                initializeKeywordGroups();

                // read all image links archived in file
                getImageArchive();

                // read all included and excluded station from configuration
                populateIncludedExcludedStations(config.StationID);

                // if all components of the mxf file have been successfully created, save the file
                if (success = buildLineupServices() && serviceCountSafetyCheck() &&
                              getAllScheduleEntryMd5s(config.DaysToDownload) &&
                              buildAllProgramEntries() &&
                              buildAllGenericSeriesInfoDescriptions() && buildAllExtendedSeriesDataForUiPlus() &&
                              getAllMoviePosters() &&
                              getAllSeriesImages() &&
                              buildKeywords() &&
                              writeMxf())
                {
                    // create the xmltv file if desired
                    if (config.CreateXmltv && CreateXmltvFile())
                    {
                        writeXmltv();
                        ++processedObjects; reportProgress();
                    }

                    // save the image links
                    writeImageArchive();

                    // create the ModernMedia UI+ json file if desired
                    if (config.ModernMediaUiPlusSupport)
                    {
                        ModernMediaUiPlus.WriteModernMediaUiPlusJson(config.ModernMediaUiPlusJsonFilepath ?? null);
                        ++processedObjects; reportProgress();
                    }

                    // clean the cache folder of stale data
                    cleanCacheFolder();

                    Logger.WriteVerbose(string.Format("Downloaded and processed {0} of data from Schedules Direct.", sdAPI.TotalDownloadBytes));
                    Logger.WriteVerbose(string.Format("Generated .mxf file contains {0} services, {1} series, {2} programs, and {3} people with {4} image links.",
                                                      sdMxf.With[0].Services.Count, sdMxf.With[0].SeriesInfos.Count, sdMxf.With[0].Programs.Count, sdMxf.With[0].People.Count, sdMxf.With[0].GuideImages.Count));
                    Logger.WriteInformation("Completed EPG123 update execution. SUCCESS.");
                }
                else
                {
                    Logger.WriteError("Failed to create MXF file. Exiting.");
                }
            }
            else
            {
                Logger.WriteError(string.Format("Failed to retrieve token from Schedules Direct. message: {0}", errString));
            }
        }