|
1 | 1 | # youtubedl-java [](https://travis-ci.org/sapher/youtubedl-java) |
2 | 2 |
|
3 | | - |
4 | | -Just a simple WIP java wrapper for youtubedl |
5 | | - |
6 | | -#Table of contents |
7 | | - |
8 | | -- [Prerequisite](#prerequisite) |
9 | | -- [Usage](#usage) |
10 | | -- [Links](#links) |
| 3 | +A simple java wrapper for [youtube-dl](https://github.com/rg3/youtube-dl) executable |
11 | 4 |
|
12 | 5 | # Prerequisite |
13 | | -You need `youtube-dl` to be installed and available. You can follow [those instructions](https://github.com/rg3/youtube-dl/blob/master/README.md#installation) to install `youtube-dl` |
14 | | - |
15 | | -# Usage |
16 | | - |
17 | | -YoutubeDL wrapper is compose of 3 main class : `YoutubeDL`, `YoutubeDLRequest`, `YoutubeDLResponse`. |
18 | | - |
19 | | -## YoutubeDL |
20 | | -Static class that execute a request and return a response. |
21 | | - |
22 | | -### Execute a command |
23 | | - |
24 | | -``` |
25 | | -YoutubeDL.execute('--version'); |
26 | | -``` |
27 | | - |
28 | | -### Execute a request |
29 | 6 |
|
30 | | -``` |
31 | | -YoutubeDLRequest request = new YoutubeDLRequest(); |
32 | | -YoutubeDL.execute(request); |
33 | | -``` |
34 | | - |
35 | | -## YoutubeDLRequest |
36 | | -Represent a command for youtube-dl to execute. |
37 | | -You can **set** and **get** all options handle by youtube-dl : [YoutubeDL Options](https://github.com/rg3/youtube-dl/blob/master/README.md#options). |
38 | | -Don't use those deprecated (you can but.. don't). |
| 7 | +Youtube-dl should be installed and available. |
39 | 8 |
|
40 | | -``` |
41 | | -// Example to set / get rate limit |
42 | | -request.setRateLimit(1024); |
43 | | -request.getRateLimit(); |
44 | | -``` |
| 9 | +# Usage |
45 | 10 |
|
46 | | -## YoutubeDLResponse |
47 | | -Represent the result of a request. |
48 | 11 |
|
49 | | -This object is composed of: |
| 12 | +## Make request |
50 | 13 |
|
51 | | -* **exitCode** Exit code of youtube-dl programm |
52 | | -* **err** String from stderr |
53 | | -* **out** String from stdout |
54 | | -* **directory** Directory where the programme has been launched |
55 | | -* *more useful to come...* |
| 14 | +```java |
| 15 | +// Video url to download |
| 16 | +String videoUrl = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"; |
56 | 17 |
|
57 | | -## Custom request |
| 18 | +// Destination directory |
| 19 | +String directory = System.getProperty("user.home"); |
58 | 20 |
|
59 | | -You can use `YoutubeDLRequest` object to build any command you want. |
| 21 | +// Build request |
| 22 | +YoutubeDLRequest request = new YoutubeDLRequest(videoUrl, directory); |
| 23 | +request.setOption("ignore-errors"); // --ignore-errors |
| 24 | +request.setOption("output", "%(id)s"); // --output "%(id)s" |
| 25 | +request.setOption("retries", 10); // --retries 10 |
60 | 26 |
|
61 | | -```java |
62 | | -// Download a video |
63 | | -YoutubeDLRequest request = new YoutubeDLRequest(); |
64 | | -request.setUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); |
65 | | -request.setDirectory("/Users/johndoe/Desktop"); |
| 27 | +// Make request and return response |
66 | 28 | YoutubeDLResponse response = YoutubeDL.execute(request); |
67 | 29 |
|
68 | | -// will result to youtube-dl https://www.youtube.com/watch?v=dQw4w9WgXcQ |
| 30 | +// Response |
| 31 | +String stdOut = response.getOut(); // Executable output |
69 | 32 | ``` |
70 | | - |
71 | | -Be care, you can build a nonsensical command. |
72 | | - |
73 | 33 | # Links |
74 | | - |
75 | | -[YoutubeDL Documentation](https://github.com/rg3/youtube-dl/blob/master/README.md#installation) |
76 | | - |
77 | | -**[Back to top](#table-of-contents)** |
| 34 | +* [Youtube-dl documentation](https://github.com/sapher/youtubedl-java) |
0 commit comments