2012-01-03 10 views
12

Sono andato su google e sto avendo problemi a ottenere il link rtsp da un video di youtube dare il VIDEO_ID.Link YouTube RTSP

Sono confuso su come utilizzare quell'ID e quindi analizzare google per il collegamento.

Grazie per il vostro tempo e impegno.

risposta

13

Ho trovato questo blog entry, forse è un punto di partenza. Se segui i collegamenti <id> ottieni un altro formato in cui dovresti trovare il link rtsp.

MODIFICA: dopo aver esaminato ciò che ha pubblicato WarrenFaith. PROPONE A LUI

questo è come si ottiene un collegamento rtsp.

  1. fare una richiesta
  2. analizzare i dati per il contenuto 3gp
    • Esso fornisce anche con il rating e tutta quella roba buona che si può prendere.

speranza che aiuta ragazzi

+0

grazie WarrenFaith: D – bluejamesbond

+0

id "Q-GLuydiMe4" non si apre attraverso questo way –

+0

L'ID Q-GLuydiMe4 non si apre in questo modo? perché è, hai conosciuto questo problema? –

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

Un modo breve e semplice di ottenere il collegamento RTSP, dovrebbe essere facilmente portabile su qualsiasi piattaforma.

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

. Perché ? –

+0

L'ID Q-GLuydiMe4 non si apre in questo modo? Puoi spiegare ? –

+0

forse il video ha altre restrizioni su di esso. – Ajibola

1

senza un programma se volete andare a prendere un collegamento YOUTUBE RTSP poi

  1. VAI A www.youtube.com

  2. selezionare il video di cui u vuole collegamento RTSP ... .

  3. accedere all'URL di quel video .....

  4. recuperare l'id dalla URL ossia http://www.youtube.com/watch?v=6acRHWnfZAE ((l'id inizia da "=" e va fino alla fine ... nel caso precedente 6acRHWnfZAE è l'ID del video nell'esempio

  5. ora aperto http://gdata.youtube.com/feeds/api/videos/ e dopo questo url incollare l'id del tuo video ......

  6. una pagina si aprirà

  7. ora cercare i mezzi di comunicazione: contenuti in quella pagina ci saranno almeno 3 attributo uno sarà HTTP n gli altri due saranno rtsp (formato 1 n formato 6); come per la mia esperienza formato 1 è solo per il video ,,,, n formato 6 è per l'audio n il video sia

+6

Risposta da youtube: Non più disponibile – seoul