• 0

Need with with Imgur program


Question

Hey guys,

I wanted to work on a new project just for fun, so I thought a program that downloaded imgur galleries would be cool. I am working on it, but the program will run through duplicates after 51 images usually.

I've looked at all i can and can't find the problem. My guess is that it's the server resetting me. I wanted a challenge so i tried to get past it. I tried creating a new url connection each time, I also created a seperate class that did the downloading and creating a new object of that class everytime but it didn't work.

Thoughts?

Source

http://shayconcepts.com/programming/ImgurGalleryDownloader/imgurDL.zip

Link to comment
Share on other sites

19 answers to this question

Recommended Posts

  • 0

You are parsing the HTML page. Don't do that. Use imgur's API instead - from the documentation, you can just append ".xml" to any gallery page and it returns the gallery as an XML file.

In general, don't parse HTML pages unless there is no other way. It's not easy and it can change any day, making your program useless.

Link to comment
Share on other sites

  • 0

You are parsing the HTML page. Don't do that. Use imgur's API instead - from the documentation, you can just append ".xml" to any gallery page and it returns the gallery as an XML file.

In general, don't parse HTML pages unless there is no other way. It's not easy and it can change any day, making your program useless.

Thanks! I'll take a look.

EDIT: it seems it only returns 56 images though :/

I learned about regex and it has worked really well for me! I'll take a look at your link and find a better way to parse HTML. Thanks!

Link to comment
Share on other sites

  • 0
I learned about regex and it has worked really well for me! I'll take a look at your link and find a better way to parse HTML. Thanks!
If you really need to parse HTML, you should use a proper HTML library; for Java there is HtmlUnit and Jsoup at least. Better would be to not parse any HTML and use imgur's API as Aethec suggested.
Link to comment
Share on other sites

  • 0

If you really need to parse HTML, you should use a proper HTML library; for Java there is HtmlUnit and Jsoup at least. Better would be to not parse any HTML and use imgur's API as Aethec suggested.

But when using the API, I append the .xml but it doesn't show ALL the images in the gallery

Link to comment
Share on other sites

  • 0

To get other pages, append /page/XXX to an existing gallery URL. XXX is the page number. Don't forget the .xml, too.

Thank you so much!! How did you find this? The API doc?

Link to comment
Share on other sites

  • 0

So Im using an XML parser and the /page/#.xml and it's working perfectly! Superb help! Thanks guys!

Now if a server disconnects me, how can I reestablish a connection, as if I had restarted my program.

Link to comment
Share on other sites

  • 0

try {

// le magic

} catch (Exception e)

{

// re-establish connection

}

catch (ConnectException e) ... always catch the specific exception you want, and never the base class of all exceptions.
Link to comment
Share on other sites

  • 0

If you're only downloading files from Imgur, you don't have to start or restart the connection - you just download files, and if the download fails, retry.

Hmm ok. Thanks! I will see what I can do.

Link to comment
Share on other sites

  • 0

Ok guys, I need some more help. How do I get the xml of an album? They are apparently different than galleries! The xml page isn't coming up. Or if there isn't an xml, what is recommended to get the images?

Ex

http://imgur.com/a/HKtAR/

It's all there in the API documentation: http://api.imgur.com/resources_anon#album

Example: http://api.imgur.com/2/album/HKtAR

Link to comment
Share on other sites

This topic is now closed to further replies.