为了账号安全,请及时绑定邮箱和手机立即绑定

Youtube 视频下载 (Android/Java)

Youtube 视频下载 (Android/Java)

慕容森 2021-10-20 16:12:40
注意:原问题已删除原始问题是https://stackoverflow.com/questions/15240011/get-the-download-url-for-youtube-video-android-java/15240012#15240012这里的答案已经过时,不起作用,所以我会发布一个新问题并回答我自己旧代码new YouTubePageStreamUriGetter().execute("https://www.youtube.com/watch?v=4GuqB1BQVr4");class Meta {    public String num;    public String type;    public String ext;    Meta(String num, String ext, String type) {        this.num = num;        this.ext = ext;        this.type = type;    }}class Video {    public String ext = "";    public String type = "";    public String url = "";    Video(String ext, String type, String url) {        this.ext = ext;        this.type = type;        this.url = url;    }}public ArrayList<Video> getStreamingUrisFromYouTubePage(String ytUrl)        throws IOException {    if (ytUrl == null) {        return null;    }    // Remove any query params in query string after the watch?v=<vid> in    // e.g.    // http://www.youtube.com/watch?v=0RUPACpf8Vs&feature=youtube_gdata_player    int andIdx = ytUrl.indexOf('&');    if (andIdx >= 0) {        ytUrl = ytUrl.substring(0, andIdx);    }    // Get the HTML response    String userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0.1)";    HttpClient client = new DefaultHttpClient();    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT,            userAgent);    HttpGet request = new HttpGet(ytUrl);    HttpResponse response = client.execute(request);    String html = "";    InputStream in = response.getEntity().getContent();    BufferedReader reader = new BufferedReader(new InputStreamReader(in));    StringBuilder str = new StringBuilder();    String line = null;    while ((line = reader.readLine()) != null) {        str.append(line.replace("\\u0026", "&"));    }    in.close();    html = str.toString();    // Parse the HTML response and extract the streaming URIs    if (html.contains("verify-age-thumb")) {        CLog.w("YouTube is asking for age verification. We can't handle that sorry.");        return null;    }此代码不起作用
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 228 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信