Thread: [Java] MediaFire Utility

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 [Java] MediaFire Utility 
    Registered Member
    Emily's Avatar
    Join Date
    Jul 2010
    Age
    20
    Posts
    603
    Thanks
    65
    Thanked 206 Times in 119 Posts
    Rep Power
    269
    Simple class that just generates the hyper link from the URL and then downloads the file to an output folder (change the resources/ portion if you have a different output directory). Downloads to the original file type and file name of the uploaded file, so no need to specify that. Enjoy.

    Code:
    package org.runeception.utilities.web;
    
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.BufferedReader;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.logging.Logger;
    /**
     * Downloads Files off MediaFire's Web Host
     * @author Emily Perkins (emilah@live.com)
     * @since 3/26/2012 11:48 PM
     * @version 1.2.0
     *
     */
    public class MediaFire {
    	
    	public MediaFire() {
    		try {
    			logger.info("Opening Stream...");
    			String host = getHyperLinkURL();
    			String fileName = host.split("/")[5];
    			logger.info("Hyperlink Url: "+host);
    			BufferedInputStream input = new BufferedInputStream(new URL(host).openStream());
    			logger.info("Downloading: "+fileName);
    			BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream("resources/" + fileName), BUFFER_SIZE);
    			int bytesRead = 0;
    			byte[] buffer = new byte[BUFFER_SIZE];
    			while((bytesRead = input.read(buffer, 0, BUFFER_SIZE)) >= 0)
    				output.write(buffer, 0, bytesRead);
    			output.close();
    			input.close();
    			logger.info("Finished Downloading...");
    		} catch (MalformedURLException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	
    	public String getHyperLinkURL() {
    		try {
    			BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(DOWNLOAD_LINK).openStream()));
    			String line = "";
    			while((line = reader.readLine()) != null) {
    				if(line.contains("<div class=\"download_link\"")) 
    					return reader.readLine().split("href=\"")[1].split("\" onclick")[0];
    			}
    		} catch (MalformedURLException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		return null;
    	}
    	
    	public static void main(String[] args) {
    		new MediaFire();
    	}
    	
    	private final int BUFFER_SIZE = 1024;
    	
    	private final String DOWNLOAD_LINK = "http://www.mediafire.com/?3aw9hljbr9ve378";
    	
    	static Logger logger = Logger.getLogger(MediaFire.class.getName());
    
    }
    Spoiler for Images:










    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Engaged PvP 668 - Online

    Lynchy's Avatar
    Join Date
    Dec 2010
    Age
    2
    Posts
    819
    Thanks
    584
    Thanked 84 Times in 65 Posts
    Rep Power
    226
    Great job Emily, looking forward to seeing more, best of luck!
    Reply With Quote  
     

  4. #3  
    Registered Member
    Tenzin's Avatar
    Join Date
    Sep 2011
    Posts
    1,104
    Thanks
    381
    Thanked 392 Times in 224 Posts
    Rep Power
    470
    Why not just download it from the website?
    Reply With Quote  
     

  5. Thankful users:


  6. #4  
    Hei
    Hei is offline
    Ex-Moderator
    Hei's Avatar
    Join Date
    Dec 2006
    Age
    17
    Posts
    2,624
    Thanks
    937
    Thanked 615 Times in 321 Posts
    Rep Power
    2289
    Quote Originally Posted by null View Post
    Why not just download it from the website?
    Why not just tell your server players to manually download cache and place it in proper directory?
    Reply With Quote  
     

  7. Thankful users:


  8. #5  
    Registered Member
    Tenzin's Avatar
    Join Date
    Sep 2011
    Posts
    1,104
    Thanks
    381
    Thanked 392 Times in 224 Posts
    Rep Power
    470
    Quote Originally Posted by sKyrO View Post
    Why not just tell your server players to manually download cache and place it in proper directory?
    If that's what you're using it for, you could just use the direct link.
    Reply With Quote  
     

  9. Thankful user:


  10. #6  
    Hei
    Hei is offline
    Ex-Moderator
    Hei's Avatar
    Join Date
    Dec 2006
    Age
    17
    Posts
    2,624
    Thanks
    937
    Thanked 615 Times in 321 Posts
    Rep Power
    2289
    Quote Originally Posted by null View Post
    If that's what you're using it for, you could just use the direct link.
    I'm not using it for anything, but that's just one way to use it. And you can't get direct link for mediafire, an unique link is generated for each user.
    Reply With Quote  
     

  11. Thankful user:


  12. #7  
    Registered Member

    Join Date
    Jan 2012
    Posts
    137
    Thanks
    64
    Thanked 67 Times in 33 Posts
    Rep Power
    116
    It's not really good practice to put your execution code in a constructor.
    Reply With Quote  
     

  13. Thankful user:


  14. #8  
    Renown Programmer
    Nikki's Avatar
    Join Date
    Aug 2008
    Age
    19
    Posts
    3,731
    Thanks
    457
    Thanked 693 Times in 300 Posts
    Rep Power
    5000
    Quote Originally Posted by sKyrO View Post
    I'm not using it for anything, but that's just one way to use it. And you can't get direct link for mediafire, an unique link is generated for each user.
    That's why you put this in a file and call it from your cache downloading method

    I was looking at this the other day, never thought it'd be so easy (they have 20 duplicate fields )
    Please don't add/pm me asking for RSPS help!

    Links:
    - Sleeksnap
    - Pastebin
    - Automatic Portforwarding
    - Enabling RSA on Hyperion/PI
    - Project Signatures

    Reply With Quote  
     

  15. Thankful user:


  16. #9  
    Banned

    Join Date
    Dec 2008
    Posts
    4,239
    Thanks
    388
    Thanked 414 Times in 223 Posts
    Rep Power
    0
    If you make this for sharecash, I'd love you
    Reply With Quote  
     

  17. Thankful user:


  18. #10  
    Pon de Floor


    Mister Maggot's Avatar
    Join Date
    Dec 2008
    Age
    17
    Posts
    6,747
    Thanks
    3,108
    Thanked 2,561 Times in 1,425 Posts
    Rep Power
    5000
    An upload utility would be awesome.
    Quote Originally Posted by Original View Post
    Yeah, I haven't used JFrame before, I've always used OpenGL
    I coded a boolean once
    ¯\_(ツ)_/¯ lol idk just rep me
    Reply With Quote  
     

  19. Thankful user:



Page 1 of 2 12 LastLast
Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mediafire
    By Tozeo in forum Chat
    Replies: 4
    Last Post: 11-14-2011, 06:18 AM
  2. Megaupload Or Mediafire
    By Z-ro in forum Voting
    Replies: 17
    Last Post: 07-29-2010, 12:35 PM
  3. upload on mediafire
    By dani_gonzales in forum Help
    Replies: 5
    Last Post: 05-19-2010, 05:36 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •