add m3u8script
This commit is contained in:
21
m3u8script/LICENSE
Normal file
21
m3u8script/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 eneller
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
40
m3u8script/README.md
Normal file
40
m3u8script/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# m3u8script
|
||||
A script to facilitate downloading videos saved as .m3u8 in general.
|
||||
|
||||
## Finding the .m3u8 file
|
||||
[Please extract the URL to your .m3u8 file first:](findm3u8.mp4)
|
||||
1. Open the developer tools
|
||||
2. Go to the network tab and reload the page
|
||||
3. locate an entry containing an m3u8 link
|
||||
4. copy the link
|
||||
|
||||
In pictures:
|
||||

|
||||

|
||||
(Pictures taken in Firefox)
|
||||
</br></br>
|
||||

|
||||
(Pictures taken in Brave (Chromium Browser))
|
||||
|
||||
## Using the tool
|
||||
The tool does not need to be installed, only downloaded (m3u8script.java). All you might need to do is [install the Java Development Kit, or JDK,](https://www.oracle.com/de/java/technologies/javase-jdk15-downloads.html) and set the CLASSPATH variable.
|
||||
You can then run it:
|
||||

|
||||
|
||||
When encountering an error, you might also try
|
||||
`java -cp ./ m3u8script.java`
|
||||
|
||||
## Options
|
||||
|option|explanation|
|
||||
|----|----|
|
||||
|`-single m3u8URL`| allows you to download and convert a single .m3u8 file. In this case, output must either end in a *folder/* or *file.m3u8*|
|
||||
|`-multi textfile`| allows you to specify the path to a text file that contains links to .m3u8 files (one on each line), allowing hands-free batch processing. -output must specify a folder path|
|
||||
|`-output fileorfolder`| specifies a local directory path. When using ’-multi’, it must contain only a folder name, since filenames will be applied automatically. When used with -single, it can contain a full filename with the extension .m3u8. If you want to use automatic naming, just specify a folder path|
|
||||
|`-prefix prefixToUse`| You can use this command to specify the pattern this script should look for. Default should work in most cases. |
|
||||
|
||||
Example: `java m3u8script.java -multi /home/guest/Downloads/list.txt -output /home/guest/Downloads/videos`
|
||||
|
||||
## Downloading
|
||||
You can then use ffmpeg or VLC media player to download the videos:
|
||||
|
||||

|
||||
BIN
m3u8script/brave.png
Normal file
BIN
m3u8script/brave.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 128 KiB |
BIN
m3u8script/cli.jpg
Normal file
BIN
m3u8script/cli.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
BIN
m3u8script/find1.png
Normal file
BIN
m3u8script/find1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 151 KiB |
BIN
m3u8script/find2.png
Normal file
BIN
m3u8script/find2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 196 KiB |
BIN
m3u8script/findm3u8.mp4
Normal file
BIN
m3u8script/findm3u8.mp4
Normal file
Binary file not shown.
137
m3u8script/m3u8script.java
Normal file
137
m3u8script/m3u8script.java
Normal file
@@ -0,0 +1,137 @@
|
||||
package de.eneller.scripts;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class m3u8script {
|
||||
public static Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
|
||||
|
||||
public static void main(String[] args) {
|
||||
logger.setLevel(Level.ALL);
|
||||
if (args.length < 2) {
|
||||
printHelp();
|
||||
System.exit(1);
|
||||
}
|
||||
System.out.println(Arrays.toString(args));
|
||||
String url = "";
|
||||
String inputFile = "";
|
||||
String prefix = "media_";
|
||||
String output = "";
|
||||
boolean m = false;
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
switch (args[i]) {
|
||||
case "-single":
|
||||
url = args[i + 1].trim();
|
||||
break;
|
||||
case "-multi":
|
||||
inputFile = args[i + 1].trim();
|
||||
m = true;
|
||||
break;
|
||||
case "-prefix":
|
||||
prefix = args[i + 1].trim();
|
||||
break;
|
||||
case "-output":
|
||||
output = args[i + 1].trim();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m == false) {
|
||||
if (output.matches(".*\\.m3u8$") == false) {
|
||||
output = output + "/";
|
||||
}
|
||||
parse(url, output, prefix);
|
||||
} else {
|
||||
String[] pathArr = output.split("/");
|
||||
|
||||
if (output.matches(".*/$") == false) {
|
||||
output = output + "/";
|
||||
}
|
||||
|
||||
try (Scanner scn = new Scanner(new File(inputFile));) {
|
||||
|
||||
String data;
|
||||
int c = 0;
|
||||
int a = 0;
|
||||
while (scn.hasNextLine()) {
|
||||
a++;
|
||||
data = scn.nextLine();
|
||||
if (parse(data, output, prefix)) {
|
||||
c++;
|
||||
}
|
||||
}
|
||||
logger.log(Level.INFO, c + " out of " + a + " operations successfully completed. In case of errors, please check the log.");
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.log(Level.SEVERE, "Couldnt find input file");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean parse(String m3u8WebPath, String outputPath, String matchPrefix) {
|
||||
boolean b = true;
|
||||
try {
|
||||
URL url = new URL(m3u8WebPath);
|
||||
Scanner scn = new Scanner((new BufferedReader(new InputStreamReader(url.openStream()))));
|
||||
String[] splitWebPath = m3u8WebPath.split("/");
|
||||
String m3u8WebPrefix = "";
|
||||
for (int i = 0; i < splitWebPath.length - 1; i++) {
|
||||
m3u8WebPrefix = m3u8WebPrefix + splitWebPath[i] + "/";
|
||||
}
|
||||
if (outputPath.matches(".*/$")) {
|
||||
String generatedFileName = splitWebPath[splitWebPath.length - 2];
|
||||
generatedFileName = generatedFileName.replaceAll("%20", "_");
|
||||
generatedFileName = generatedFileName.replaceAll("\\.smil", ".m3u8");
|
||||
outputPath = outputPath + generatedFileName;
|
||||
}
|
||||
|
||||
File outm3u8 = new File(outputPath);
|
||||
|
||||
if (outm3u8.createNewFile()) {
|
||||
logger.log(Level.INFO, "File created at " + outputPath);
|
||||
} else {
|
||||
logger.log(Level.WARNING, "File already exists, please specify a different path " + outputPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
FileWriter outWriter = new FileWriter(outm3u8);
|
||||
String data = "";
|
||||
while (scn.hasNextLine()) {
|
||||
data = scn.nextLine();
|
||||
if (data.startsWith(matchPrefix)) {
|
||||
data = m3u8WebPrefix + data;
|
||||
}
|
||||
outWriter.write(data + "\n");
|
||||
}
|
||||
outWriter.close();
|
||||
scn.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.log(Level.SEVERE, "Couldnt find .m3u8 file at specified path");
|
||||
} catch (MalformedURLException e) {
|
||||
logger.log(Level.SEVERE, "Couldnt read file at URL");
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "An error occured while trying to create the output file, please check that your path exists");
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getInput(String s) {
|
||||
Scanner scn = new Scanner(System.in);
|
||||
System.out.println(s);
|
||||
return scn.nextLine();
|
||||
}
|
||||
|
||||
public static void printHelp() {
|
||||
System.out.println("Seems like you tried to run the script without specifying necessary parameters." + System.lineSeparator() +
|
||||
"The following commands are available:" + System.lineSeparator() + System.lineSeparator() +
|
||||
"Use -multi yourfile.txt to specify the absolute path to an input file containing a list of URLs" + System.lineSeparator() +
|
||||
"Or use -single urlto.m3u8 in combination with -output /path/to/output/folderorfile" + System.lineSeparator() + System.lineSeparator() +
|
||||
"Please go to https://github.com/eneller/m3u8script for additional help");
|
||||
}
|
||||
}
|
||||
BIN
m3u8script/vlc.png
Normal file
BIN
m3u8script/vlc.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
Reference in New Issue
Block a user