RTSP youtube link

后端 未结 4 1912
离开以前
离开以前 2020-12-01 06:07

I have gone all over google and am having trouble getting the rtsp link from a youtube video give the VIDEO_ID.

I am confused on how to use that id and then parse go

相关标签:
4条回答
  • 2020-12-01 06:15

    I found this blog entry, maybe its a starting point. If you follow on of the <id> links you get another format where you should find the rtsp link.

    EDIT: after going through what WarrenFaith posted. PROPS TO HIM

    this is how you get a rtsp link.

    1. make a request
      • http://gdata.youtube.com/feeds/mobile/videos/VIDEO_ID
    2. parse that data for the 3gp content
      • It also provides you with the rating and all that good stuff that you may want.

    hope that helps you guys

    0 讨论(0)
  • 2020-12-01 06:19

    without a program if u want to fetch a YOUTUBE RTSP link then

    1. GO TO www.youtube.com

    2. select the video whose rtsp link u want....

    3. go to the url of that video.....

    4. fetch the id from the url i.e. http://www.youtube.com/watch?v=6acRHWnfZAE ((the id of the starts from "=" and goes upto the end... in the above case 6acRHWnfZAE is the id of the video in the example

    5. now open http://gdata.youtube.com/feeds/api/videos/ and after this url paste the id of your video......

    6. a page will open

    7. now search for the media:content in that page there will be atleast 3 attribute one will be HTTP n the other two will be rtsp (format 1 n format 6); as per my experience format 1 is only for video,,,, n format 6 is for audio n video both

    0 讨论(0)
  • 2020-12-01 06:31
    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;
        }
    
    0 讨论(0)
  • 2020-12-01 06:36

    A short and simple way of getting the rtsp link, should be easily portable to any platform.

    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 讨论(0)
提交回复
热议问题