Reply to thread

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



This entry point is not used anymore, so is more simple....delete it?



You are rigth. This question stuck in my inkwell. Fixed.



Thanks



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)


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);

          }

        }

      }

    }

[/CODE]


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!


Top Bottom