- Thread starter
- #21
I'm still not familiar with the peculiarities of the MediaPortal code. My apologies. And even less with GitHub. More apologies. I prefer to answer here
At this time, the code is as follows
This code it's just a drop in the ocean, and far from the complexity of developing a mobile driver to manage MediaPortal, but this procedure is used a lot of times.
My only intention is that, this method work efficiently and quickly (of course without errors)
Greetings from Spain!
This entry point is not used anymore, so is more simple....delete it?Code:[Obsolete("Method1 is deprecated, please use Method2 instead.")]
You are rigth. This question stuck in my inkwell. Fixed.Usually it's good to set some decent timeout like 20 or 30 seconds. At least in Java world defaults can be very long like minutes or even infinite so I would put wReq.Timeout = 20000 after wReq.Accept
ThanksLooks good to me
This have been tested with bad results. I prefer to keep it that way, but read again c) from my initial solutions, at the start of this post. (a little joke)using (Stream response = wReq.GetResponse().GetResponseStream()) ?.
At this time, the code is as follows
Code:
[Obsolete("This entry point is deprecated, please use DownLoadImage(string strURL, string strFile) instead")]
public static void DownLoadImage(string strURL, string strFile, System.Drawing.Imaging.ImageFormat imageFormat)
{
if ((string.IsNullOrEmpty(strURL)) || (string.IsNullOrEmpty(strFile)))
return;
DownLoadImage(strURL, strFile);
}
/// <summary>
/// Download a remote image and save it locally.
/// UserAgent and Accept headers are set for correct request.
/// Error handling is not responsibility of this method and should be done by method caller as seen fit
/// see https://forum.team-mediaportal.com/posts/1096988 for more details
/// </summary>
/// <param name="strURL">remote image to download</param>
/// <param name="strFile">local image to save</param>
public static void DownLoadImage(string strURL, string strFile)
{
if ((string.IsNullOrEmpty(strURL)) || (string.IsNullOrEmpty(strFile)))
{
return;
}
Uri uri = new Uri(strURL);
HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(uri);
wReq.Proxy.Credentials = CredentialCache.DefaultCredentials;
wReq.UserAgent = "Mozilla/8.0 (compatible; MSIE 9.0; Windows NT 6.1; .NET CLR 1.0.3705;)";
wReq.Accept = "*/*";
wReq.Timeout = 20000;
using (HttpWebResponse wr = (HttpWebResponse)wReq.GetResponse())
{
using (Stream br = wr.GetResponseStream())
{
using (FileStream fs = new FileStream(strFile, FileMode.OpenOrCreate, FileAccess.Write))
{
br.CopyTo(fs);
}
}
}
}
This code it's just a drop in the ocean, and far from the complexity of developing a mobile driver to manage MediaPortal, but this procedure is used a lot of times.
My only intention is that, this method work efficiently and quickly (of course without errors)
Greetings from Spain!
Last edited: