Java access to video thumbnails such as Youku

Source: Internet
Author: User
Tags json readline stub

1 Import Java.io.BufferedReader;

2 Import java.io.IOException;

3 Import Java.io.InputStreamReader;

4 Import java.net.MalformedURLException;

5 Import Java.net.URL;

6

7 Import net.sf.json.*;

8

9

Ten public class Test2 {

11

12/**

* @param args

* @throws IOException

15 */

public static void Main (string[] args) throws IOException {

//TODO auto-generated method stub

A String URL = "http://v.youku.com/v_show/id_XMjU0MjI2NzY0.html";

19//Get the string behind the ID, i.e. "xmju0mji2nzy0.html"

int no = Url.indexof ("id_");

21//Get ID value, i.e. "Xmju0mji2nzy0"

String videoid = url.substring (no+3, Url.indexof (". html"));

23//Get the URL object of the video information data

The URL myurl = new URL ("http://v.youku.com/player/getPlayList/VideoIDS/" +videoid+/timezone/+08/version/5/source/ Out?password=&ran=2513&n=3 ");

25//Get the input stream from the URL object

InputStreamReader ISR = new InputStreamReader (Myurl.openstream ());

27//Package

BufferedReader br = new BufferedReader (ISR);

//readline Get text

String URL = br.readline ();

31//Close the stream

Br.close ();

33//Get JSON Object

Jsonobject json = jsonobject.fromobject (URLs);

35//Get JSON data (within data)

Jsonarray arr = json.getjsonarray ("Data");

37//Get the value of logo and print

System.out.println (Jsonobject.fromobject (arr.get (0)). Get ("logo");

39}

40

41}

The other is not using JSON scheme, relatively small white, but also my first method.

1 Import Java.io.BufferedReader;

2 Import java.io.IOException;

3 Import Java.io.InputStreamReader;

4 Import Java.net.URL;

5

6

7

8 public class Test1 {

9

10/**

One * @param args

* @throws IOException

13 */

public static void Main (string[] args) throws IOException {

/TODO auto-generated Method stub

16//Set video address

The String url = "http://v.youku.com/v_show/id_XMjU0MjI2NzY0.html";

18//Get the string behind the ID, i.e. "xmju0mji2nzy0.html"

int no = Url.indexof ("id_");

20//Get ID value, i.e. "Xmju0mji2nzy0"

String videoid = url.substring (no+3, Url.indexof (". html"));

22//Get the URL object of the 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 ");

24//Get the input stream from the URL object

InputStreamReader ISR = new InputStreamReader (Myurl.openstream ());

26//Package

BufferedReader br = new BufferedReader (ISR);

//readline get the text and then "/" cut the information in the text

string[] url = br.readline (). Split ("/");

Isr.close ();

Br.close ();

32//Because the information data is fixed format, the direct fourth element is definitely what we need.

-String target = urls[3];

34//To the above results continue to "cut

A String Imgid = target.substring (0,target.indexof (""));

36//Piece together, that's the address we need.

Panax notoginseng String img = "http://g2.ykimg.com/" + imgid;

System.out.println (IMG);

39/*

40 result is: Http://g2.ykimg.com/1100641F464D8FBF5FA3D90209C8DF96B67E2C-567E-AB53-C132-D7787FC966AB

41 */

42}

43

44}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.