Giter Club home page Giter Club logo

javatube's Introduction

JavaTube

GitHub Workflow Status (with event)

JDK

JavaTube is a YouTube video download library based on pytube library.

JavaTube is a library written in java and aims to be highly reliable.

Features

  • Support for downloading the full playlist
  • Support for progressive and adaptive streams
  • Interaction with channels (Videos, YouTube Shorts, lives and Playlists)
  • onProgress callback register
  • Keyword search support
  • Ability to get video details (Title, Description, Publish Date, Length, Thumbnail Url, Views, Author and Keywords)
  • Subtitle generator for .srt format
  • Support downloading yt_otf streams
  • Possibility to choose the client (WEB, ANDROID, IOS)
  • Native js interpreter

Contribution

Currently this project is maintained by only one person. Feel free to create issues with questions, bug reports or improvement ideas.

WARNING

This code is for educational purposes and must not be used in any way for commercial purposes.

Downloading videos from YouTube without proper authorization may violate the terms of the platform.

Downloading copyrighted videos may infringe on the creators' intellectual property.

I reaffirm not to use this software to violate any laws.

Using JavaTube

To download YouTube videos you need to import the YouTube class and pass a YouTube video url to access the streams.

The streams() method returns a StreamQuery object that lists the properly handled streams.

You must only get one stream to be able to download it. You can use the methods:

  • getHighestResolution()
  • getLowestResolution()
  • getOnlyAudio()

You can also manually select the stream using .get("index").

The download() method must receive the path that the stream will be downloaded.

public static void main(String[] args) throws Exception {
    Youtube yt = new Youtube("https://www.youtube.com/watch?v=2lAe1cqCOXo");
    yt.streams().getHighestResolution().download("./");
}

or

public static void main(String[] args) throws Exception {
        new Youtube("https://www.youtube.com/watch?v=2lAe1cqCOXo").streams().get(1).download("./");
    }
}

Downloading videos with multiple audio tracks

Videos with multiple progressive audio tracks come with the original audio, which is why we must choose the adaptive types.

Because the dubbed audio tracks have the same tag, we have to filter by name.

This will only list tracks dubbed in the chosen language:

for(Stream s : new Youtube("https://www.youtube.com/watch?v=g_VxOIlg7q8").streams().getExtraAudioTracksByName("English").getAll()){
    System.out.println(s.getItag() + " " + s.getAudioTrackName() + " " + s.getAbr() + " " + s.getUrl());
}

You can check the dubbed tracks using:

for(Stream s : new Youtube("https://www.youtube.com/watch?v=g_VxOIlg7q8").streams().getExtraAudioTracks().getAll()){
    System.out.println(s.getItag() + " " + s.getAudioTrackName() + " " + s.getAbr() + " " + s.getUrl());
}

Download using filters

You must pass a HashMap String with the filter you want to use and its respective value

public static void main(String[] args) throws Exception {
    Youtube yt = new Youtube("https://www.youtube.com/watch?v=2lAe1cqCOXo");

    HashMap<String, String> filters = new HashMap<>();
    filters.put("progressive", "true");
    filters.put("subType", "mp4");

    yt.streams().filter(filters).getFirst().download("./");
    
}

Download with callback function

If no parameter is passed, a download percentage string will be printed to the terminal

public static void progress(Long value){
    System.out.println(value);
}

public static void main(String[] args) throws Exception {
    Youtube yt = new Youtube("https://www.youtube.com/watch?v=2lAe1cqCOXo");
    yt.streams().getHighestResolution().download("./", Download::progress);
}

Downloading a playlist

The getVideos() method will return an ArrayList with the links extracted from the playlist url (YouTube mix not supported)

 public static void main(String[] args) throws Exception {
    for(String pl : new Playlist("https://www.youtube.com/playlist?list=PLS1QulWo1RIbfTjQvTdj8Y6yyq4R7g-Al").getVideos()){
        new Youtube(pl).streams().getHighestResolution().download("./");
    }
}

Using the search feature

  • getResults(): method will return an ArrayList with links to videos, shorts, playlists and channels.

  • getVideoResults(): method returns an ArrayList of Youtube objects, containing videos.

  • getShortsResults(): method returns an ArrayList of Youtube objects, containing YouTube Shorts.

  • getChannelsResults(): method returns an ArrayList of Channel objects, containing the channels.

  • getPlaylistsResults(): method returns an ArrayList of Playlist objects, containing the playlists.

  • getCompletionSuggestions(): method returns a list containing search suggestions.

  • generateContinuation(): method will not return anything, just add the continuation of the items to their respective lists.

If no match was found the method will return empty, other than getCompletionSuggestions() which returns null.

public static void main(String[] args) throws Exception {
    for(String yt : new Search("Java").getResults()){
        System.out.println(yt);
    }
}

Interacting with channels

  • getVideos(): method returns an ArrayList containing the channel's videos.

  • getShorts(): method returns an ArrayList containing the channel's YouTube Shorts.

  • getLives(): method returns an ArrayList containing the channel's lives.

  • getPlaylists(): method returns an ArrayList containing the channel's playlists.

