[Pending] - Utils: DownLoadImage failed when PageRequest need Header "User-Agent" | Page 3

Discussion in 'Submit: code patches (MediaPortal/TV-Server/etc.)' started by morfius, August 22, 2014.

  1. morfius

    morfius Portal Pro

    Joined:
    November 10, 2011
    Messages:
    40
    Likes Received:
    24
    Gender:
    Male
    Occupation:
    Technician Engineer
    Location:
    Valladolid
    Ratings:
    +42 / 0
    Home Country:
    Spain Spain
    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 (Text):
    1.  
    2.     [Obsolete("This entry point is deprecated, please use DownLoadImage(string strURL, string strFile) instead")]    
    3.     public static void DownLoadImage(string strURL, string strFile, System.Drawing.Imaging.ImageFormat imageFormat)
    4.     {
    5.       if ((string.IsNullOrEmpty(strURL)) || (string.IsNullOrEmpty(strFile)))
    6.         return;
    7.       DownLoadImage(strURL, strFile);
    8.     }
    9.  
    10.     /// <summary>
    11.     /// Download a remote image and save it locally.
    12.     /// UserAgent and Accept headers are set for correct request.
    13.     /// Error handling is not responsibility of this method and should be done by method caller as seen fit
    14.     /// see https://forum.team-mediaportal.com/posts/1096988 for more details
    15.     /// </summary>
    16.     /// <param name="strURL">remote image to download</param>
    17.     /// <param name="strFile">local image to save</param>
    18.     public static void DownLoadImage(string strURL, string strFile)
    19.     {
    20.       if ((string.IsNullOrEmpty(strURL)) || (string.IsNullOrEmpty(strFile)))
    21.       {
    22.         return;
    23.       }
    24.       Uri uri = new Uri(strURL);
    25.       HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(uri);
    26.       wReq.Proxy.Credentials = CredentialCache.DefaultCredentials;
    27.  
    28.       wReq.UserAgent = "Mozilla/8.0 (compatible; MSIE 9.0; Windows NT 6.1; .NET CLR 1.0.3705;)";
    29.       wReq.Accept = "*/*";
    30.       wReq.Timeout = 20000;
    31.  
    32.       using (HttpWebResponse wr = (HttpWebResponse)wReq.GetResponse())
    33.       {
    34.         using (Stream br = wr.GetResponseStream())
    35.         {
    36.           using (FileStream fs = new FileStream(strFile, FileMode.OpenOrCreate, FileAccess.Write))
    37.           {
    38.             br.CopyTo(fs);
    39.           }
    40.         }
    41.       }
    42.     }
    43.  
    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: September 7, 2014
    • Like Like x 4
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. morfius

    morfius Portal Pro

    Joined:
    November 10, 2011
    Messages:
    40
    Likes Received:
    24
    Gender:
    Male
    Occupation:
    Technician Engineer
    Location:
    Valladolid
    Ratings:
    +42 / 0
    Home Country:
    Spain Spain
    Hi Sebastiii. Sorry, but just read now your post.. My blood its fine (a little of cholesterol) but really... it's not new (far from it) ;) I think my better contribution to this project are about the information of films and tv shows, and perhaps, any isolated method or function needed for some part of the code.
    I understand all members here are pro-actives. I am technician engineer, developer (level medium), system administrator (many years) and considerable knowledges about SQL database.
    There are a Joke:..
    .- Who has some music knowledges?
    .- Me, sir.
    .- You. Load the piano of the Captain!
    I don't have any problems to Load the Piano, or to perform minor tasks.
    At this time, i'd like finish these tasks:
    One Convert HOWTO post to Wiki (Movie Info Grabbers)
    Two: This post


    Regards!
     
    • Like Like x 4
  4. Sebastiii
    • Team MediaPortal

    Sebastiii Development Group

    Joined:
    November 12, 2007
    Messages:
    16,270
    Likes Received:
    6,221
    Gender:
    Male
    Location:
    France
    Ratings:
    +10,229 / 9
    Home Country:
    France France
    Show System Specs
    Where we are with this post ? I didn't follow it and have pull request on github too :)
     
    • Thank You! Thank You! x 1
  5. morfius

    morfius Portal Pro

    Joined:
    November 10, 2011
    Messages:
    40
    Likes Received:
    24
    Gender:
    Male
    Occupation:
    Technician Engineer
    Location:
    Valladolid
    Ratings:
    +42 / 0
    Home Country:
    Spain Spain
    Hi Sebastiii. At this moment, in Github
    Closed with unmerged commits.
    So... The last version of the proposed routine is not merge in the code.
    I think it should include the last version before closing this post.
    I am in your hands to make any improvementes or to make any changes you want to.
    Greetings from Spain.
     
    • Thank You! Thank You! x 1
  6. Edalex
    • Premium Supporter

    Edalex Community Plugin Dev

    Joined:
    January 3, 2008
    Messages:
    2,907
    Likes Received:
    713
    Gender:
    Male
    Location:
    Saratov
    Ratings:
    +1,229 / 9
    Home Country:
    Russian Federation Russian Federation
    Show System Specs
    Nice to see new contributions to MP!
    I assume that error with downloading file was with scrapper so why don't we modify scraper itself instead of rewriting mediaportal code? Scrapper in C# so downloading with any webclient/webrequest is possible.
    Also I want to say that setting headers in download method is not so flexible. Some sites could require special headers i.e. "MediaPortal 1.1.0".
    So I think it will be better to have another method with more parameters like headers, gzip encoding and so on.
     
    • Like Like x 2
  7. Sebastiii
    • Team MediaPortal

    Sebastiii Development Group

    Joined:
    November 12, 2007
    Messages:
    16,270
    Likes Received:
    6,221
    Gender:
    Male
    Location:
    France
    Ratings:
    +10,229 / 9
    Home Country:
    France France
    Show System Specs
    For sure, i'm not the guy to improve it but, you are right it always welcome to see new contributions :)
     
    • Like Like x 1
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!