Example #1
0
        private bool DownloadChannelLogos(ChannelLogos logos, IServiceSet serviceSet)
        {
            try
            {
                foreach (WebChannelBasic ch in channelLogosRequired)
                {
                    try
                    {
                        Stream logoStream = serviceSet.MASStream.GetImage(WebMediaType.TV, null, ch.Id.ToString());
                        Log.Trace("Downloaded logo for channel {0} (length {1})", ch.Title, logoStream.Length);
                        if (logoStream.Length > 0)
                        {
                            logos.WriteToCacheDirectory(ch.Title, "png", logoStream);
                        }
                    }
                    catch (EndpointNotFoundException)
                    {
                        Log.Trace("Logo for channel {0} not available on server", ch.Title);
                    }
                }

                return(true);
            }
            catch (MessageSecurityException)
            {
                return(false);
            }
        }
Example #2
0
        public override WebFileInfo GetFileInfo()
        {
            if ((MediaType == WebMediaType.TV || MediaType == WebMediaType.Recording) && FileType == WebFileType.Logo)
            {
                if (_logos == null)
                {
                    _logos = new ChannelLogos();
                }

                // get display name
                int idChannel = MediaType == WebMediaType.TV ?
                                Int32.Parse(Id) :
                                Connections.TAS.GetRecordingById(Int32.Parse(Id)).ChannelId;
                var    channel  = Connections.TAS.GetChannelBasicById(idChannel);
                string location = _logos.FindLocation(channel.Title);
                if (location == null)
                {
                    Log.Debug("Did not find tv logo for channel {0} with id {1}", channel.Title, idChannel);
                    return(new WebFileInfo()
                    {
                        Exists = false
                    });
                }

                // great, return it
                return(new WebFileInfo(location));
            }

            return(path != null ? new WebFileInfo(path) : base.GetFileInfo());
        }
Example #3
0
        private void Init()
        {
            // don't do anything if we don't have a TVE connection
            if (!TVAccessService.Instance.TestConnectionToTVService())
            {
                return;
            }

            // exit if we already got all logos
            logos = new ChannelLogos();
            ScanForRequiredLogos();
            if (channelLogosRequired.Count == 0)
            {
                Log.Trace("All channel logos already available, not downloading any...");
                return;
            }

            // try downloading them on starting and exit if successful
            if (PerformCheck())
            {
                return;
            }

            // setup timer
            backgroundTimer = new Timer()
            {
                AutoReset = true,
                Interval  = 60 * 60 * 1000,
            };
            backgroundTimer.Elapsed += new ElapsedEventHandler(TimerElapsed);
            backgroundTimer.Start();
        }
Example #4
0
        private bool DownloadChannelLogos(ChannelLogos logos, IServiceSet serviceSet)
        {
            try
            {
                foreach (WebChannelBasic ch in channelLogosRequired)
                {
                    try
                    {
                        Stream logoStream = serviceSet.MASStream.GetImage(WebMediaType.TV, null, ch.Id.ToString());
                        logos.WriteToCacheDirectory(ch.Title, "png", logoStream);
                        Log.Debug("Downloaded logo for channel {0}", ch.Title);
                    }
                    catch (EndpointNotFoundException)
                    {
                        Log.Trace("Logo for channel {0} not available on server", ch.Title);
                    }
                }

                return(true);
            }
            catch (MessageSecurityException)
            {
                return(false);
            }
            catch (Exception ex)
            {
                Log.Warn(String.Format("Failed to download channel logos from {0}", serviceSet), ex);
                return(false);
            }
        }
Example #5
0
        private void Init()
        {
            // load list of channel logos that we don't have yet
            logos = new ChannelLogos();
            ITVAccessService tas = TVAccessService.Instance;

            if (!tas.TestConnectionToTVService())
            {
                return;
            }
            channelLogosRequired = tas.GetChannelsBasic()
                                   .Where(ch => logos.FindLocation(ch.Title) == null)
                                   .ToList();

            // exit if we already got all logos
            if (channelLogosRequired.Count == 0)
            {
                Log.Trace("All channel logos already available, not downloading any...");
                return;
            }

            // try downloading them on starting and exit if successful
            if (PerformCheck())
            {
                return;
            }

            // setup timer
            backgroundTimer = new Timer()
            {
                AutoReset = true,
                Interval  = 60 * 60 * 1000,
            };
            backgroundTimer.Elapsed += new ElapsedEventHandler(TimerElapsed);
            backgroundTimer.Start();
        }
Example #6
0
        public override WebFileInfo GetFileInfo()
        {
            if (fileInfoCache != null)
            {
                return(fileInfoCache);
            }

            if (path != null)
            {
                fileInfoCache = new WebFileInfo(path);
                return(fileInfoCache);
            }

            if ((MediaType == WebMediaType.TV || MediaType == WebMediaType.Recording || MediaType == WebMediaType.Radio) && FileType == WebFileType.Logo)
            {
                if (_logos == null)
                {
                    _logos = new ChannelLogos();
                }

                // get display name
                int idChannel = MediaType == WebMediaType.TV || MediaType == WebMediaType.Radio ?
                                Int32.Parse(Id) :
                                Connections.TAS.GetRecordingById(Int32.Parse(Id)).ChannelId;
                var    channel  = Connections.TAS.GetChannelBasicById(idChannel);
                string location = _logos.FindLocation(channel.Title);
                if (location == null)
                {
                    Log.Debug("Did not find tv logo for channel {0} with id {1}", channel.Title, idChannel);
                    fileInfoCache = new WebFileInfo()
                    {
                        Exists = false
                    };
                    return(fileInfoCache);
                }

                // great, return it
                fileInfoCache = new WebFileInfo(location);
                return(fileInfoCache);
            }

            if (Offset < 0)
            {
                var artwork      = Connections.MAS.GetArtwork(Provider, MediaType, Id);
                var preferedItem = artwork.Where(x => x.Type == FileType)
                                   .OrderByDescending(x => x.Rating)
                                   .Skip(-1 - Offset)
                                   .FirstOrDefault();
                if (preferedItem == null)
                {
                    Log.Debug("Requested prefered artwork item for provider={0} mediatype={1} filetype={2} id={3}, but no artwork found",
                              Provider, MediaType, FileType, Id);
                    fileInfoCache = new WebFileInfo()
                    {
                        Exists = false
                    };
                    return(fileInfoCache);
                }

                fileInfoCache = Connections.MAS.GetFileInfo(Provider, MediaType, FileType, Id, preferedItem.Offset);
                return(fileInfoCache);
            }

            return(base.GetFileInfo());
        }