public static void main(String[] args) throws Exception {
    for(String c : new Channel("https://www.youtube.com/channel/UCmRtPmgnQ04CMUpSUqPfhxQ").getVideos()){
        System.out.println(new Youtube(c).getTitle());
    }
}

Using the subtitles feature

See available languages.

public static void main(String[] args) throws Exception {
    for(Captions caption: new Youtube("https://www.youtube.com/watch?v=2lAe1cqCOXo&t=1s").getCaptionTracks()){
        System.out.println(caption.getCode());
        }
    }
}

Write to console in .srt format.

public static void main(String[] args) throws Exception {
        System.out.println(new Youtube("https://www.youtube.com/watch?v=2lAe1cqCOXo&t=1s").getCaptions().getByCode("en").xmlCaptionToSrt());
    }
}

Download it in .srt format (if the .srt format is not informed, the xml will be downloaded).

public static void main(String[] args) throws Exception {
        new Youtube("https://www.youtube.com/watch?v=2lAe1cqCOXo&t=1s").getCaptions().getByCode("en").download("caption.srt", "./")
    }
}

Filters Parameters:

  • "res" The video resolution (e.g.: "360p", "720p")

  • "fps" The frames per second (e.g.: "24fps", "60fps")

  • "mineType" Two-part identifier for file formats and format contents composed of a “type”, a “subtype” (e.g.: "video/mp4", "audio/mp4")

  • "type" Type part of the mineType (e.g.: audio, video)

  • "subType" Sub-type part of the mineType (e.g.: mp4, webm)

  • "abr" Average bitrate (e.g.: "128kbps", "192kbps")

  • "videoCodec" Video compression format

  • "audioCodec" Audio compression format

  • "onlyAudio" Excludes streams with video tracks (e.g.: "true" or "false")

  • "onlyVideo" Excludes streams with audio tracks (e.g.: "true" or "false")

  • "progressive" Excludes adaptive streams (one file contains both audio and video tracks) (e.g.: "true" or "false")

  • "adaptive" Excludes progressive streams (audio and video are on separate tracks) (e.g.: "true" or "false")

javatube's People

Contributors

felipeucelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

javatube's Issues

application crashes when internet is down

Hey, when I am trying to use the download method, while the video is downloading if the internet disconnects the application crashes, also when I use the stream and search methods, if there is no internet the application crashes.
how can I handle it?

issue with the adaptive videos

Hey, for some reason I can not load the adaptive videos that are in the streamQuery given in the stream() method in Youtube class, can it be fixed somehow?

Regex Matcher Exception

Hey, when I use the 'stream()' function is gives me the error: "Fsa=function(\w){[a-z]=[a-z].[a-z]("");([\w.\w*(\w,\d);]*)(?:return)", how can I fix it?

The searching is taking a very long time

Hey, I really like your code and it so much fun to work with it and really everything is working fine, but the searching is taking a very long time something like 10 - 15 seconds, can I improve it somehow?

Problems in java files

When import java tube files in my project its show me this error in classes

/storage/emulated/0/AndroidIDEProjects/MyApplication/app/src/main/java/com/purplerat/myapplication/javatube/Captions.java:105: error: cannot find symbol Files.writeString(path, xmlCaptionToSrt(), StandardCharsets.UTF_8); ^ symbol: method writeString(Path,String,Charset) location: class Files /storage/emulated/0/AndroidIDEProjects/MyApplication/app/src/main/java/com/purplerat/myapplication/javatube/Captions.java:111: error: cannot find symbol Files.writeString(path, getXmlCaptions(), StandardCharsets.UTF_8); ^ symbol: method writeString(Path,String,Charset) location: class Files /storage/emulated/0/AndroidIDEProjects/MyApplication/app/src/main/java/com/purplerat/myapplication/javatube/Playlist.java:114: error: cannot find symbol if (!continuationEnd.isEmpty()) { ^ symbol: method isEmpty() location: variable continuationEnd of type JSONArray /storage/emulated/0/AndroidIDEProjects/MyApplication/app/src/main/java/com/purplerat/myapplication/javatube/Channel.java:108: error: cannot find symbol if (!continuationEnd.isEmpty()){ ^ symbol: method isEmpty() location: variable continuationEnd of type JSONArray /storage/emulated/0/AndroidIDEProjects/MyApplication/app/src/main/java/com/purplerat/myapplication/javatube/Search.java:20: error: incompatible types: Charset cannot be converted to String return URLEncoder.encode(this.query, StandardCharsets.UTF_8);

How solve this ?

RegexMatcherError

Hey, the 'getThrottlingFunctionCode(String js) function in Cipher class throwing an RegexMatcherError exception, can you fix it?

search is taking too long

hey, there is a problem with the search action, it is taking a lot of time, can you fix it somehow?

How use it

I need to know how use this library in my android studio project?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.