Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 63 additions & 48 deletions src/main/java/com/josdem/jmetadata/ApplicationConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,67 @@

package com.josdem.jmetadata;

public interface ApplicationConstants {
String LOGIN_FAIL = "Login fail";
String LOGGED_AS = "Logged as : ";
String DONE = "Done";
String OPEN_ERROR = "Error on importing Music";
String WORKING = "Working";
int ARTIST_COLUMN = 0;
int TITLE_COLUMN = 1;
int ALBUM_COLUMN = 2;
int GENRE_COLUMN = 3;
int YEAR_COLUMN = 4;
int TRACK_NUMBER_COLUMN = 5;
int TOTAL_TRACKS_NUMBER_COLUMN = 6;
int CD_NUMBER_COLUMN = 7;
int TOTAL_CDS_NUMBER_COLUMN = 8;
int STATUS_COLUMN = 9;
int WIDTH = 1024;
int HEIGHT = 600;
String COVER_ART_FROM_FILE = "Cover Art from File";
String COVER_ART_FROM_LASTFM = "Cover Art from Lastfm";
String COVER_ART_FROM_MUSIC_BRAINZ = "Cover Art from MusicBrainz";
String COVER_ART_FROM_DRAG_AND_DROP = "Cover Art from Drag & Drop";
String COVER_ART_DEFAULT = "Covert Art not found";
String APPLY = "Apply";
String EXPORT = "Export";
String NEW = "New";
String READY = "Ready";
String APPLICATION_NAME = "JMetadata";
String IMAGE_EXT = "PNG";
String FILE_EXT = "txt";
String PREFIX = "JMetadata_";
String GETTING_ALBUM = "Getting Album from Musicbrainz";
String GETTING_LAST_FM = "Getting Last.fm Metadata";
String COMPLETE_DEFAULT_VALUES = "Completing default values";
String GETTING_FORMATTER = "Formatting metadata";
String WRITING_METADATA = "Writing Metadata";
String USERNAME_LABEL = "username:";
String PASSWORD_LABEL = "password:";
int THREE_HUNDRED = 300;
String CORRUPTED_METADATA_LABEL = " has a corrupted coverArt";
String METADATA_FROM_FILE_LABEL = " title and artist metadata were extracted from file name";
String AND_ANOTHER = " and another ";
String DIRECTORY_EMPTY = "I could not find any mp3 or mp4 audio file in the directory";
String DIRECTORY_NOT_FOUND = "I could not find that directory to scan: ";
String FILE_NOT_FOUND = "I could not find this file: ";
String TOO_MUCH_FILES_LOADED = "Too much files loaded, maximum allowed: ";
String MEDIA_TYPE = "application/json";
String USER_AGENT = "JMetadata/1.1.0 ([email protected])";
public final class ApplicationConstants {

private ApplicationConstants() {}

public static final String LOGIN_FAIL = "Login fail";
public static final String LOGGED_AS = "Logged as : ";
public static final String DONE = "Done";
public static final String OPEN_ERROR = "Error on importing Music";
public static final String WORKING = "Working";

public static final int ARTIST_COLUMN = 0;
public static final int TITLE_COLUMN = 1;
public static final int ALBUM_COLUMN = 2;
public static final int GENRE_COLUMN = 3;
public static final int YEAR_COLUMN = 4;
public static final int TRACK_NUMBER_COLUMN = 5;
public static final int TOTAL_TRACKS_NUMBER_COLUMN = 6;
public static final int CD_NUMBER_COLUMN = 7;
public static final int TOTAL_CDS_NUMBER_COLUMN = 8;
public static final int STATUS_COLUMN = 9;

public static final int WIDTH = 1024;
public static final int HEIGHT = 600;

public static final String COVER_ART_FROM_FILE = "Cover Art from File";
public static final String COVER_ART_FROM_LASTFM = "Cover Art from Lastfm";
public static final String COVER_ART_FROM_MUSIC_BRAINZ = "Cover Art from MusicBrainz";
public static final String COVER_ART_FROM_DRAG_AND_DROP = "Cover Art from Drag & Drop";
public static final String COVER_ART_DEFAULT = "Cover Art not found";

public static final String APPLY = "Apply";
public static final String EXPORT = "Export";
public static final String NEW = "New";
public static final String READY = "Ready";

public static final String APPLICATION_NAME = "JMetadata";
public static final String IMAGE_EXT = "PNG";
public static final String FILE_EXT = "txt";
public static final String PREFIX = "JMetadata_";

public static final String GETTING_ALBUM = "Getting Album from Musicbrainz";
public static final String GETTING_LAST_FM = "Getting Last.fm Metadata";
public static final String COMPLETE_DEFAULT_VALUES = "Completing default values";
public static final String GETTING_FORMATTER = "Formatting metadata";
public static final String WRITING_METADATA = "Writing Metadata";

public static final String USERNAME_LABEL = "username:";
public static final String PASSWORD_LABEL = "password:";

public static final int THREE_HUNDRED = 300;

public static final String CORRUPTED_METADATA_LABEL = " has a corrupted coverArt";
public static final String METADATA_FROM_FILE_LABEL =
" title and artist metadata were extracted from file name";
public static final String AND_ANOTHER = " and another ";
public static final String DIRECTORY_EMPTY =
"I could not find any mp3 or mp4 audio file in the directory";
public static final String DIRECTORY_NOT_FOUND = "I could not find that directory to scan: ";
public static final String FILE_NOT_FOUND = "I could not find this file: ";
public static final String TOO_MUCH_FILES_LOADED = "Too much files loaded, maximum allowed: ";

public static final String MEDIA_TYPE = "application/json";
public static final String USER_AGENT = "JMetadata/1.1.0 ([email protected])";
}
9 changes: 6 additions & 3 deletions src/main/java/com/josdem/jmetadata/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package com.josdem.jmetadata;

public interface Auth {
static final String KEY = "LASTFM_API_KEY";
static final String SECRET = "LASTFM_API_SECRET";
public final class Auth {

private Auth() {}

public static final String KEY = "LASTFM_API_KEY";
public static final String SECRET = "LASTFM_API_SECRET";
}
22 changes: 11 additions & 11 deletions src/main/java/com/josdem/jmetadata/action/ActionResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
package com.josdem.jmetadata.action;

public enum ActionResult {
Ready,
New,
Error,
Not_Scrobbleable,
Sessionless,
NotFound,
Updated,
NotLogged,
Sent,
Exported,
Complete
READY,
NEW,
ERROR,
NOT_SCROBBLEABLE,
SESSIONLESS,
NOT_FOUND,
UPDATED,
NOT_LOGGED,
SENT,
EXPORTED,
COMPLETE
}
52 changes: 26 additions & 26 deletions src/main/java/com/josdem/jmetadata/action/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,39 @@
import org.asmatron.messengine.action.RequestAction;
import org.asmatron.messengine.action.ValueAction;

/**
* @author josdem ([email protected])
* @understands A class who has Publisher Subscriber label descriptors
*/
public interface Actions {
String LOGIN_ID = "login";
ActionId<ValueAction<User>> LOGIN = cm(LOGIN_ID);

String GET_METADATA = "getMetadata";
ActionId<EmptyAction> METADATA = cm(GET_METADATA);

String SEND_METADATA = "sendMetadata";
ActionId<RequestAction<Metadata, ActionResult>> SEND = cm(SEND_METADATA);

String COMPLETE_ALBUM_METADATA = "completeAlbumMetadata";
ActionId<RequestAction<List<Metadata>, ActionResult>> COMPLETE_MUSICBRAINZ =
public final class Actions {

private Actions() {}

public static final String LOGIN_ID = "login";
public static final ActionId<ValueAction<User>> LOGIN = cm(LOGIN_ID);

public static final String GET_METADATA = "getMetadata";
public static final ActionId<EmptyAction> METADATA = cm(GET_METADATA);

public static final String SEND_METADATA = "sendMetadata";
public static final ActionId<RequestAction<Metadata, ActionResult>> SEND = cm(SEND_METADATA);

public static final String COMPLETE_ALBUM_METADATA = "completeAlbumMetadata";
public static final ActionId<RequestAction<List<Metadata>, ActionResult>> COMPLETE_MUSICBRAINZ =
cm(COMPLETE_ALBUM_METADATA);

String COMPLETE_LAST_FM_METADATA = "completeLastfmMetadata";
ActionId<RequestAction<List<Metadata>, ActionResult>> COMPLETE_LAST_FM =
public static final String COMPLETE_LAST_FM_METADATA = "completeLastfmMetadata";
public static final ActionId<RequestAction<List<Metadata>, ActionResult>> COMPLETE_LAST_FM =
cm(COMPLETE_LAST_FM_METADATA);

String WRITE_METADATA = "writeMetadata";
ActionId<RequestAction<Metadata, ActionResult>> WRITE = cm(WRITE_METADATA);
public static final String WRITE_METADATA = "writeMetadata";
public static final ActionId<RequestAction<Metadata, ActionResult>> WRITE = cm(WRITE_METADATA);

String EXPORT_METADATA = "exportMetadata";
ActionId<RequestAction<ExportPackage, ActionResult>> EXPORT = cm(EXPORT_METADATA);
public static final String EXPORT_METADATA = "exportMetadata";
public static final ActionId<RequestAction<ExportPackage, ActionResult>> EXPORT =
cm(EXPORT_METADATA);

String COMPLETE_FORMATTER_METADATA = "completeFormatterMetadata";
ActionId<RequestAction<Metadata, ActionResult>> COMPLETE_FORMATTER =
public static final String COMPLETE_FORMATTER_METADATA = "completeFormatterMetadata";
public static final ActionId<RequestAction<Metadata, ActionResult>> COMPLETE_FORMATTER =
cm(COMPLETE_FORMATTER_METADATA);

String COMPLETE_DEFAULT_METADATA = "completeDefaultMetadata";
ActionId<RequestAction<List<Metadata>, ActionResult>> COMPLETE_DEFAULT =
public static final String COMPLETE_DEFAULT_METADATA = "completeDefaultMetadata";
public static final ActionId<RequestAction<List<Metadata>, ActionResult>> COMPLETE_DEFAULT =
cm(COMPLETE_DEFAULT_METADATA);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void setup() {
@RequestMethod(Actions.COMPLETE_ALBUM_METADATA)
public synchronized ActionResult completeAlbumMetadata(List<Metadata> metadataList) {
if (!musicBrainzCompleteServiceAdapter.canComplete(metadataList)) {
return ActionResult.Ready;
return ActionResult.READY;
}
try {
if (ApplicationState.cache.get(metadataList.getFirst().getAlbum()) == null) {
Expand All @@ -84,7 +84,7 @@ public synchronized ActionResult completeAlbumMetadata(List<Metadata> metadataLi
ApplicationState.cache.put(albumName, musicBrainzResponse);
log.info("MusicBrainz Response: {}", musicBrainzResponse);
if (musicBrainzResponse.getReleases().isEmpty()) {
return ActionResult.Ready;
return ActionResult.READY;
}
Album album = musicBrainzService.getAlbumByName(albumName);
log.info("MusicBrainz Album: {}", album);
Expand All @@ -102,23 +102,23 @@ public synchronized ActionResult completeAlbumMetadata(List<Metadata> metadataLi
} else {
log.error("Error getting releases: {}", result.errorBody());
}
return ActionResult.New;
return ActionResult.NEW;
}
} catch (IOException ex) {
log.error(ex.getMessage(), ex);
return ActionResult.Error;
return ActionResult.ERROR;
}
return ActionResult.Complete;
return ActionResult.COMPLETE;
}

@RequestMethod(Actions.COMPLETE_LAST_FM_METADATA)
public ActionResult completeLastFmMetadata(List<Metadata> metadataList) {
log.info("trying to complete using LastFM service");
if (!lastFMCompleteServiceAdapter.canComplete(metadataList)) {
return ActionResult.Ready;
return ActionResult.READY;
}
metadataList.forEach(lastfmService::completeLastFM);
return ActionResult.New;
return ActionResult.NEW;
}

@RequestMethod(Actions.WRITE_METADATA)
Expand All @@ -144,10 +144,10 @@ public synchronized ActionResult completeAlbum(Metadata metadata) {
metadataWriter.writeCoverArt(coverArtNew.getImage());
metadata.setCoverArt(coverArtNew.getImage());
}
return ActionResult.Updated;
return ActionResult.UPDATED;
} catch (BusinessException bse) {
log.error(bse.getMessage(), bse);
return ActionResult.Error;
return ActionResult.ERROR;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@

import com.josdem.jmetadata.action.ActionResult;
import com.josdem.jmetadata.action.Actions;
import com.josdem.jmetadata.exception.MetadataException;
import com.josdem.jmetadata.model.Metadata;
import com.josdem.jmetadata.service.DefaultService;
import java.io.IOException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.asmatron.messengine.annotations.RequestMethod;
import org.jaudiotagger.audio.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.tag.TagException;
import org.springframework.stereotype.Controller;

@Controller
Expand All @@ -37,16 +32,11 @@ public class DefaultController {
private final DefaultService defaultService;

@RequestMethod(Actions.COMPLETE_DEFAULT_METADATA)
public synchronized ActionResult complete(List<Metadata> metadatas)
throws IOException,
CannotReadException,
TagException,
ReadOnlyFileException,
MetadataException {
public synchronized ActionResult complete(List<Metadata> metadatas) {
if (defaultService.isCompletable(metadatas)) {
defaultService.complete(metadatas);
return ActionResult.New;
return ActionResult.NEW;
}
return ActionResult.Ready;
return ActionResult.READY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ActionResult sendMetadata(ExportPackage exportPackage)
return exporterHelper.export(exportPackage);
} catch (IOException ioe) {
log.error(ioe.getMessage(), ioe);
return ActionResult.Error;
return ActionResult.ERROR;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public synchronized ActionResult format(Metadata metadata) {
formatterService.isAnalyzable(metadata);
Boolean formatted = formatterService.wasFormatted(metadata);
Boolean capitalized = formatterService.wasCamelized(metadata);
return formatted || capitalized ? ActionResult.New : ActionResult.Ready;
return formatted || capitalized ? ActionResult.NEW : ActionResult.READY;
}
}
Loading
Loading