Exemple #1
0
        public static bool DownloadFile(string url, string localFile)
        {
            WebClient webClient = new WebClient();

            webClient.Headers.Add("user-agent", Settings.UserAgent);

            // .NET 4.0: Use TLS v1.2. Many download sources no longer support the older and now insecure TLS v1.0/1.1 and SSL v3.
            ServicePointManager.SecurityProtocol = ( SecurityProtocolType )0xc00;

            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(localFile));
                if (!File.Exists(localFile) || ImageAllocator.LoadImageFastFromFile(localFile) == null)
                {
                    MPTVSeriesLog.Write("Downloading new file from: " + url, MPTVSeriesLog.LogLevel.Debug);
                    webClient.DownloadFile(url, localFile);
                }
                return(true);
            }
            catch (WebException)
            {
                MPTVSeriesLog.Write("File download failed from '{0}' to '{1}'", url, localFile);
                return(false);
            }
        }
Exemple #2
0
        static void appendLogos(List <string> logosForBuilding, ref Graphics g, int totalHeight, int totalWidth)
        {
            int          noImgs     = logosForBuilding.Count;
            List <Image> imgs       = new List <Image>();
            List <Size>  imgSizes   = new List <Size>();
            int          spacer     = 5;
            int          checkWidth = 0;
            // step one: get all sizes (not all logos are obviously square) and scale them to fit vertically
            Image single = null;
            float scale = 0, totalHeightf = (float)totalHeight;
            Size  tmp   = default(Size);
            int   x_pos = 0;

            for (int i = 0; i < logosForBuilding.Count; i++)
            {
                try
                {
                    single = ImageAllocator.LoadImageFastFromFile(logosForBuilding[i]);
                }
                catch (Exception)
                {
                    MPTVSeriesLog.Write("Could not load Image file... " + logosForBuilding[i]);
                    return;
                }
                scale       = totalHeightf / (float)single.Size.Height;
                tmp         = new Size((int)(single.Width * scale), (int)(single.Height * scale));
                checkWidth += tmp.Width;
                imgSizes.Add(tmp);
                imgs.Add(single);
            }
            // step two: check if we are too big horizontally and if so scale again
            checkWidth += imgSizes.Count * spacer;
            if (checkWidth > totalWidth)
            {
                scale = (float)checkWidth / (float)totalWidth;
                for (int i = 0; i < imgSizes.Count; i++)
                {
                    imgSizes[i] = new Size((int)(imgSizes[i].Width / scale), (int)(imgSizes[i].Height / scale));
                }
            }
            // step three: finally draw them
            for (int i = 0; i < imgs.Count; i++)
            {
                g.DrawImage(imgs[i], x_pos, totalHeight - imgSizes[i].Height, imgSizes[i].Width, imgSizes[i].Height);
                x_pos += imgSizes[i].Width + spacer;
            }
        }
