amy 2024-09-20 12:10:35 +03:30
parent 459df60dcd
commit 75d14a7f09
7 changed files with 78 additions and 7 deletions

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>

View file

@ -1,5 +1,6 @@
plugins {
id("java")
id("io.freefair.lombok") version "8.10"
}
group = "dev.exhq"
@ -12,6 +13,10 @@ repositories {
dependencies {
testImplementation(platform("org.junit:junit-bom:5.10.0"))
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 {

View file

@ -1,7 +0,0 @@
package dev.exhq;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

View 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)));
}
}

View file

@ -0,0 +1,4 @@
package dev.exhq.nutjammer.scraper;
public record RequestType(String id, RequestTypePlatform platform) {
}

View file

@ -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;
}
}

View 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();
}
}