2012-01-03 76 views
12

我已經走了谷歌,並且無法從YouTube視頻獲取rtsp鏈接給VIDEO_ID。RTSP youtube鏈接

我很困惑如何使用該ID,然後解析谷歌的鏈接。

感謝您的時間和精力。

回答

13

我發現這個blog entry,也許是它的一個起點。如果您繼續使用<id>鏈接,則會獲得另一種格式,您應該在其中找到rtsp鏈接。編輯: 經過WarrenFaith發佈的內容。 PROPS TO HIM

這就是你如何得到一個rtsp鏈接。

  1. 提出請求
  2. 解析數據爲3GP內容
    • 它也爲您提供了評級和所有你可能需要的好東西。

希望幫助你們

+0

謝謝WarrenFaith:d – bluejamesbond 2012-01-03 17:46:58

+0

「Q-GLuydiMe4」 ID將無法通過這個開放方式 – 2014-02-24 11:16:53

+0

Q-GLuydiMe4 id不會通過這種方式打開?爲什麼,你知道這個問題嗎? – 2014-02-24 11:27:00

6
Note:Working only android mobile(Not in Tablate) 

private class YourAsyncTask extends AsyncTask<Void, Void, Void>`enter code here` 
    { 
     ProgressDialog progressDialog; 

     @Override 
     protected void onPreExecute() 
     { 
      super.onPreExecute(); 
      progressDialog = ProgressDialog.show(AlertDetail.this, "", "Loading Video wait...", true); 
     } 

     @Override 
     protected Void doInBackground(Void... params) 
     { 
      try 
      { 
       String url = "http://www.youtube.com/watch?v=1FJHYqE0RDg"; 
       videoUrl = getUrlVideoRTSP(url); 
       Log.e("Video url for playing=========>>>>>", videoUrl); 
      } 
      catch (Exception e) 
      { 
       Log.e("Login Soap Calling in Exception", e.toString()); 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Void result) 
     { 
      super.onPostExecute(result); 
      progressDialog.dismiss(); 
/* 
      videoView.setVideoURI(Uri.parse("rtsp://v4.cache1.c.youtube.com/CiILENy73wIaGQk4RDShYkdS1BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp")); 
      videoView.setMediaController(new MediaController(AlertDetail.this)); 
      videoView.requestFocus(); 
      videoView.start();*/    
      videoView.setVideoURI(Uri.parse(videoUrl)); 
      MediaController mc = new MediaController(AlertDetail.this); 
      videoView.setMediaController(mc); 
      videoView.requestFocus(); 
      videoView.start();   
      mc.show(); 
     } 

    } 

public static String getUrlVideoRTSP(String urlYoutube) 
    { 
     try 
     { 
      String gdy = "http://gdata.youtube.com/feeds/api/videos/"; 
      DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
      String id = extractYoutubeId(urlYoutube); 
      URL url = new URL(gdy + id); 
      HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
      Document doc = documentBuilder.parse(connection.getInputStream()); 
      Element el = doc.getDocumentElement(); 
      NodeList list = el.getElementsByTagName("media:content");///media:content 
      String cursor = urlYoutube; 
      for (int i = 0; i < list.getLength(); i++) 
      { 
       Node node = list.item(i); 
       if (node != null) 
       { 
        NamedNodeMap nodeMap = node.getAttributes(); 
        HashMap<String, String> maps = new HashMap<String, String>(); 
        for (int j = 0; j < nodeMap.getLength(); j++) 
        { 
         Attr att = (Attr) nodeMap.item(j); 
         maps.put(att.getName(), att.getValue()); 
        } 
        if (maps.containsKey("yt:format")) 
        { 
         String f = maps.get("yt:format"); 
         if (maps.containsKey("url")) 
         { 
          cursor = maps.get("url"); 
         } 
         if (f.equals("1")) 
          return cursor; 
        } 
       } 
      } 
      return cursor; 
     } 
     catch (Exception ex) 
     { 
      Log.e("Get Url Video RTSP Exception======>>", ex.toString()); 
     } 
     return urlYoutube; 

    } 

protected static String extractYoutubeId(String url) throws MalformedURLException 
    { 
     String id = null; 
     try 
     { 
      String query = new URL(url).getQuery(); 
      if (query != null) 
      { 
       String[] param = query.split("&"); 
       for (String row : param) 
       { 
        String[] param1 = row.split("="); 
        if (param1[0].equals("v")) 
        { 
         id = param1[1]; 
        } 
       } 
      } 
      else 
      { 
       if (url.contains("embed")) 
       { 
        id = url.substring(url.lastIndexOf("/") + 1); 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      Log.e("Exception", ex.toString()); 
     } 
     return id; 
    } 
2

得到rtsp鏈接的短而簡單的方式,應該是很容易移植到任何平臺。

String video_id = "1FJHYqE0RDg"; 
String gdata = "http://gdata.youtube.com/feeds/api/videos/"; 
String youtube_response = Util.getUrlResponse(gdata+video_id); // just a simple HTTP GET 
String rtsp_link = "rtsp:"+ StringUtils.split(StringUtils.split(youtube_response, "rtsp:")[1], ".3gp")[0] + ".3gp"; 
+0

「Q-GLuydiMe4」ID不會通過這種方式打開。爲什麼? – 2014-02-24 11:22:27

+0

Q-GLuydiMe4 id不會通過這種方式打開?你可以解釋嗎 ? – 2014-02-24 11:27:47

+0

也許視頻對其有其他限制。 – Ajibola 2014-02-24 18:29:33

1

沒有一個程序如果u想要提取YOUTUBE RTSP鏈接,然後

  1. GO TO www.youtube.com

  2. 選擇ü希望其rtsp鏈接的視頻... 。

  3. 轉到該視頻的網址.....

  4. 取從URL ID IE http://www.youtube.com/watch?v=6acRHWnfZAE ((所述由「=」的開始的ID和去高達結束... ...在上述情況下6acRHWnfZAE是視頻的示例中的ID

  5. 現在打開http://gdata.youtube.com/feeds/api/videos/,然後在此URL上粘貼您的視頻的ID ......

  6. ,打開的頁面

  7. 現在搜索媒體:在頁面 內容會有ATLEAST 3 屬性 一會HTTP n中的另外兩個將是RTSP格式1 n 格式6); 按我的經驗格式1僅用於視頻,,,,ň格式6對於音頻的N個視頻都

+6

來自youtube的回覆:不再可用 – seoul 2015-06-28 18:19:30