Exemple #3
0
        static string buildLogoImage(List <string> logosForBuilding, bool firstOnly, int imgWidth, int imgHeight)
        {
            try
            {
                if (logosForBuilding.Count == 1 || (firstOnly && logosForBuilding.Count > 0))
                {
                    return(logosForBuilding[0]);
                }
                else if (logosForBuilding.Count > 1)
                {
                    tmpFile = string.Empty;
                    foreach (string logo in logosForBuilding)
                    {
                        tmpFile += System.IO.Path.GetFileNameWithoutExtension(logo);
                    }
                    tmpFile = Helper.PathCombine(pathfortmpfile, "TVSeriesDynLogo" + tmpFile + ".png");

                    Bitmap   b   = new Bitmap(imgWidth, imgHeight);
                    Image    img = b;
                    Graphics g   = Graphics.FromImage(img);
                    appendLogos(logosForBuilding, ref g, imgHeight, imgWidth);
                    if (Settings.isConfig)
                    {
                        b.Save(tmpFile);
                        return(tmpFile);
                    }
                    else
                    {
                        return(ImageAllocator.GetOtherImage(b, tmpFile, new Size(), true)); // don't resize in allocator
                    }
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch (Exception ex)
            {
                MPTVSeriesLog.Write("The Logo Building Engine generated an error: " + ex.Message);
                return(string.Empty);
            }
        }
Exemple #4
0
        static string getLogos(Level level, int imgHeight, int imgWidth, bool firstOnly, ref List <string> logosForBuilding)
        {
            string res = work(level, imgHeight, imgWidth, firstOnly, ref logosForBuilding);

            if (!Settings.isConfig && res != null && res.Length > 0 && res[0] != '[')
            {
                if (tmpEp != null && tmpEp.Image == res)
                {
                    return(ImageAllocator.GetOtherImage(res, new Size(), false)); // don't resize by allocator
                }
                else
                {
                    return(ImageAllocator.GetOtherImage(res, new Size(), true)); // don't resize by allocator
                }
            }
            else
            {
                return(res); // we build the memimage already
            }
        }
        private void onFacadeItemSelected(GUIListItem item, GUIControl parent)
        {
            // if this is not a message from the facade, exit
            if (parent != m_Facade && parent != m_Facade.FilmstripLayout &&
                parent != m_Facade.ThumbnailLayout && parent != m_Facade.ListLayout &&
                parent != m_Facade.PlayListLayout)
            {
                return;
            }

            if (item == null || item.TVTag == null)
            {
                return;
            }

            DBEpisode episode = item.TVTag as DBEpisode;

            if (episode == null || prevSelectedEpisode == episode)
            {
                return;
            }

            if (item.IsPlayed)
            {
                episode[DBOnlineEpisode.cWatched] = true;
            }

            // Push properties to skin
            TVSeriesPlugin.setGUIProperty(guiProperty.Title.ToString(), FieldGetter.resolveDynString(m_sFormatEpisodeTitle, episode));
            TVSeriesPlugin.setGUIProperty(guiProperty.Subtitle.ToString(), FieldGetter.resolveDynString(m_sFormatEpisodeSubtitle, episode));
            TVSeriesPlugin.setGUIProperty(guiProperty.Description.ToString(), FieldGetter.resolveDynString(m_sFormatEpisodeMain, episode));
            TVSeriesPlugin.setGUIProperty(guiProperty.Logos.ToString(), localLogos.getLogos(ref episode, TVSeriesPlugin.logosHeight, TVSeriesPlugin.logosWidth));
            TVSeriesPlugin.setGUIProperty(guiProperty.EpisodeImage.ToString(), ImageAllocator.GetEpisodeImage(episode));
            GUIPropertyManager.SetProperty("#selectedthumb", ImageAllocator.GetEpisodeImage(episode));

            TVSeriesPlugin.pushFieldsToSkin(episode, "Episode");

            // Some strange issues with logos when using mouse and hovering over current item
            // Dont push properties next time if the same episode is selected
            prevSelectedEpisode = episode;
        }
Exemple #6
0
        public static bool DownloadFile(string url, string localFile)
        {
            WebClient webClient = new WebClient();

            webClient.Headers.Add("user-agent", Settings.UserAgent);

            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(localFile));
                if (!File.Exists(localFile) || ImageAllocator.LoadImageFastFromFile(localFile) == null)
                {
                    MPTVSeriesLog.Write("Downloading new file from: " + url, MPTVSeriesLog.LogLevel.Debug);
                    webClient.DownloadFile(url, localFile);
                }
                return(true);
            }
            catch (WebException)
            {
                MPTVSeriesLog.Write("File download failed from '{0}' to '{1}'", url, localFile);
                return(false);
            }
        }
