This commit is contained in:
Celeste Madeline Samuel Nokto Dur Grossiord
2026-09-06 13:16:50 +02:00
parent 894ac6525e
commit ac26a8a4c0
75 changed files with 1425 additions and 579 deletions
@@ -0,0 +1,94 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1
rnd TEXT NOT NULL DEFAULT a
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public String getRND(String bindName) throws SQLException {
String sql = "SELECT rnd FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString("rnd");
} else {
return 1;
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -1,43 +0,0 @@
package org.sillyjirafe.uoapi.binds;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import org.sillyblahaj.uoapi.Api;
import org.sillyblahaj.uoapi.element;
public class OpenVerseImagesApi implements Api
{
public String getName()
{
return "OpenVerseImagesApi";
}
public String getURL(int page) {
return "https://api.openverse.org/v1/images/?format=json&page=" + page;
}
public List<element> Parse(String jsonRaw) {
List<element> resultats = new ArrayList<>();
try {
JSONObject json = new JSONObject(jsonRaw);
JSONArray items = json.getJSONArray("results");
for (int i = 0; i < items.length(); i++) {
JSONObject image = items.getJSONObject(i);
String titre = image.getString("title");
String url = image.getString("url");
String licence = image.getString("license");
resultats.add(new element(titre, url, licence, "openverse", "image"));
}
} catch (org.json.JSONException e) {
System.out.println("error but continue : " + e.getMessage());
}
return resultats;
}
}
@@ -1,25 +0,0 @@
package org.sillyjirafe.api;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import org.sillyblahaj.uoapi.element;
public class Json {
public static String JSONConvert(List<element> elements) {
JSONArray tableau = new JSONArray();
for (element e : elements) {
JSONObject obj = new JSONObject();
obj.put("title", e.title());
obj.put("url", e.url());
obj.put("licence", e.licence());
obj.put("source", e.source());
obj.put("type", e.type());
tableau.put(obj);
}
return tableau.toString();
}
}
@@ -0,0 +1,94 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1,
rnd TEXT NOT NULL DEFAULT 'a'
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public String getRND(String bindName) throws SQLException {
String sql = "SELECT rnd FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString("rnd");
} else {
return "a";
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -0,0 +1,94 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1
rnd TEXT NOT NULL DEFAULT a
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public int getRND(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -0,0 +1,105 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1,
rnd TEXT NOT NULL DEFAULT 'a'
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public String getRND(String bindName) throws SQLException {
String sql = "SELECT rnd FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString("rnd");
} else {
return "a";
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public static String NextLetter(String actual) {
char lettre = actual.charAt(0);
if (lettre >= 'z') {
return "a";
}
char suivante = (char) (lettre + 1);
return String.valueOf(suivante);
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -0,0 +1,94 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1
rnd TEXT NOT NULL DEFAULT a
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public String getRND(String bindName) throws SQLException {
String sql = "SELECT rnd FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString("rnd");
} else {
return "a";
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -5,11 +5,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.sillyblahaj.uoapi.binds.GitHubApacheApi;
import org.sillyblahaj.uoapi.binds.GitHubLGPLApi;
import org.sillyblahaj.uoapi.binds.GitHubMITApi;
import org.sillyblahaj.uoapi.binds.OpenVerseAudiosApi;
import org.sillyblahaj.uoapi.binds.OpenVerseImagesApi;
import org.sillyjirafe.uoapi.binds.GitHubApacheApi;
import org.sillyjirafe.uoapi.binds.GitHubLGPLApi;
import org.sillyjirafe.uoapi.binds.GitHubMITApi;
import org.sillyjirafe.uoapi.binds.OpenVerseAudiosApi;
import org.sillyjirafe.uoapi.binds.OpenVerseImagesApi;
public class Out {
List<Api> Apis = new ArrayList<>();
@@ -21,6 +21,7 @@ public class Out {
Apis.add(new GitHubApacheApi());
Apis.add(new OpenVerseImagesApi());
Apis.add(new OpenVerseAudiosApi());
Apis.add(new CodeBergApi()));
List<String> bindnames = new ArrayList<>();
@@ -1,58 +0,0 @@
package org.sillyjirafe.api;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.sillyblahaj.uoapi.element;
import com.sun.net.httpserver.HttpServer;
public class Start {
public static void API(Connection conn) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(8081), 0);
server.createContext("/search", exchange -> {
String query = exchange.getRequestURI().getQuery();
Map<String, String> settings = parseQuery(query);
try {
List<element> results = Search.search(conn, settings);
String json = Json.JSONConvert(results);
exchange.getResponseHeaders().set("Content-Type", "application/json");
exchange.sendResponseHeaders(200, json.getBytes().length);
exchange.getResponseBody().write(json.getBytes());
exchange.getResponseBody().close();
} catch (Exception e) {
e.printStackTrace();
exchange.sendResponseHeaders(500, 0);
exchange.getResponseBody().close();
}
});
server.start();
System.out.println("Search API run on 8081 port");
}
public static Map<String, String> parseQuery(String query) {
Map<String, String> params = new HashMap<>();
if (query == null) return params;
String[] paires = query.split("&");
for (String paire : paires) {
String[] cle_valeur = paire.split("=", 2);
if (cle_valeur.length == 2) {
params.put(cle_valeur[0], cle_valeur[1]);
}
}
return params;
}
}
@@ -1,28 +1,28 @@
package org.sillyjrafe.uoapi.binds;
import java.util.ArrayList;
import java.util.List;
package org.sillyjirafe.uoapi.binds;
import org.json.JSONArray;
import org.json.JSONObject;
import org.sillyjirafe.uoapi.Api;
import org.sillyjirafe.uoapi.element;
import java.util.ArrayList;
import java.util.List;
public class GitHubLGPLApi implements Api
public class CodeBergApi implements Api
{
public String getName()
{
return "GitHubLGPLApi";
return "CadeBergApi";
}
public String getURL(int page) {
return "https://api.github.com/search/repositories?q=license:lgpl-3.0&page=" + page;
return "https://codeberg.org/api/v1/repos/search?page=" + page;
}
public List<element> Parse(String jsonRaw) {
List<element> resultats = new ArrayList<>();
try {
JSONObject json = new JSONObject(jsonRaw);
JSONArray items = json.getJSONArray("items");
@@ -0,0 +1,5 @@
package org.sillyjirafe.uoapi;
public class ApiKeys {
}
@@ -0,0 +1,94 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1
rnd TEXT NOT NULL DEFAULT a
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public int getRND(String bindName) throws SQLException {
String sql = "SELECT rnd FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("rnd");
} else {
return 1;
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -0,0 +1,127 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1,
rnd TEXT NOT NULL DEFAULT 'a'
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public String getRND(String bindName) throws SQLException {
String sql = "SELECT rnd FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString("rnd");
} else {
return "a";
}
}
}
public void updatePage(String bindName, int maxPage) throws SQLException {
int pageActuelle = getPage(bindName);
String rndActuel = getRND(bindName);
int nouvellePage;
String nouveauRnd;
if (pageActuelle >= maxPage) {
nouvellePage = 1;
nouveauRnd = NextLetter(rndActuel);
} else {
nouvellePage = pageActuelle + 1;
nouveauRnd = rndActuel;
}
String sql = """
INSERT INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)
ON CONFLICT(bind_name) DO UPDATE SET last_page = ?, rnd = ?
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.setInt(2, nouvellePage);
ps.setString(3, nouveauRnd);
ps.setInt(4, nouvellePage);
ps.setString(5, nouveauRnd);
ps.executeUpdate();
}
}
public static String NextLetter(String actual) {
char[] lettres = actual.toCharArray();
int i = lettres.length - 1;
while (i >= 0) {
if (lettres[i] < 'z') {
lettres[i]++;
return new String(lettres);
}
lettres[i] = 'a';
i--;
}
return "a" + new String(lettres);
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -2,12 +2,12 @@ package org.sillyjirafe.uoapi.binds;
import org.json.JSONArray;
import org.json.JSONObject;
import org.sillyblahaj.uoapi.Api;
import org.sillyblahaj.uoapi.element;
import org.sillyjirafe.uoapi.Api;
import org.sillyjirafe.uoapi.element;
import java.util.ArrayList;
import java.util.List;
public class GitHubMITApi implements Api
public class CodeBergApi implements Api
{
public String getName()
@@ -0,0 +1,94 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1
rnd TEXT NOT NULL DEFAULT a
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public int getRND(String bindName) throws SQLException {
String sql = "SELECT rnd FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -0,0 +1,94 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1,
rnd TEXT NOT NULL DEFAULT 'a'
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public String getRND(String bindName) throws SQLException {
String sql = "SELECT rnd FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString("rnd");
} else {
return "a";
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -0,0 +1,105 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1,
rnd TEXT NOT NULL DEFAULT 'a'
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public String getRND(String bindName) throws SQLException {
String sql = "SELECT rnd FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString("rnd");
} else {
return "a";
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public static String lettreSuivante(String actuelle) {
char lettre = actuelle.charAt(0);
if (lettre >= 'z') {
return "a";
}
char suivante = (char) (lettre + 1);
return String.valueOf(suivante);
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -1,58 +0,0 @@
package org.sillyblahaj.api;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.sillyblahaj.uoapi.element;
import com.sun.net.httpserver.HttpServer;
public class Start {
public static void API(Connection conn) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(8081), 0);
server.createContext("/search", exchange -> {
String query = exchange.getRequestURI().getQuery();
Map<String, String> settings = parseQuery(query);
try {
List<element> results = Search.search(conn, settings);
String json = Json.JSONConvert(results);
exchange.getResponseHeaders().set("Content-Type", "application/json");
exchange.sendResponseHeaders(200, json.getBytes().length);
exchange.getResponseBody().write(json.getBytes());
exchange.getResponseBody().close();
} catch (Exception e) {
e.printStackTrace();
exchange.sendResponseHeaders(500, 0);
exchange.getResponseBody().close();
}
});
server.start();
System.out.println("Search API run on 8081 port");
}
public static Map<String, String> parseQuery(String query) {
Map<String, String> params = new HashMap<>();
if (query == null) return params;
String[] paires = query.split("&");
for (String paire : paires) {
String[] cle_valeur = paire.split("=", 2);
if (cle_valeur.length == 2) {
params.put(cle_valeur[0], cle_valeur[1]);
}
}
return params;
}
}
@@ -1,44 +0,0 @@
package org.sillyjirafe.uoapi.binds;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import org.sillyjirafe.uoapi.Api;
import org.sillyblahaj.uoapi.element;
public class OpenVerseAudiosApi implements Api
{
public String getName()
{
return "OpenVerseAudiosApi";
}
public String getURL(int page) {
return "https://api.openverse.org/v1/audio/?format=json&page=" + page;
}
public List<element> Parse(String jsonRaw) {
List<element> resultats = new ArrayList<>();
try {
JSONObject json = new JSONObject(jsonRaw);
JSONArray items = json.getJSONArray("results");
for (int i = 0; i < items.length(); i++) {
JSONObject image = items.getJSONObject(i);
String titre = image.getString("title");
String url = image.getString("url");
String licence = image.getString("license");
resultats.add(new element(titre, url, licence, "openverse", "audio"));
}
} catch (org.json.JSONException e) {
System.out.println("error but continue : " + e.getMessage());
}
return resultats;
}
}
@@ -1,45 +0,0 @@
package org.sillyjrafe.uoapi.binds;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import org.sillyblahaj.uoapi.Api;
import org.sillyblahaj.uoapi.element;
public class GitHubLGPLApi implements Api
{
public String getName()
{
return "GitHubLGPLApi";
}
public String getURL(int page) {
return "https://api.github.com/search/repositories?q=license:lgpl-3.0&page=" + page;
}
public List<element> Parse(String jsonRaw) {
List<element> resultats = new ArrayList<>();
try {
JSONObject json = new JSONObject(jsonRaw);
JSONArray items = json.getJSONArray("items");
for (int i = 0; i < items.length(); i++) {
JSONObject repo = items.getJSONObject(i);
String titre = repo.getString("full_name");
String url = repo.getString("html_url");
String licence = repo.getJSONObject("license").getString("spdx_id");
resultats.add(new element(titre, url, licence, "github", "code"));
}
} catch (org.json.JSONException e) {
System.out.println("error but continue : " + e.getMessage());
}
return resultats;
}
}
@@ -0,0 +1,94 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1
rnd TEXT NOT NULL DEFAULT a
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public int getRND(String bindName) throws SQLException {
String sql = "SELECT rnd FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString("rnd");
} else {
return 1;
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -1,44 +0,0 @@
package org.sillyjirafe.uoapi.binds;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import org.sillyblahaj.uoapi.Api;
import org.sillyblahaj.uoapi.element;
public class GitHubApacheApi implements Api
{
public String getName()
{
return "GitHubApacheApi";
}
public String getURL(int page) {
return "https://api.github.com/search/repositories?q=license:apache-2.0&page=" + page;
}
public List<element> Parse(String jsonRaw) {
List<element> resultats = new ArrayList<>();
try {
JSONObject json = new JSONObject(jsonRaw);
JSONArray items = json.getJSONArray("items");
for (int i = 0; i < items.length(); i++) {
JSONObject repo = items.getJSONObject(i);
String titre = repo.getString("full_name");
String url = repo.getString("html_url");
String licence = repo.getJSONObject("license").getString("spdx_id");
resultats.add(new element(titre, url, licence, "github", "code"));
}
} catch (org.json.JSONException e) {
System.out.println("error but continue : " + e.getMessage());
}
return resultats;
}
}
@@ -0,0 +1,80 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1
rnd TEXT NOT NULL DEFAULT a
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -1,43 +0,0 @@
package org.sillyjirafe.uoapi.binds;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import org.sillyjirafe.uoapi.Api;
import org.sillyblahaj.uoapi.element;
public class OpenVerseImagesApi implements Api
{
public String getName()
{
return "OpenVerseImagesApi";
}
public String getURL(int page) {
return "https://api.openverse.org/v1/images/?format=json&page=" + page;
}
public List<element> Parse(String jsonRaw) {
List<element> resultats = new ArrayList<>();
try {
JSONObject json = new JSONObject(jsonRaw);
JSONArray items = json.getJSONArray("results");
for (int i = 0; i < items.length(); i++) {
JSONObject image = items.getJSONObject(i);
String titre = image.getString("title");
String url = image.getString("url");
String licence = image.getString("license");
resultats.add(new element(titre, url, licence, "openverse", "image"));
}
} catch (org.json.JSONException e) {
System.out.println("error but continue : " + e.getMessage());
}
return resultats;
}
}
@@ -1,44 +0,0 @@
package org.sillyblahaj.api;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.sillyblahaj.uoapi.element;
public class Search {
public static List<element> search(Connection conn, Map<String, String> settings) throws SQLException {
List<element> results = new ArrayList<>();
String sql = """
SELECT * FROM creations
WHERE (? = '' OR title LIKE ?)
AND (? = '' OR licence = ?)
AND (? = '' OR type = ?)
""";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, settings.getOrDefault("q", ""));
ps.setString(2, "%" + settings.getOrDefault("q", "") + "%");
ps.setString(3, settings.getOrDefault("licence", ""));
ps.setString(4, settings.getOrDefault("licence", ""));
ps.setString(5, settings.getOrDefault("type", ""));
ps.setString(6, settings.getOrDefault("type", ""));
ResultSet rs = ps.executeQuery();
while (rs.next()) {
results.add(new element(
rs.getString("title"),
rs.getString("url"),
rs.getString("licence"),
rs.getString("source"),
rs.getString("type")
));
}
}
return results;
}
}
@@ -1,42 +0,0 @@
package org.sillyjirafe.linker;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.sillyblahaj.db.Crawl_StateDB;
import org.sillyblahaj.db.ElementsDB;
import org.sillyblahaj.uoapi.*;
public class Main {
public static void main(String[] args) throws Exception
{
Out Out = new Out();
ElementsDB elementDB = new ElementsDB("jdbc:sqlite:elements.db");
Crawl_StateDB crawlstateDB = new Crawl_StateDB("jdbc:sqlite:crawlstates.db");
elementDB.LinkToDB();
crawlstateDB.LinkToDB();
List<String> bindNames = Out.PreOut();
Map<String, Integer> pages = new HashMap<>();
for (String nom : bindNames) {
pages.put(nom, crawlstateDB.getPage(nom));
}
List<element> elements = Out.out(pages);
for (int i = 0; i < elements.size(); i++)
{
element el = elements.get(i);
elementDB.AddEllement(el.title(), el.url(), el.licence(), el.source(), el.type());
}
for (String name : bindNames) {
crawlstateDB.updatePage(name);
}
elementDB.Close();
crawlstateDB.Close();
}
}
@@ -1,44 +0,0 @@
package org.sillyjirafe.api;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.sillyblahaj.uoapi.element;
public class Search {
public static List<element> search(Connection conn, Map<String, String> settings) throws SQLException {
List<element> results = new ArrayList<>();
String sql = """
SELECT * FROM creations
WHERE (? = '' OR title LIKE ?)
AND (? = '' OR licence = ?)
AND (? = '' OR type = ?)
""";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, settings.getOrDefault("q", ""));
ps.setString(2, "%" + settings.getOrDefault("q", "") + "%");
ps.setString(3, settings.getOrDefault("licence", ""));
ps.setString(4, settings.getOrDefault("licence", ""));
ps.setString(5, settings.getOrDefault("type", ""));
ps.setString(6, settings.getOrDefault("type", ""));
ResultSet rs = ps.executeQuery();
while (rs.next()) {
results.add(new element(
rs.getString("title"),
rs.getString("url"),
rs.getString("licence"),
rs.getString("source"),
rs.getString("type")
));
}
}
return results;
}
}
@@ -0,0 +1,94 @@
package org.sillyjirafe.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Crawl_StateDB
{
String URL = new String();
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page, rnd) VALUES (?, ?, ?)";
Connection connection;
public Crawl_StateDB(String BDstr) throws SQLException
{
URL = BDstr;
connection = DriverManager.getConnection(URL);
}
public void LinkToDB() throws SQLException
{
try (Statement stmt = connection.createStatement())
{
stmt.execute("""
CREATE TABLE IF NOT EXISTS crawlstates (
bind_name TEXT PRIMARY KEY,
last_page INTEGER NOT NULL DEFAULT 1,
rnd TEXT NOT NULL DEFAULT a
)
""");
}
}
public void AddEllement(String bind, int lastpage) throws SQLException
{
try (PreparedStatement ps = connection.prepareStatement(insertSql))
{
ps.setString(1, bind);
ps.setInt(2, lastpage);
ps.executeUpdate();
System.out.printf("%s is now page %d \n", bind, lastpage);
}
}
public int getPage(String bindName) throws SQLException {
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("last_page");
} else {
return 1;
}
}
}
public String getRND(String bindName) throws SQLException {
String sql = "SELECT rnd FROM crawlstates WHERE bind_name = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString("rnd");
} else {
return "a";
}
}
}
public void updatePage(String bindName) throws SQLException {
String sql = """
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
""";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, bindName);
ps.executeUpdate();
}
}
public void Close() throws SQLException
{
if (connection != null)
{
connection.close();
}
}
}
@@ -1,42 +0,0 @@
package org.sillyjirafe.linker;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.sillyjirafe.db.Crawl_StateDB;
import org.sillyjirafe.db.ElementsDB;
import org.sillyblahaj.uoapi.*;
public class Main {
public static void main(String[] args) throws Exception
{
Out Out = new Out();
ElementsDB elementDB = new ElementsDB("jdbc:sqlite:elements.db");
Crawl_StateDB crawlstateDB = new Crawl_StateDB("jdbc:sqlite:crawlstates.db");
elementDB.LinkToDB();
crawlstateDB.LinkToDB();
List<String> bindNames = Out.PreOut();
Map<String, Integer> pages = new HashMap<>();
for (String nom : bindNames) {
pages.put(nom, crawlstateDB.getPage(nom));
}
List<element> elements = Out.out(pages);
for (int i = 0; i < elements.size(); i++)
{
element el = elements.get(i);
elementDB.AddEllement(el.title(), el.url(), el.licence(), el.source(), el.type());
}
for (String name : bindNames) {
crawlstateDB.updatePage(name);
}
elementDB.Close();
crawlstateDB.Close();
}
}
@@ -1,44 +0,0 @@
package org.sillyjirafe.uoapi.binds;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import org.sillyblahaj.uoapi.Api;
import org.sillyblahaj.uoapi.element;
public class OpenVerseAudiosApi implements Api
{
public String getName()
{
return "OpenVerseAudiosApi";
}
public String getURL(int page) {
return "https://api.openverse.org/v1/audio/?format=json&page=" + page;
}
public List<element> Parse(String jsonRaw) {
List<element> resultats = new ArrayList<>();
try {
JSONObject json = new JSONObject(jsonRaw);
JSONArray items = json.getJSONArray("results");
for (int i = 0; i < items.length(); i++) {
JSONObject image = items.getJSONObject(i);
String titre = image.getString("title");
String url = image.getString("url");
String licence = image.getString("license");
resultats.add(new element(titre, url, licence, "openverse", "audio"));
}
} catch (org.json.JSONException e) {
System.out.println("error but continue : " + e.getMessage());
}
return resultats;
}
}