Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .../TVLibrary/Plugins/XmlTvImport/XMLTVImport.cs | 13 +++++-
- TvEngine3/TVLibrary/TVDatabase/Program.cs | 23 +++++++--
- .../TVDatabase/TvBusinessLayer/BusinessLayer.cs | 11 +++--
- .../TVLibrary/TvPlugin/TvPlugin/TVScheduler.cs | 2 +
- TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVSearch.cs | 2 +
- .../TVLibrary/TvPlugin/TvPlugin/TvGuideBase.cs | 2 +
- mediaportal/Core/guilib/DownloadedImage.cs | 54 +++++++++++++++++-----
- mediaportal/Core/guilib/GUIImage.cs | 22 ++++++++-
- mediaportal/Core/guilib/GUITextureManager.cs | 38 ++++++++++++---
- 9 files changed, 140 insertions(+), 27 deletions(-)
- diff --git a/TvEngine3/TVLibrary/Plugins/XmlTvImport/XMLTVImport.cs b/TvEngine3/TVLibrary/Plugins/XmlTvImport/XMLTVImport.cs
- index feff189..1745cf5 100644
- --- a/TvEngine3/TVLibrary/Plugins/XmlTvImport/XMLTVImport.cs
- +++ b/TvEngine3/TVLibrary/Plugins/XmlTvImport/XMLTVImport.cs
- @@ -425,6 +425,7 @@ namespace TvEngine
- String nodeDate = null;
- String nodeStarRating = null;
- String nodeClassification = null;
- + String nodeIcon = null;
- XmlReader xmlProg = xmlReader.ReadSubtree();
- xmlProg.ReadStartElement(); // read programme
- @@ -475,6 +476,10 @@ namespace TvEngine
- if (nodeClassification == null) nodeClassification = xmlProg.ReadInnerXml();
- else xmlProg.Skip();
- break;
- + case "icon":
- + if (nodeIcon == null) nodeIcon = xmlProg.GetAttribute("src");
- + else xmlProg.Skip();
- + break;
- default:
- // unknown, skip entire node
- xmlProg.Skip();
- @@ -507,6 +512,7 @@ namespace TvEngine
- string episodePart = "";
- int starRating = -1;
- string classification = "";
- + string icon = "";
- string title = ConvertHTMLToAnsi(nodeTitle);
- @@ -666,6 +672,11 @@ namespace TvEngine
- classification = nodeClassification;
- }
- + if (nodeIcon != null)
- + {
- + icon = nodeIcon;
- + }
- +
- if (showProgress && ShowProgress != null && (_status.Programs % 100) == 0) ShowProgress(_status);
- #endregion
- @@ -710,7 +721,7 @@ namespace TvEngine
- Program prog = new Program(chan.IdChannel, longtodate(startDate), longtodate(stopDate), title,
- description, category, Program.ProgramState.None,
- System.Data.SqlTypes.SqlDateTime.MinValue.Value, seriesNum,
- - episodeNum, episodeName, episodePart, starRating, classification, -1);
- + episodeNum, episodeName, episodePart, starRating, classification, -1, icon);
- channelPrograms.programs.Add(prog);
- programIndex++;
- //prog.Description = ConvertHTMLToAnsi(strDescription);
- diff --git a/TvEngine3/TVLibrary/TVDatabase/Program.cs b/TvEngine3/TVLibrary/TVDatabase/Program.cs
- index 79c218a..6557de9 100644
- --- a/TvEngine3/TVLibrary/TVDatabase/Program.cs
- +++ b/TvEngine3/TVLibrary/TVDatabase/Program.cs
- @@ -50,6 +50,7 @@ namespace TvDatabase
- [TableColumn("starRating", NotNull = true)] private int starRating;
- [TableColumn("classification", NotNull = true)] private string classification;
- [TableColumn("parentalRating", NotNull = true)] private int parentalRating;
- + [TableColumn("icon", NotNull = true)] private string icon;
- #endregion
- @@ -80,7 +81,7 @@ namespace TvDatabase
- public Program(int idChannel, DateTime startTime, DateTime endTime, string title, string description, string genre,
- ProgramState state, DateTime originalAirDate, string seriesNum, string episodeNum, string episodeName,
- string episodePart, int starRating,
- - string classification, int parentalRating)
- + string classification, int parentalRating, string icon = "")
- {
- isChanged = true;
- this.idChannel = idChannel;
- @@ -98,6 +99,7 @@ namespace TvDatabase
- this.starRating = starRating;
- this.classification = classification;
- this.parentalRating = parentalRating;
- + this.icon = icon;
- }
- /// <summary>
- @@ -107,7 +109,7 @@ namespace TvDatabase
- public Program(int idProgram, int idChannel, DateTime startTime, DateTime endTime, string title, string description,
- string genre, ProgramState state, DateTime originalAirDate, string seriesNum, string episodeNum,
- string episodeName, string episodePart,
- - int starRating, string classification, int parentalRating)
- + int starRating, string classification, int parentalRating, string icon = "")
- {
- this.idProgram = idProgram;
- this.idChannel = idChannel;
- @@ -125,6 +127,7 @@ namespace TvDatabase
- this.starRating = starRating;
- this.classification = classification;
- this.parentalRating = parentalRating;
- + this.icon = icon;
- }
- #endregion
- @@ -538,6 +541,20 @@ namespace TvDatabase
- }
- }
- + /// <summary>
- + /// The programs icon (url) from the distributor
- + /// </summary>
- + public string Icon
- + {
- + get { return icon; }
- + set
- + {
- + isChanged |= icon != value;
- + icon = value;
- + }
- + }
- +
- +
- #endregion
- #region Storage and Retrieval
- @@ -1162,7 +1179,7 @@ namespace TvDatabase
- Program p = new Program(idProgram, idChannel, StartTime, EndTime, Title, Description, Genre, (ProgramState)state,
- OriginalAirDate,
- SeriesNum, EpisodeNum, EpisodeName, EpisodePart, StarRating, Classification,
- - parentalRating);
- + parentalRating, icon);
- return p;
- }
- diff --git a/TvEngine3/TVLibrary/TVDatabase/TvBusinessLayer/BusinessLayer.cs b/TvEngine3/TVLibrary/TVDatabase/TvBusinessLayer/BusinessLayer.cs
- index ab9d378..146dd01 100644
- --- a/TvEngine3/TVLibrary/TVDatabase/TvBusinessLayer/BusinessLayer.cs
- +++ b/TvEngine3/TVLibrary/TVDatabase/TvBusinessLayer/BusinessLayer.cs
- @@ -1468,7 +1468,8 @@ namespace TvDatabase
- Convert.ToString(prog["episodePart"]),
- Convert.ToInt32(prog["starRating"]),
- Convert.ToString(prog["classification"]),
- - Convert.ToInt32(prog["parentalRating"])
- + Convert.ToInt32(prog["parentalRating"]),
- + Convert.ToString(prog["icon"])
- );
- int idChannel = p.IdChannel;
- @@ -2602,7 +2603,7 @@ namespace TvDatabase
- List<Program> currentInserts = new List<Program>(aProgramList);
- sqlCmd.CommandText =
- - "INSERT INTO Program (idChannel, startTime, endTime, title, description, seriesNum, episodeNum, genre, originalAirDate, classification, starRating, state, parentalRating, episodeName, episodePart) VALUES (?idChannel, ?startTime, ?endTime, ?title, ?description, ?seriesNum, ?episodeNum, ?genre, ?originalAirDate, ?classification, ?starRating, ?state, ?parentalRating, ?episodeName, ?episodePart)";
- + "INSERT INTO Program (idChannel, startTime, endTime, title, description, seriesNum, episodeNum, genre, originalAirDate, classification, starRating, state, parentalRating, episodeName, episodePart, icon) VALUES (?idChannel, ?startTime, ?endTime, ?title, ?description, ?seriesNum, ?episodeNum, ?genre, ?originalAirDate, ?classification, ?starRating, ?state, ?parentalRating, ?episodeName, ?episodePart, ?icon)";
- sqlCmd.Parameters.Add("?idChannel", MySqlDbType.Int32);
- sqlCmd.Parameters.Add("?startTime", MySqlDbType.DateTime);
- @@ -2619,6 +2620,7 @@ namespace TvDatabase
- sqlCmd.Parameters.Add("?parentalRating", MySqlDbType.Int32);
- sqlCmd.Parameters.Add("?episodeName", MySqlDbType.Text);
- sqlCmd.Parameters.Add("?episodePart", MySqlDbType.Text);
- + sqlCmd.Parameters.Add("?icon", MySqlDbType.Text);
- try
- {
- @@ -2648,6 +2650,7 @@ namespace TvDatabase
- sqlCmd.Parameters["?parentalRating"].Value = prog.ParentalRating;
- sqlCmd.Parameters["?episodeName"].Value = prog.EpisodeName;
- sqlCmd.Parameters["?episodePart"].Value = prog.EpisodePart;
- + sqlCmd.Parameters["?icon"].Value = prog.Icon;
- try
- {
- // Finally insert all our data
- @@ -2791,7 +2794,7 @@ namespace TvDatabase
- List<Program> currentInserts = new List<Program>(aProgramList);
- sqlCmd.CommandText =
- - "INSERT INTO Program (idChannel, startTime, endTime, title, description, seriesNum, episodeNum, genre, originalAirDate, classification, starRating, state, parentalRating, episodeName, episodePart) VALUES (@idChannel, @startTime, @endTime, @title, @description, @seriesNum, @episodeNum, @genre, @originalAirDate, @classification, @starRating, @state, @parentalRating, @episodeName, @episodePart)";
- + "INSERT INTO Program (idChannel, startTime, endTime, title, description, seriesNum, episodeNum, genre, originalAirDate, classification, starRating, state, parentalRating, episodeName, episodePart, icon) VALUES (@idChannel, @startTime, @endTime, @title, @description, @seriesNum, @episodeNum, @genre, @originalAirDate, @classification, @starRating, @state, @parentalRating, @episodeName, @episodePart, @icon)";
- sqlCmd.Parameters.Add("idChannel", SqlDbType.Int);
- sqlCmd.Parameters.Add("startTime", SqlDbType.DateTime);
- @@ -2808,6 +2811,7 @@ namespace TvDatabase
- sqlCmd.Parameters.Add("parentalRating", SqlDbType.Int);
- sqlCmd.Parameters.Add("episodeName", SqlDbType.VarChar);
- sqlCmd.Parameters.Add("episodePart", SqlDbType.VarChar);
- + sqlCmd.Parameters.Add("icon", SqlDbType.VarChar);
- try
- {
- @@ -2837,6 +2841,7 @@ namespace TvDatabase
- sqlCmd.Parameters["parentalRating"].Value = prog.ParentalRating;
- sqlCmd.Parameters["episodeName"].Value = prog.EpisodeName;
- sqlCmd.Parameters["episodePart"].Value = prog.EpisodePart;
- + sqlCmd.Parameters["icon"].Value = prog.Icon;
- try
- {
- diff --git a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVScheduler.cs b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVScheduler.cs
- index b6ca596..8a1da91 100644
- --- a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVScheduler.cs
- +++ b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVScheduler.cs
- @@ -1291,6 +1291,7 @@ namespace TvPlugin
- GUIPropertyManager.SetProperty("#TV.Scheduled.Description", String.Empty);
- GUIPropertyManager.SetProperty("#TV.Scheduled.thumb", String.Empty);
- GUIPropertyManager.SetProperty("#TV.Scheduled.Channel", String.Empty);
- + GUIPropertyManager.SetProperty("#TV.Scheduled.Icon", String.Empty);
- if (prog != null)
- {
- @@ -1307,6 +1308,7 @@ namespace TvPlugin
- schedule.EndTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat));
- GUIPropertyManager.SetProperty("#TV.Scheduled.Time", strTime);
- + GUIPropertyManager.SetProperty("#TV.Scheduled.Icon", prog.Icon);
- if (schedule.IdChannel < 0)
- {
- diff --git a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVSearch.cs b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVSearch.cs
- index 6e43cfd..91b6ea3 100644
- --- a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVSearch.cs
- +++ b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TVSearch.cs
- @@ -1290,6 +1290,7 @@ namespace TvPlugin
- GUIPropertyManager.SetProperty("#TV.Search.Description", String.Empty);
- GUIPropertyManager.SetProperty("#TV.Search.thumb", String.Empty);
- GUIPropertyManager.SetProperty("#TV.Search.Channel", String.Empty);
- + GUIPropertyManager.SetProperty("#TV.Search.Icon", String.Empty);
- if (prog == null)
- {
- // see comment at top of method
- @@ -1319,6 +1320,7 @@ namespace TvPlugin
- GUIPropertyManager.SetProperty("#TV.Search.Description", prog.Description);
- GUIPropertyManager.SetProperty("#TV.Search.Genre", prog.Genre);
- GUIPropertyManager.SetProperty("#TV.Search.Channel", prog.ReferencedChannel().DisplayName);
- + GUIPropertyManager.SetProperty("#TV.Search.Icon", prog.Icon);
- // see comment at top of method
- //lblProgramTitle.Label = TVUtil.GetDisplayTitle(prog);
- diff --git a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvGuideBase.cs b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvGuideBase.cs
- index 971e9a5..96e3a94 100644
- --- a/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvGuideBase.cs
- +++ b/TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvGuideBase.cs
- @@ -1242,6 +1242,7 @@ namespace TvPlugin
- GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.Duration", String.Empty);
- GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.DurationMins", String.Empty);
- GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.TimeFromNow", String.Empty);
- + GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.Icon", String.Empty);
- _currentStartTime = 0;
- _currentEndTime = 0;
- @@ -1284,6 +1285,7 @@ namespace TvPlugin
- GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.TimeFromNow", GetStartTimeFromNow(_currentProgram));
- GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.Episode", _currentProgram.EpisodeNumber);
- GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.SubTitle", _currentProgram.EpisodeName);
- + GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.Icon", _currentProgram.Icon);
- if (_currentProgram.Classification == "")
- {
- diff --git a/mediaportal/Core/guilib/DownloadedImage.cs b/mediaportal/Core/guilib/DownloadedImage.cs
- index e29e5a0..acaa310 100644
- --- a/mediaportal/Core/guilib/DownloadedImage.cs
- +++ b/mediaportal/Core/guilib/DownloadedImage.cs
- @@ -22,6 +22,7 @@ using System;
- using System.IO;
- using System.Net;
- using MediaPortal.Configuration;
- +using System.Text.RegularExpressions;
- namespace MediaPortal.GUI.Library
- {
- @@ -34,31 +35,56 @@ namespace MediaPortal.GUI.Library
- private string _url;
- private DateTime _dateDownloaded = DateTime.MinValue;
- private int _cacheMinutes = 60 * 30; //30minutes
- + private bool _shouldSave = false;
- - public DownloadedImage(string url)
- + public DownloadedImage(string url, bool shouldsave=false)
- {
- URL = url;
- int pos = url.LastIndexOf("/");
- +
- + if (shouldsave)
- + {
- + _shouldSave = true;
- + _cacheMinutes = 60 * 60 * 24 * 3; // 3 days
- + }
- _fileName = GetTempFileName();
- }
- private string GetTempFileName()
- {
- - int x = 0;
- - while (true)
- + Regex rgx = new Regex(@"[^\w]+", RegexOptions.IgnoreCase);
- + string tempURL = rgx.Replace(_url, "");
- + if (tempURL.Length > 100)
- + {
- + tempURL = tempURL.Substring(tempURL.Length - 100);
- + }
- + string filePrefix = "MPTemp-";
- + if (_shouldSave)
- {
- - string tempFile = Config.GetFile(Config.Dir.Thumbs, String.Format("MPTemp{0}.gif", x));
- - string tempFile2 = Config.GetFile(Config.Dir.Thumbs, String.Format("MPTemp{0}.jpg", x));
- - string tempFile3 = Config.GetFile(Config.Dir.Thumbs, String.Format("MPTemp{0}.bmp", x));
- - if (!File.Exists(tempFile) &&
- - !File.Exists(tempFile2) &&
- - !File.Exists(tempFile3))
- + filePrefix = @"Web\";
- + string thumbspath = Config.GetSubFolder(Config.Dir.Thumbs, @"Web\");
- + if (!Directory.Exists(thumbspath))
- {
- - return tempFile;
- + Directory.CreateDirectory(Config.GetSubFolder(Config.Dir.Thumbs, @"Web\"));
- }
- - ++x;
- }
- +
- + foreach (string ext in new string[] { "gif", "jpg", "png", "bmp" })
- + {
- + string tempFile = Config.GetFile(Config.Dir.Thumbs, String.Format("{0}{1}.{2}", filePrefix, tempURL, ext));
- + if (File.Exists(tempFile))
- + {
- + if (_dateDownloaded == DateTime.MinValue)
- + {
- + _dateDownloaded = DateTime.Now;
- + }
- + System.IO.File.SetLastWriteTimeUtc(tempFile, DateTime.UtcNow);
- + return tempFile;
- + }
- + }
- +
- + return Config.GetFile(Config.Dir.Thumbs, String.Format("{0}{1}.gif", filePrefix, tempURL));
- }
- @@ -85,7 +111,7 @@ namespace MediaPortal.GUI.Library
- get
- {
- TimeSpan ts = DateTime.Now - _dateDownloaded;
- - if (ts.TotalSeconds > CacheTime)
- + if (ts.TotalSeconds > CacheTime && (!_shouldSave || _dateDownloaded == DateTime.MinValue))
- {
- return true;
- }
- @@ -126,6 +152,10 @@ namespace MediaPortal.GUI.Library
- {
- extension = ".jpg";
- }
- + if (contentType.IndexOf("png") >= 0)
- + {
- + extension = ".png";
- + }
- if (contentType.IndexOf("bmp") >= 0)
- {
- extension = ".bmp";
- diff --git a/mediaportal/Core/guilib/GUIImage.cs b/mediaportal/Core/guilib/GUIImage.cs
- index 08a252f..2aae4a7 100644
- --- a/mediaportal/Core/guilib/GUIImage.cs
- +++ b/mediaportal/Core/guilib/GUIImage.cs
- @@ -82,7 +82,8 @@ namespace MediaPortal.GUI.Library
- [XMLSkin("texture", "flipY")] protected bool _flipY = false;
- [XMLSkin("texture", "diffuse")] protected string _diffuseFileName = "";
- [XMLSkin("texture", "overlay")] protected string _overlayFileName = "";
- - [XMLSkin("texture", "mask")] protected string _maskFileName = "";
- + [XMLSkin("texture", "mask")] protected string _maskFileName = "";
- + [XMLSkin("texture", "save")] protected bool _websave = false; // Hint from the skin to look/save this image locally if it is downloaded
- [XMLSkinElement("filtered")] protected bool _filterImage = true;
- [XMLSkinElement("align")] protected Alignment _imageAlignment = Alignment.ALIGN_LEFT;
- [XMLSkinElement("valign")] protected VAlignment _imageVAlignment = VAlignment.ALIGN_TOP;
- @@ -453,7 +454,24 @@ namespace MediaPortal.GUI.Library
- {
- get { return _imagePath; }
- set { _imagePath = value; }
- + }
- +
- + /// <summary>
- + /// Get/Set if the web image should be saved between MP sessions.
- + /// </summary>
- + public bool WebSave
- + {
- + get { return _websave; }
- + set
- + {
- + if (_websave != value)
- + {
- + _websave = value;
- + _reCalculate = true;
- + }
- + }
- }
- +
- /// <summary>
- /// Get the transparent color.
- @@ -714,7 +732,7 @@ namespace MediaPortal.GUI.Library
- }
- else
- {
- - frameCount = GUITextureManager.Load(fileName, m_dwColorKey, m_iRenderWidth, _textureHeight, _shouldCache);
- + frameCount = GUITextureManager.Load(fileName, m_dwColorKey, m_iRenderWidth, _textureHeight, _shouldCache, _websave);
- }
- if (frameCount == 0)
- diff --git a/mediaportal/Core/guilib/GUITextureManager.cs b/mediaportal/Core/guilib/GUITextureManager.cs
- index 45fdc68..1a81833 100644
- --- a/mediaportal/Core/guilib/GUITextureManager.cs
- +++ b/mediaportal/Core/guilib/GUITextureManager.cs
- @@ -88,6 +88,32 @@ namespace MediaPortal.GUI.Library
- {
- }
- }
- + }
- +
- +
- + files = null;
- +
- + try
- + {
- + files = Directory.GetFiles(Config.GetFolder(Config.Dir.Thumbs), @"Web\*.*");
- + }
- + catch { }
- +
- + if (files != null)
- + {
- + foreach (string file in files)
- + {
- + try
- + {
- + if ((DateTime.Now - File.GetLastWriteTime(file)).TotalDays >= 3) // Delete web cached files untouched for 3 or more days
- + {
- + File.Delete(file);
- + }
- + }
- + catch (Exception)
- + {
- + }
- + }
- }
- }
- }
- @@ -147,7 +173,7 @@ namespace MediaPortal.GUI.Library
- return result;
- }
- - private static string GetFileName(string fileName)
- + private static string GetFileName(string fileName, bool shouldsave = false)
- {
- if (fileName.Length == 0)
- {
- @@ -157,13 +183,13 @@ namespace MediaPortal.GUI.Library
- {
- return "";
- }
- - string lowerFileName = fileName.ToLowerInvariant().Trim();
- - if (lowerFileName.IndexOf(@"http:") >= 0)
- + string lowerFileName = fileName.ToLowerInvariant().Trim();
- + if (lowerFileName.IndexOf(@"http:") >= 0 || lowerFileName.IndexOf(@"https:") >= 0)
- {
- DownloadedImage image;
- if (!_cacheDownload.TryGetValue(lowerFileName, out image))
- {
- - image = new DownloadedImage(fileName);
- + image = new DownloadedImage(fileName, shouldsave);
- _cacheDownload[lowerFileName] = image;
- }
- @@ -190,9 +216,9 @@ namespace MediaPortal.GUI.Library
- return Load(fileNameOrg, lColorKey, iMaxWidth, iMaxHeight, false);
- }
- - public static int Load(string fileNameOrg, long lColorKey, int iMaxWidth, int iMaxHeight, bool persistent)
- + public static int Load(string fileNameOrg, long lColorKey, int iMaxWidth, int iMaxHeight, bool persistent, bool shouldsave=false)
- {
- - string fileName = GetFileName(fileNameOrg);
- + string fileName = GetFileName(fileNameOrg, shouldsave);
- string cacheKey = fileName.ToLowerInvariant();
- if (String.IsNullOrEmpty(fileName))
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement