This commit is contained in:
parent
459df60dcd
commit
75d14a7f09
7 changed files with 78 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
|
id("io.freefair.lombok") version "8.10"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "dev.exhq"
|
group = "dev.exhq"
|
||||||
|
@ -12,6 +13,10 @@ repositories {
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||||
|
implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.0-rc1")
|
||||||
|
implementation("com.fasterxml.jackson.core:jackson-core:2.18.0-rc1")
|
||||||
|
implementation("com.fasterxml.jackson.core:jackson-databind:2.18.0-rc1")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.test {
|
tasks.test {
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package dev.exhq;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("Hello world!");
|
|
||||||
}
|
|
||||||
}
|
|
13
src/main/java/dev/exhq/nutjammer/Main.java
Normal file
13
src/main/java/dev/exhq/nutjammer/Main.java
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package dev.exhq.nutjammer;
|
||||||
|
|
||||||
|
import dev.exhq.nutjammer.scraper.RequestType;
|
||||||
|
import dev.exhq.nutjammer.scraper.RequestTypePlatform;
|
||||||
|
import dev.exhq.nutjammer.scraper.Scraper;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) throws MalformedURLException {
|
||||||
|
System.out.println(Scraper.GetDirtyResponse(new RequestType("track:52YwsjghnnJeTfKhBfpHe3", RequestTypePlatform.SPOTIFY)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package dev.exhq.nutjammer.scraper;
|
||||||
|
|
||||||
|
public record RequestType(String id, RequestTypePlatform platform) {
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package dev.exhq.nutjammer.scraper;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum RequestTypePlatform {
|
||||||
|
SPOTIFY("spotify"),
|
||||||
|
ITUNES("itunes"),
|
||||||
|
APPLEMUSIC("appleMusic"),
|
||||||
|
YOUTUBE("youtube"),
|
||||||
|
YOUTUBEMUSIC("youtubeMusic");
|
||||||
|
|
||||||
|
private final String fancyname;
|
||||||
|
|
||||||
|
RequestTypePlatform(String fancyname) {
|
||||||
|
this.fancyname = fancyname;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
35
src/main/java/dev/exhq/nutjammer/scraper/Scraper.java
Normal file
35
src/main/java/dev/exhq/nutjammer/scraper/Scraper.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package dev.exhq.nutjammer.scraper;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
|
||||||
|
public class Scraper {
|
||||||
|
static String funnyChar = URLEncoder.encode(":", StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
public static String GetDirtyResponse(RequestType requestType) throws MalformedURLException {
|
||||||
|
String link = "https://corsisdum.exhq.dev/v1-alpha.1/links?url=" +
|
||||||
|
requestType.platform().getFancyname() + funnyChar + URLEncoder.encode(requestType.id(), StandardCharsets.UTF_8);
|
||||||
|
System.out.println(link);
|
||||||
|
URL url = null;
|
||||||
|
try {
|
||||||
|
url = new URI(link).toURL();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
//TODO idk do something
|
||||||
|
}
|
||||||
|
StringBuilder answer = new StringBuilder();
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) {
|
||||||
|
for (String line; (line = reader.readLine()) != null; ) {
|
||||||
|
answer.append(line).append("\n");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return answer.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue