utf8 in DB and youtubeapi parsing problem fixed
This commit is contained in:
parent
bdcc276d58
commit
a0b0ce6bfb
|
@ -97,7 +97,7 @@ public class DB implements Runnable {
|
||||||
private void connect(boolean selectdb) {
|
private void connect(boolean selectdb) {
|
||||||
try {
|
try {
|
||||||
//verbinden
|
//verbinden
|
||||||
con = DriverManager.getConnection("jdbc:mysql://" + server + ":" + port + "/" + (selectdb ? db : "") + "?serverTimezone=UTC&verifyServerCertificate=false&useSSL=true", user, pw);
|
con = DriverManager.getConnection("jdbc:mysql://" + server + ":" + port + "/" + (selectdb ? db : "") + "?serverTimezone=UTC&verifyServerCertificate=false&useSSL=true&useUnicode=true&characterEncoding=utf-8", user, pw);
|
||||||
}catch (SQLException e) {
|
}catch (SQLException e) {
|
||||||
log.error("Error while connecting to the database! ", e);
|
log.error("Error while connecting to the database! ", e);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,6 @@ public class DB implements Runnable {
|
||||||
* @param input
|
* @param input
|
||||||
*/
|
*/
|
||||||
public void addVideos(ArrayList<Video> input, boolean force) {
|
public void addVideos(ArrayList<Video> input, boolean force) {
|
||||||
//log.info("add " + input.size() + " videos");
|
|
||||||
if(input != null) {
|
if(input != null) {
|
||||||
if(input.size() > 0) {
|
if(input.size() > 0) {
|
||||||
writebuffercurrentsize += input.size();
|
writebuffercurrentsize += input.size();
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class YoutubeAPI {
|
||||||
try {
|
try {
|
||||||
int intid = Integer.parseInt(id);
|
int intid = Integer.parseInt(id);
|
||||||
out.put(intid, name);
|
out.put(intid, name);
|
||||||
System.out.println(intid + ";" + name);
|
// System.out.println(intid + ";" + name);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ public class YoutubeAPI {
|
||||||
String title = snippet.getString("title"); //maxlen: 100
|
String title = snippet.getString("title"); //maxlen: 100
|
||||||
long published = getDate(snippet.getString("publishedAt"));
|
long published = getDate(snippet.getString("publishedAt"));
|
||||||
String channel = snippet.getString("channelTitle");
|
String channel = snippet.getString("channelTitle");
|
||||||
String tags = snippet.getJSONArray("tags").toList().stream().map(o -> (String) o).collect(Collectors.joining(", ")); // max len: ~500
|
String tags = snippet.getJSONArray("tags").toList().stream().map(o -> (String) o).collect(Collectors.joining(",")); // max len: ~500
|
||||||
|
|
||||||
byte category = 0;
|
byte category = 0;
|
||||||
try {
|
try {
|
||||||
|
@ -115,7 +115,7 @@ public class YoutubeAPI {
|
||||||
int duration = (int) getDuration(contentDetails.getString("duration"));
|
int duration = (int) getDuration(contentDetails.getString("duration"));
|
||||||
boolean live = !snippet.getString("liveBroadcastContent").equalsIgnoreCase("none");
|
boolean live = !snippet.getString("liveBroadcastContent").equalsIgnoreCase("none");
|
||||||
|
|
||||||
String langCode = snippet.getString("defaultLanguage");
|
String langCode = snippet.optString("defaultLanguage", snippet.optString("defaultAudioLanguage", ""));
|
||||||
if(langCode.length() > 3) {
|
if(langCode.length() > 3) {
|
||||||
langCode = langCode.substring(0, 3);
|
langCode = langCode.substring(0, 3);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,13 @@ public class YoutubeAPITest {
|
||||||
Assertions.assertEquals(vid.id, "gsvKF2ojUzs");
|
Assertions.assertEquals(vid.id, "gsvKF2ojUzs");
|
||||||
Assertions.assertEquals(vid.title, "Mikebøi - Missed");
|
Assertions.assertEquals(vid.title, "Mikebøi - Missed");
|
||||||
Assertions.assertEquals(vid.channel, "Trap Nation");
|
Assertions.assertEquals(vid.channel, "Trap Nation");
|
||||||
Assertions.assertEquals(vid.tags, "mikeboi missed, trap nation, trapnation, трап натион, electronic music 2020, Trap, Electronic Dance Music, missed trap nation, trap music, Electronic Music, Trap Music, Dance Music, missed mike boi, gaming music, Trap Music 2017, mike boy missed, mikebøi - missed, нас не догонят ремикс, Trap Nation, TrapNation, Mikebøi - Missed, trap nation 2020, trap music 2020 remix, EDM, missed mikeboi, music");
|
Assertions.assertEquals(vid.tags, "mikeboi missed,trap nation,trapnation,трап натион,electronic music 2020,Trap,Electronic Dance Music,missed trap nation,trap music,Electronic Music,Trap Music,Dance Music,missed mike boi,gaming music,Trap Music 2017,mike boy missed,mikebøi - missed,нас не догонят ремикс,Trap Nation,TrapNation,Mikebøi - Missed,trap nation 2020,trap music 2020 remix,EDM,missed mikeboi,music");
|
||||||
Assertions.assertEquals(vid.length, 213);
|
Assertions.assertEquals(vid.length, 213);
|
||||||
Assertions.assertEquals(vid.languageCode, "en");
|
Assertions.assertEquals(vid.languageCode, "en");
|
||||||
Assertions.assertEquals(vid.categorie, 10);
|
Assertions.assertEquals(vid.categorie, 10);
|
||||||
Assertions.assertEquals(vid.created, 1491571496);
|
Assertions.assertEquals(vid.created, 1491571496);
|
||||||
Assertions.assertFalse(vid.live);
|
Assertions.assertFalse(vid.live);
|
||||||
|
|
||||||
|
|
||||||
Map<Integer, String> obj = api.getCategories();
|
Map<Integer, String> obj = api.getCategories();
|
||||||
|
|
||||||
Assertions.assertNotNull(obj);
|
Assertions.assertNotNull(obj);
|
||||||
|
|
Loading…
Reference in New Issue