Exemple #7
0
        /// <summary>
        /// Takes an Image and tries to load it into MP' graphics memory
        /// If the sFileName was already in memory, it will not be reloaded (basically it caches)
        /// </summary>
        /// <param name="image">The System.Drawing.Bitmap to be loaded</param>
        /// <param name="identifier">A unique identifier for the image so it can be retrieved later on</param>
        /// <returns>memory identifier</returns>
        public static string buildMemoryImage(Image image, string identifier, System.Drawing.Size size, bool buildIdentifier)
        {
            string name = buildIdentifier ? ImageAllocator.buildIdentifier(identifier) : identifier;

            try
            {
                // we don't have to try first, if name already exists mp will not do anything with the image
                if (size.Height > 0 && (size.Height != image.Size.Height || size.Width != image.Size.Width)) //resize
                {
                    image = Resize(image, size);
                }
                PerfWatcher.GetNamedWatch("add to TextureManager").Start();
                //MPTVSeriesLog.WriteMultiLine("AsyncImageResource LoadFromMemory - " + Environment.StackTrace, MPTVSeriesLog.LogLevel.Debug);
                GUITextureManager.LoadFromMemory(image, name, 0, size.Width, size.Height);
                PerfWatcher.GetNamedWatch("add to TextureManager").Stop();
            }
            catch (Exception)
            {
                MPTVSeriesLog.Write("Unable to add to MP's Graphics memory: " + identifier);
                return(string.Empty);
            }
            return(name);
        }
        /// <summary>
        /// Sets the following Properties:
        /// "#Play.Current.Title"
        /// "#Play.Current.Plot"
        /// "#Play.Current.Thumb"
        /// "#Play.Current.Year"
        /// </summary>
        /// <param name="clear">Clears the properties instead of filling them if True</param>
        void SetGUIProperties(bool clear)
        {
            if (m_currentEpisode == null)
            {
                return;
            }

            DBSeries series = null;

            if (!clear)
            {
                series = Helper.getCorrespondingSeries(m_currentEpisode[DBEpisode.cSeriesID]);
            }
            DBSeason season = null;

            if (!clear)
            {
                season = Helper.getCorrespondingSeason(m_currentEpisode[DBEpisode.cSeriesID], m_currentEpisode[DBEpisode.cSeasonIndex]);
            }

            // Show Plot in OSD or Hide Spoilers (note: FieldGetter takes care of that)
            GUIPropertyManager.SetProperty("#Play.Current.Plot", clear ? " " : FieldGetter.resolveDynString(TVSeriesPlugin.m_sFormatEpisodeMain, m_currentEpisode));

            // Show Episode Thumbnail or Series Poster if Hide Spoilers is enabled
            string osdImage = string.Empty;

            if (!clear)
            {
                foreach (KeyValuePair <string, string> kvp in SkinSettings.VideoOSDImages)
                {
                    switch (kvp.Key)
                    {
                    case "episode":
                        osdImage = ImageAllocator.GetEpisodeImage(m_currentEpisode);
                        break;

                    case "season":
                        osdImage = season.Banner;
                        break;

                    case "series":
                        osdImage = series.Poster;
                        break;

                    case "custom":
                        string value = replaceDynamicFields(kvp.Value);
                        string file  = Helper.getCleanAbsolutePath(value);
                        if (System.IO.File.Exists(file))
                        {
                            osdImage = file;
                        }
                        break;
                    }

                    osdImage = osdImage.Trim();
                    if (string.IsNullOrEmpty(osdImage))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            GUIPropertyManager.SetProperty("#Play.Current.Thumb", clear ? " " : osdImage);

            // double check, i don't want play images to be cleared on ended or stopped...
            if (PlayPropertyUpdater.CancellationPending)
            {
                return;
            }

            foreach (KeyValuePair <string, string> kvp in SkinSettings.VideoPlayImages)
            {
                if (!clear)
                {
                    string value = replaceDynamicFields(kvp.Value);
                    string file  = Helper.getCleanAbsolutePath(value);
                    if (System.IO.File.Exists(file))
                    {
                        MPTVSeriesLog.Write(string.Format("Setting play image {0} for property {1}", file, kvp.Key), MPTVSeriesLog.LogLevel.Debug);
                        GUIPropertyManager.SetProperty(kvp.Key, clear ? " " : file);
                    }
                }
                else
                {
                    MPTVSeriesLog.Write(string.Format("Clearing play image for property {0}", kvp.Key), MPTVSeriesLog.LogLevel.Debug);
                    GUIPropertyManager.SetProperty(kvp.Key, " ");
                }
            }

            GUIPropertyManager.SetProperty("#Play.Current.Title", clear ? " " : m_currentEpisode.onlineEpisode.CompleteTitle);
            GUIPropertyManager.SetProperty("#Play.Current.Year", clear ? " " : FieldGetter.resolveDynString("<" + DBEpisode.cOutName + "." + DBOnlineEpisode.cFirstAired + ">", m_currentEpisode, false));
            GUIPropertyManager.SetProperty("#Play.Current.Genre", clear ? " " : FieldGetter.resolveDynString(TVSeriesPlugin.m_sFormatEpisodeSubtitle, m_currentEpisode));
        }
        /// <summary>
        /// Updates the movie metadata on the playback screen (for when the user clicks info).
        /// The delay is neccesary because Player tries to use metadata from the MyVideos database.
        /// We want to update this after that happens so the correct info is there.
        /// </summary>
        /// <param name="item">Playlist item</param>
        /// <param name="clear">Clears the properties instead of filling them if True</param>
        private void SetProperties(PlayListItem item, bool clear)
        {
            if (item == null)
            {
                return;
            }

            string   title  = string.Empty;
            DBSeries series = null;
            DBSeason season = null;

            if (!clear)
            {
                title  = string.Format("{0} - {1}x{2} - {3}", item.SeriesName, item.SeasonIndex, item.EpisodeIndex, item.EpisodeName);
                series = Helper.getCorrespondingSeries(item.Episode[DBEpisode.cSeriesID]);
                season = Helper.getCorrespondingSeason(item.Episode[DBEpisode.cSeriesID], int.Parse(item.SeasonIndex));
            }

            // Show Plot in OSD or Hide Spoilers (note: FieldGetter takes care of that)
            GUIPropertyManager.SetProperty("#Play.Current.Plot", clear ? " " : FieldGetter.resolveDynString(TVSeriesPlugin.m_sFormatEpisodeMain, item.Episode));

            // Show Episode Thumbnail or Series Poster if Hide Spoilers is enabled
            string osdImage = string.Empty;

            if (!clear)
            {
                foreach (KeyValuePair <string, string> kvp in SkinSettings.VideoOSDImages)
                {
                    switch (kvp.Key)
                    {
                    case "episode":
                        osdImage = ImageAllocator.GetEpisodeImage(item.Episode);
                        break;

                    case "season":
                        osdImage = season.Banner;
                        break;

                    case "series":
                        osdImage = series.Poster;
                        break;

                    case "custom":
                        string value = replaceDynamicFields(kvp.Value, item.Episode);
                        string file  = Helper.getCleanAbsolutePath(value);
                        if (System.IO.File.Exists(file))
                        {
                            osdImage = file;
                        }
                        break;
                    }

                    osdImage = osdImage.Trim();
                    if (string.IsNullOrEmpty(osdImage))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            GUIPropertyManager.SetProperty("#Play.Current.Thumb", clear ? " " : osdImage);

            foreach (KeyValuePair <string, string> kvp in SkinSettings.VideoPlayImages)
            {
                if (!clear)
                {
                    string value = replaceDynamicFields(kvp.Value, item.Episode);
                    string file  = Helper.getCleanAbsolutePath(value);
                    if (System.IO.File.Exists(file))
                    {
                        MPTVSeriesLog.Write(string.Format("Setting play image {0} for property {1}", file, kvp.Key), MPTVSeriesLog.LogLevel.Debug);
                        GUIPropertyManager.SetProperty(kvp.Key, clear ? " " : file);
                    }
                }
                else
                {
                    MPTVSeriesLog.Write(string.Format("Clearing play image for property {0}", kvp.Key), MPTVSeriesLog.LogLevel.Debug);
                    GUIPropertyManager.SetProperty(kvp.Key, " ");
                }
            }

            GUIPropertyManager.SetProperty("#Play.Current.Title", clear ? "" : title);
            GUIPropertyManager.SetProperty("#Play.Current.Year", clear ? "" : FieldGetter.resolveDynString("<" + DBEpisode.cOutName + "." + DBOnlineEpisode.cFirstAired + ">", item.Episode, false));
            GUIPropertyManager.SetProperty("#Play.Current.Genre", clear ? "" : FieldGetter.resolveDynString(TVSeriesPlugin.m_sFormatEpisodeSubtitle, item.Episode));
        }