Skip to content

Commit

Permalink
Merge pull request #10 from BLCK-B/dev
Browse files Browse the repository at this point in the history
merge v7 changes
  • Loading branch information
BLCK-B authored Nov 8, 2023
2 parents dab6f8a + 973d4c0 commit c114931
Show file tree
Hide file tree
Showing 17 changed files with 423 additions and 191 deletions.
2 changes: 1 addition & 1 deletion MRTinstallerScript.nsi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; UI settings
!include "MUI2.nsh"
!define VERSION "6"
!define VERSION "7"
!define MUI_ABORTWARNING
!define MUI_ICON "MRTicon.ico"
!insertmacro MUI_PAGE_LICENSE "license.txt"
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/blck/MusicReleaseTracker/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public void clickArtistAdd(@RequestBody String artistname) {
public void clickArtistDelete() {
sendRequest.artistClickDelete();
}
@PostMapping("/deleteUrl")
public void deleteUrl() {
sendRequest.deleteUrl();
}

@RequestMapping ("/cleanArtistSource")
public void cleanArtistSource() {
Expand Down Expand Up @@ -132,4 +136,13 @@ public String getLastArtist() {
return sendRequest.getLastArtist();
}

@PostMapping("/resetSettings")
public void resetSettings() {
sendRequest.resetSettings();
}
@PostMapping("/resetDB")
public void resetDB() {
sendRequest.resetDB();
}

}
34 changes: 29 additions & 5 deletions src/main/java/com/blck/MusicReleaseTracker/DBtools.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ public static void path() {

public static void createTables() {
//on start: create DB if not exist, check DB structure, if different -> create new from template and refill with all data possible
File templateFile = new File(settingsStore.getDBTemplatePath().substring(12));
templateFile.delete();
createDB(settingsStore.getDBpath());
createDB(settingsStore.getDBTemplatePath());

//if different structure, fill template artist table data from musicdata and then rename/delete, make new template
//this only preserves "artists" data and assumes that the insertion logic will be adjusted on any changes
// made to the "artists" table: change in order of columns, removing a column or changing a column's name
//this only preserves "artists" data and assumes that the insertion logic will be adjusted after any changes...
//made to the "artists" table: change in order of columns, adding/removing a column or changing a column's name
Map<String, ArrayList<String>> DBMap = getDBStructure(settingsStore.getDBpath());
Map<String, ArrayList<String>> DBtemplateMap = getDBStructure(settingsStore.getDBTemplatePath());
if (!DBMap.equals(DBtemplateMap)) {
Expand All @@ -79,7 +81,7 @@ public static void createTables() {
Statement stmt = connDB.createStatement();
ResultSet rs = stmt.executeQuery(sql);

sql = "insert into artists(artistname, urlbrainz, urlbeatport, urljunodownload) values(?, ?, ?, ?)";
sql = "insert into artists(artistname, urlbrainz, urlbeatport, urljunodownload, urlyoutube) values(?, ?, ?, ?, ?)";
PreparedStatement pstmt = connDBtemplate.prepareStatement(sql);
ArrayList<String> columnList = DBMap.get("artists");
//cycling table rows
Expand Down Expand Up @@ -147,11 +149,20 @@ private static void createDB(String path) {
stmt = conn.createStatement();
stmt.execute(sql);

sql = "CREATE TABLE IF NOT EXISTS youtube (\n"
+ " song text NOT NULL,\n"
+ " artist text NOT NULL,\n"
+ " date text NOT NULL\n"
+ ");";
stmt = conn.createStatement();
stmt.execute(sql);

sql = "CREATE TABLE IF NOT EXISTS artists (\n"
+ " artistname text PRIMARY KEY,\n"
+ " urlbrainz text,\n"
+ " urlbeatport text,\n"
+ " urljunodownload text\n"
+ " urljunodownload text,\n"
+ " urlyoutube text\n"
+ ");";
stmt = conn.createStatement();
stmt.execute(sql);
Expand Down Expand Up @@ -242,7 +253,7 @@ public static void writeSingleConfig(String name, String value) {
}
}

public static void updateSettingsDB() {
public static void updateSettings() {
//create config if it does not exist, change to latest structure and transfer data if a different structure is detected

// appData/MusicReleaseTracker/MRTsettings.hocon
Expand Down Expand Up @@ -353,6 +364,19 @@ private static ArrayList<String> extractStructure(Config config) {
}
return structure;
}

public static void resetSettings() {
//default settings
File configFile = new File(settingsStore.getConfigPath());
configFile.delete();
updateSettings();
}
public static void resetDB() {
//default musicdata
File musicdata = new File(settingsStore.getDBpath().substring(12));
musicdata.delete();
createDB(settingsStore.getDBpath());
}
}


Expand Down
71 changes: 56 additions & 15 deletions src/main/java/com/blck/MusicReleaseTracker/GUIController.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public void artistClickDelete() {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lastClickedArtist);
pstmt.executeUpdate();
sql = "DELETE FROM youtube WHERE artist = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lastClickedArtist);
pstmt.executeUpdate();
conn.close();
lastClickedArtist = null;
}
Expand All @@ -94,8 +98,37 @@ public void artistClickDelete() {
}
}
}
public void deleteUrl() {
//set null specific URL, delete related set
if (lastClickedArtist != null && selectedSource != null) {
try {
Connection conn = DriverManager.getConnection(DBtools.settingsStore.getDBpath());
String sql = null;
switch (selectedSource) {
case "musicbrainz" -> sql = "UPDATE artists SET urlbrainz = NULL WHERE artistname = ?";
case "beatport" -> sql = "UPDATE artists SET urlbeatport = NULL WHERE artistname = ?";
case "junodownload" -> sql = "UPDATE artists SET urljunodownload = NULL WHERE artistname = ?";
case "youtube" -> sql = "UPDATE artists SET urlyoutube = NULL WHERE artistname = ?";
default -> {
return;
}
}
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lastClickedArtist);
pstmt.executeUpdate();
sql = "DELETE FROM " + selectedSource + " WHERE artist = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lastClickedArtist);
pstmt.execute();
conn.close();
}
catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
public void cleanArtistSource() {
//clean artist from source table
//clear artist entries from a source table
try {
Connection conn = DriverManager.getConnection(DBtools.settingsStore.getDBpath());
String sql = "DELETE FROM " + selectedSource + " WHERE artist = ?";
Expand Down Expand Up @@ -150,13 +183,8 @@ public List<TableModel> sourceTabClick(String source) {
public void loadTable() throws SQLException {
tableContent.clear();
//adding data to tableContent
String sql = null;
Connection conn = DriverManager.getConnection(DBtools.settingsStore.getDBpath());
switch (selectedSource) {
case "musicbrainz" -> sql = "SELECT song, date FROM musicbrainz WHERE artist = ? ORDER BY date DESC";
case "beatport" -> sql = "SELECT song, date FROM beatport WHERE artist = ? ORDER BY date DESC";
case "junodownload" -> sql = "SELECT song, date FROM junodownload WHERE artist = ? ORDER BY date DESC";
}
String sql = "SELECT song, date FROM " + selectedSource + " WHERE artist = ? ORDER BY date DESC";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lastClickedArtist);
ResultSet rs = pstmt.executeQuery();
Expand Down Expand Up @@ -210,21 +238,19 @@ public void clickAddURL(String url) {
//https://musicbrainz.org/artist/ad110705-cbe6-4c47-9b99-8526e6db0f41/recordings
artistIndex = url.indexOf("/artist/");
if (artistIndex != -1 && url.contains("musicbrainz.org")) {
//index of following "/" after "/artist/" - starting from the index that is sum of artistIndex and the length of "/artist/"
//"/artist/".length() is to skip the "/artist/" part and start the search from the beginning of the ID
int artistIdIndex = url.indexOf('/', artistIndex + "/artist/".length());
if (artistIdIndex != -1)
url = url.substring(0, artistIdIndex);
//https://musicbrainz.org/artist/ad110705-cbe6-4c47-9b99-8526e6db0f41
}
else
return;
//for latest releases
if(!url.contains("page="))
url += "/releases/?page=20";
//https://musicbrainz.org/artist/ad110705-cbe6-4c47-9b99-8526e6db0f41/releases/?page=20
try {
MainBackend.scrapeBrainz(url, lastClickedArtist);
} catch (IOException e) {
throw new RuntimeException(e);
System.out.println("incorrect link");
}
}
case "beatport" -> {
Expand All @@ -248,7 +274,7 @@ public void clickAddURL(String url) {
try {
MainBackend.scrapeBeatport(url, lastClickedArtist);
} catch (IOException e) {
throw new RuntimeException(e);
System.out.println("incorrect link");
}
}
case "junodownload" -> {
Expand All @@ -268,7 +294,14 @@ public void clickAddURL(String url) {
try {
MainBackend.scrapeJunodownload(url, lastClickedArtist);
} catch (IOException e) {
throw new RuntimeException(e);
System.out.println("incorrect link");
}
}
case "youtube" -> {
try {
MainBackend.scrapeYoutube(url, lastClickedArtist);
} catch (IOException e) {
System.out.println("incorrect link");
}
}
}
Expand All @@ -277,11 +310,12 @@ public void clickAddURL(String url) {

public void saveUrl() {
//save artist url to db
String sql;
String sql = null;
switch (selectedSource) {
case "musicbrainz" -> sql = "UPDATE artists SET urlbrainz = ? WHERE artistname = ?";
case "beatport" -> sql = "UPDATE artists SET urlbeatport = ? WHERE artistname = ?";
case "junodownload" -> sql = "UPDATE artists SET urljunodownload = ? WHERE artistname = ?";
case "youtube" -> sql = "UPDATE artists SET urlyoutube = ? WHERE artistname = ?";
default -> {
return;
}
Expand All @@ -306,6 +340,7 @@ public boolean checkExistURL() {
case "musicbrainz" -> sql = "SELECT urlbrainz FROM artists WHERE artistname = ?";
case "beatport" -> sql = "SELECT urlbeatport FROM artists WHERE artistname = ?";
case "junodownload" -> sql = "SELECT urljunodownload FROM artists WHERE artistname = ?";
case "youtube" -> sql = "SELECT urlyoutube FROM artists WHERE artistname = ?";
default -> {
return urlExists;
}
Expand Down Expand Up @@ -408,5 +443,11 @@ public String getLastArtist() {
return lastClickedArtist;
}

public void resetSettings() {
DBtools.resetSettings();
}
public void resetDB() {
DBtools.resetDB();
}

}
Loading

0 comments on commit c114931

Please sign in to comment.