Code for obtaining Youku and other video thumbnails implemented in java

Source: Internet
Author: User

Anyone who wants php can download the test http://www.jb51.net/codes/83179.html here

Copy codeThe Code is as follows: import java. io. BufferedReader;
Import java. io. IOException;
Import java. io. InputStreamReader;
Import java.net. MalformedURLException;
Import java.net. URL;
Import net. sf. json .*;

Public class test2 {
/**
* @ Param args
* @ Throws IOException
*/
Public static void main (String [] args) throws IOException {
// TODO Auto-generated method stub
String url = "http://v.youku.com/v_show/id_XMjU0MjI2NzY0.html ";
// Obtain the string after the id, that is, "XMjU0MjI2NzY0.html"
Int no = url. indexOf ("id _");
// Obtain the id value, that is, "XMjU0MjI2NzY0"
String videoId = url. substring (no + 3, url. indexOf (". html "));
// URL object for obtaining video information data
URL myurl = new URL ("http://v.youku.com/player/getPlayList/VideoIDS/" + videoId + "/timezone/+ 08/version/5/source/out? Password = & ran = 2513 & n = 3 ");
  
// Obtain the input stream from the URL object
InputStreamReader isr = new InputStreamReader (myurl. openStream ());
// Encapsulation
BufferedReader br = new BufferedReader (isr );
// Read the text in readLine.
String urls = br. readLine ();
// Close the stream
Br. close ();
// Obtain the json object
JSONObject json = JSONObject. fromObject (urls );
// Obtain json data (within data)
JSONArray arr = json. getJSONArray ("data ");
// Obtain and print the logo Value
System. out. println (JSONObject. fromObject (arr. get (0). get ("logo "));
}
}

Another method that does not use json is the first one.Copy codeThe Code is as follows: import java. io. BufferedReader;
Import java. io. IOException;
Import java. io. InputStreamReader;
Import java.net. URL;

Public class test1 {
/**
* @ Param args
* @ Throws IOException
*/
Public static void main (String [] args) throws IOException {
// TODO Auto-generated method stub
// Set the video address
String url = "http://v.youku.com/v_show/id_XMjU0MjI2NzY0.html ";
// Obtain the string after the id, that is, "XMjU0MjI2NzY0.html"
Int no = url. indexOf ("id _");
// Obtain the id value, that is, "XMjU0MjI2NzY0"
String videoId = url. substring (no + 3, url. indexOf (". html "));
// URL object for obtaining video information data
URL myurl = new URL ("http://v.youku.com/player/getPlayList/VideoIDS/" + videoId + "/timezone/+ 08/version/5/source/out? Password = & ran = 2513 & n = 3 ");
// Obtain the input stream from the URL object
InputStreamReader isr = new InputStreamReader (myurl. openStream ());
// Encapsulation
BufferedReader br = new BufferedReader (isr );
// ReadLine: Get the text and then cut the information in the text "\/"
String [] urls = br. readLine (). split ("\\/");
Isr. close ();
Br. close ();
// Because the information data is in a fixed format, the fourth element must be what we need.
String target = urls [3];
// Continue to cut the above results
String imgid = target. substring (0, target. indexOf ("\""));
// Put together the addresses we need.
String img = "http://g2.ykimg.com/" + imgid;
System. out. println (img );
/*
Result: http://g2.ykimg.com/1100641F464D8FBF5FA3D90209C8DF96B67E2C-567E-AB53-C132-D7787FC966AB
*/
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.