public frmLineups() { InitializeComponent(); // get current lineups oldLineups = sdAPI.sdGetLineups(); if ((oldLineups == null) || (oldLineups.Lineups == null) || (oldLineups.Lineups.Count == 0)) { return; } // populate listview with current lineups foreach (SdLineup lineup in oldLineups.Lineups) { listView1.Items.Add(new ListViewItem(new string[] { lineup.Transport, lineup.Name, lineup.Location, lineup.Lineup }) { Tag = lineup.Lineup, ToolTipText = lineup.Lineup }); } // adjust components for screen dpi using (Graphics g = CreateGraphics()) { if ((g.DpiX != 96) || (g.DpiY != 96)) { // adjust column widths for list views foreach (ColumnHeader column in listView1.Columns) { column.Width = (int)(column.Width * g.DpiX / 96) - 1; } } } }
public static SdLineupResponse sdGetLineups() { var sr = sdGetRequestResponse(METHODS.GET, "lineups"); if (sr == null) { Logger.WriteError("Did not receive a response from Schedules Direct for a client lineup listings."); return(null); } try { SdLineupResponse ret = JsonConvert.DeserializeObject <SdLineupResponse>(sr); switch (ret.Code) { case 0: Logger.WriteVerbose("Successfully requested listing of client lineups from Schedules Direct."); return(ret); default: break; } Logger.WriteError(string.Format("Failed request for listing of client lineups. code: {0} , message: {1}", ret.Code, sdErrorLookup(ret.Code))); } catch (Exception ex) { Logger.WriteError(string.Format("sdGetLineups() Unknown exception thrown. Message: {0}", ex.Message)); } return(null); }
private static bool buildLineupServices() { // query what lineups client is subscribed to SdLineupResponse clientLineups = sdAPI.sdGetLineups(); if (clientLineups == null) { return(false); } // determine if there are custom lineups to consider if (File.Exists(Helper.Epg123CustomLineupsXmlPath)) { CustomLineups customLineups = new CustomLineups(); using (StreamReader stream = new StreamReader(Helper.Epg123CustomLineupsXmlPath, Encoding.Default)) { XmlSerializer serializer = new XmlSerializer(typeof(CustomLineups)); TextReader reader = new StringReader(stream.ReadToEnd()); customLineups = (CustomLineups)serializer.Deserialize(reader); reader.Close(); } foreach (CustomLineup lineup in customLineups.CustomLineup) { if (!config.IncludedLineup.Contains(lineup.Lineup)) { continue; } customLineup = lineup; clientLineups.Lineups.Add(new SdLineup() { Lineup = lineup.Lineup, Name = lineup.Name, Transport = string.Empty, Location = lineup.Location, Uri = "CUSTOM", IsDeleted = false }); customMap = new SdStationMapResponse(); customMap.Map = new List <SdLineupMap>(); customMap.Stations = new List <SdLineupStation>(); customMap.Metadata = new sdMetadata() { Lineup = lineup.Lineup }; } } // reset counters processedObjects = 0; totalObjects = clientLineups.Lineups.Count; reportProgress(); // process lineups Logger.WriteMessage(string.Format("Entering buildLineupServices() for {0} lineups.", clientLineups.Lineups.Count)); foreach (SdLineup clientLineup in clientLineups.Lineups) { bool flagCustom = (!string.IsNullOrEmpty(clientLineup.Uri) && clientLineup.Uri.Equals("CUSTOM")); ++processedObjects; reportProgress(); // request the lineup's station maps SdStationMapResponse lineupMap = null; if (!flagCustom) { lineupMap = sdAPI.sdGetStationMaps(clientLineup.Lineup); if (lineupMap == null) { continue; } foreach (SdLineupStation station in lineupMap.Stations) { if (!allStations.ContainsKey(station.StationID)) { allStations.Add(station.StationID, station); } } } if (!config.IncludedLineup.Contains(clientLineup.Lineup)) { Logger.WriteVerbose(string.Format("Subscribed lineup {0} has been EXCLUDED from download and processing.", clientLineup.Lineup)); continue; } else if (clientLineup.IsDeleted) { Logger.WriteWarning(string.Format("Subscribed lineup {0} has been DELETED at the headend.", clientLineup.Lineup)); continue; } else if (flagCustom) { foreach (CustomStation station in customLineup.Station) { SdLineupStation lineupStation; if (allStations.TryGetValue(station.StationId, out lineupStation)) { customMap.Map.Add(new SdLineupMap() { StationID = station.StationId, AtscMajor = int.Parse(station.Number), AtscMinor = int.Parse(station.Subnumber) }); customStations.Add(station.StationId); customMap.Stations.Add(lineupStation); } else if (!string.IsNullOrEmpty(station.Alternate) && allStations.TryGetValue(station.Alternate, out lineupStation)) { customMap.Map.Add(new SdLineupMap() { StationID = station.Alternate, AtscMajor = int.Parse(station.Number), AtscMinor = int.Parse(station.Subnumber) }); customStations.Add(station.Alternate); customMap.Stations.Add(lineupStation); } } lineupMap = customMap; Logger.WriteVerbose(string.Format("Successfully retrieved the station mapping for lineup {0}.", clientLineup.Lineup)); } if (lineupMap == null) { return(false); } int lineupIndex = sdMxf.With[0].Lineups.Count; sdMxf.With[0].Lineups.Add(new MxfLineup() { index = lineupIndex + 1, Uid = clientLineup.Lineup, Name = "EPG123 " + clientLineup.Name + " (" + clientLineup.Location + ")", channels = new List <MxfChannel>() }); // build the services and lineup foreach (SdLineupStation station in lineupMap.Stations) { // check if station should be downloaded and processed if (!flagCustom) { if ((station == null) || (excludedStations.Contains(station.StationID) && !customStations.Contains(station.StationID))) { continue; } if (!includedStations.Contains(station.StationID) && !config.AutoAddNew) { Logger.WriteWarning(string.Format("**** Lineup {0} ({1}) has added station {2} ({3}). ****", clientLineup.Name, clientLineup.Location, station.StationID, station.Callsign)); continue; } } // build the service if necessary MxfService mxfService = sdMxf.With[0].getService(station.StationID); if (string.IsNullOrEmpty(mxfService.CallSign)) { // add callsign and station name mxfService.CallSign = station.Callsign; mxfService.Name = station.Name; // add affiliate if available if (!string.IsNullOrEmpty(station.Affiliate)) { mxfService.Affiliate = sdMxf.With[0].getAffiliateId(station.Affiliate); } // set the ScheduleEntries service id mxfService.mxfScheduleEntries.Service = mxfService.Id; // add station logo if available and allowed string logoPath = string.Format("{0}\\{1}.png", Helper.Epg123LogosFolder, station.Callsign); if (config.IncludeSDLogos) { // make sure logos directory exists if (!Directory.Exists(Helper.Epg123LogosFolder)) { Directory.CreateDirectory(Helper.Epg123LogosFolder); } // add the existing logo or download the new logo if available if (File.Exists(logoPath)) { mxfService.LogoImage = sdMxf.With[0].getGuideImage("file://" + logoPath, getStringEncodedImage(logoPath)).Id; } else { string url = string.Empty; if ((station.StationLogos != null) && (station.StationLogos.Count > 0)) { // the second station logo is typically the best contrast url = station.StationLogos[Math.Min(station.StationLogos.Count - 1, 1)].URL; } else if (station.Logo != null) { url = station.Logo.URL; } // download, crop & resize logo image, save and add if (!string.IsNullOrEmpty(url)) { stationLogosToDownload.Add(new KeyValuePair <MxfService, string>(mxfService, url)); } } } // handle xmltv logos SdStationImage logoImage = (station.StationLogos != null) ? station.StationLogos[station.StationLogos.Count - 1] : station.Logo; if (config.XmltvIncludeChannelLogos.ToLower().Equals("url") && (logoImage != null)) { mxfService.logoImage = logoImage; } else if (config.XmltvIncludeChannelLogos.ToLower().Equals("local") && File.Exists(logoPath)) { Image image = Image.FromFile(logoPath); mxfService.logoImage = new SdStationImage() { URL = logoPath, Height = image.Height, Width = image.Width }; } else if (config.XmltvIncludeChannelLogos.ToLower().Equals("substitute") && File.Exists(logoPath)) { Image image = Image.FromFile(logoPath); mxfService.logoImage = new SdStationImage() { URL = string.Format("{0}\\{1}.png", config.XmltvLogoSubstitutePath.TrimEnd('\\'), station.Callsign), Height = image.Height, Width = image.Width }; } } // use hashset to make sure we don't duplicate channel entries for this station HashSet <string> channelNumbers = new HashSet <string>(); // match station with mapping for lineup number and subnumbers foreach (SdLineupMap map in lineupMap.Map) { int number = -1; int subnumber = 0; if (map.StationID.Equals(station.StationID)) { // QAM if (map.ChannelMajor > 0) { number = map.ChannelMajor; subnumber = map.ChannelMinor; } // ATSC or NTSC else if (map.AtscMajor > 0) { number = map.AtscMajor; subnumber = map.AtscMinor; } else if (map.UhfVhf > 0) { number = map.UhfVhf; } // Cable or Satellite else if (!string.IsNullOrEmpty(map.Channel)) { subnumber = 0; if (Regex.Match(map.Channel, @"[A-Za-z]{1}[\d]{4}").Length > 0) { // 4dtv has channels starting with 2 character satellite identifier number = int.Parse(map.Channel.Substring(2)); } else if (!int.TryParse(Regex.Replace(map.Channel, "[^0-9.]", ""), out number)) { // if channel number is not a whole number, must be a decimal number string[] numbers = Regex.Replace(map.Channel, "[^0-9.]", "").Replace('_', '.').Replace('-', '.').Split('.'); if (numbers.Length == 2) { number = int.Parse(numbers[0]); subnumber = int.Parse(numbers[1]); } } } string channelNumber = number.ToString() + ((subnumber > 0) ? "." + subnumber.ToString() : null); if (channelNumbers.Add(channelNumber + ":" + station.StationID)) { addLineupChannel(lineupMap.Metadata.Lineup, mxfService.StationID, mxfService.Id, number, subnumber, lineupIndex); } } } } } if (stationLogosToDownload.Count > 0) { stationLogosDownloadComplete = false; Logger.WriteInformation(string.Format("Kicking off background worker to download and process {0} station logos.", stationLogosToDownload.Count)); backgroundDownloader = new System.ComponentModel.BackgroundWorker(); backgroundDownloader.DoWork += BackgroundDownloader_DoWork; backgroundDownloader.RunWorkerCompleted += BackgroundDownloader_RunWorkerCompleted; backgroundDownloader.WorkerSupportsCancellation = true; backgroundDownloader.RunWorkerAsync(); } if (sdMxf.With[0].Services.Count > 0) { Logger.WriteMessage("Exiting buildLineupServices(). SUCCESS."); return(true); } else { Logger.WriteError(string.Format("There are 0 stations queued for download from {0} subscribed lineups. Exiting.", clientLineups.Lineups.Count)); Logger.WriteError("Check that lineups are 'INCLUDED' and stations are selected in the EPG123 GUI."); return(false); } }