I'm trying to download metadata from MusicBrainz using a 3rd party java library: musicbrainzws2-java
I'm trying to retrieve the metadata of individual songs in a specified album. I've retrieved the MBID of the album, but when I try to search for the songs in the album I get no return.
Here is my code:
public static void main (String args []) throws MBWS2Exception {
String artistName = "Imagine Dragons";
String album_id = null;
Artist artist = new Artist();
artist.search(artistName);
List<ArtistResultWs2> results = artist.getFullSearchResultList();
ArtistWs2 song = results.get(0).getArtist();
artist = new Artist();
song = artist.lookUp(song);
List<ReleaseGroupWs2> rgl = artist.getFullReleaseGroupList();
for(int i =0; i<rgl.size(); i++){
System.out.println(rgl.get(i).getTitle());
if(rgl.get(i).getTitle().equals("Night Visions")){
album_id = rgl.get(i).getId();
}
}
System.out.println("Night visions ID: " + album_id);
Release release = new Release();
release.search(album_id);
List<ReleaseResultWs2> list = release.getFullSearchResultList();
for(int i =0; i<list.size(); i++)
System.out.println(list.get(i).getEntity());
Can someone give me some pointers.
Thanks
Managed to retrieve information code is below:
public static void main (String args []) throws MBWS2Exception {
String artistName = "Imagine Dragons";
String albumName = "Night Visions";
String album_id = null;
Artist artistsearch = new Artist();
artistsearch.search(artistName);
List<ArtistResultWs2> result = artistsearch.getFullSearchResultList();
ArtistWs2 artist = new ArtistWs2();
for(ArtistResultWs2 x : result){
if(x.getArtist().toString().equals(artistName)){
artist = x.getArtist();
break;
}
}
artistsearch = new Artist();
artistsearch.lookUp(artist);
List<ReleaseGroupWs2> release_groups = artistsearch.getFullReleaseGroupList();
ReleaseGroupWs2 releasegroup = null;
for(ReleaseGroupWs2 x : release_groups)
if(x.getTitle().equals(albumName)){
releasegroup = x;
}
ReleaseGroup releasegroupsearch = new ReleaseGroup();
releasegroupsearch.lookUp(releasegroup);
List<ReleaseWs2> releases = releasegroupsearch.getFullReleaseList();
ReleaseWs2 album = releases.get(0);
Release releaselist = new Release();
releaselist.lookUp(album);
MediumListWs2 releaselist1 = releaselist.getComplete(album).getMediumList();
List<TrackWs2> tracklist = releaselist1.getCompleteTrackList();
System.out.println("artist: " + artist);
System.out.println("album: " + album);
System.out.println("title: " + tracklist.get(0).getRecording().getTitle());
System.out.println("genre: " + tracklist.get(0).getRecording().getTags().get(0).getName());
System.out.println("track: " + tracklist.get(0).getPosition());
System.out.println("year: " + album.getYear());
System.out.println("disc no.: " + releaselist1.getMedia().get(0));
System.out.println("label: " + album.getLabelInfoString());
System.out.println("artist sort : " + tracklist.get(0).getRecording().getArtistCreditString());
System.out.println("comment: " + tracklist.get(0).getRecording().getDisambiguation());
}
}
Related
I debugging my application then I tried clicking twice and fast on the pretty dialog button and it print twice I expect that even I clicked twice it will not print twice.
I tried error handler codes but it was not working.
prettyDialog.addButton("YES",
R.color.navy_blue,
R.color.gold_yellow,
new PrettyDialogCallback() {
#Override
public void onClick() {
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
raw_serial = String.valueOf(Build.SERIAL);
serial_final = raw_serial.substring(raw_serial.length() - 7);
nf = new DecimalFormat("000000");
DateFormat dateFormat = new SimpleDateFormat("MMddyyyy");
Date date = new Date();
ticket_date = dateFormat.format(date).toString();
DateFormat datetimeformat = new SimpleDateFormat("HHmmss");
Date time = new Date();
ticket_time = datetimeformat.format(time).toString();
transaction_no = serial_final + ticket_date + ticket_time + nf.format(setting_last_transaction_no);
trace_no = merchant_code + serial_final + ticket_date + ticket_time + nf.format(ref_trace_no);
print_card_no = Cardno.substring(Cardno.length() - 4);
String print_balance;
print_balance = "P" + String.valueOf(Balance);
int balancespace = 0;
int balancelength = 0;
balancelength = print_balance.length();
balancespace = 13 - balancelength;
for (int j = 0; j < balancespace; j++) {
print_balance = " " + print_balance;
}
int print = PrinterInterface.open();
Log.e("print", String.valueOf(print));
int querystatus = PrinterInterface.queryStatus();
Log.e("querystatus", String.valueOf(querystatus));
DateFormat dateformatforprint = new SimpleDateFormat("MMM.dd,yyyy");
Date dateformatprint = new Date();
String datetoprint = dateformatforprint.format(dateformatprint).toString();
DateFormat timeformattoprint = new SimpleDateFormat("HH:mm");
Date timeformat = new Date();
String timetoprint = timeformattoprint.format(timeformat).toString();
String finalStation = "";
Log.e("asdasd", "asdasd");
if (print >= 0) {
byte[] arryTitle = null;
byte[] arryTrx = null;
byte[] arrySubtitle = null;
byte[] arryBody1 = null;
byte[] arryspace1 = null;
byte[] arryFooter = null;
//test
try {
arryTitle = ("\n" + "TRIPKO" + "\n" + "\n").getBytes("UTF-8");
arryTrx = ("TRX: " + transaction_no + "\n" +
trace_no + "\n").getBytes("UTF-8");
arrySubtitle = ("Date & Time : " + datetoprint + " " + timetoprint + "\n" +
"Merchant Name: " + subcompany_name.toUpperCase() + "\n" +
"Branch : " + terminal_name.toUpperCase() + "\n" +
"-------------------------------" + "\n" +
"\n").getBytes("UTF-8");
arryBody1 = ("Card No. : " + " **** **** **** " + print_card_no + "\n" +
"Trans Type : " + " " + type_name.toUpperCase() + "\n" +
"Current Balance : " + print_balance + "\n" +
"-------------------------------" + "\n" +
"\n").getBytes("UTF-8");
arryFooter = ("Customer Service" + "\n"
+ "Hotline#: TRIPKO(678-1234)" + "\n" +
"\n").getBytes("UTF-8");
arryspace1 = "\n".getBytes("UTF-8");
} catch (Throwable e) {
e.printStackTrace();
}
begin();
if (querystatus == 1) {
writeLineBreak(20);
write(arryspace1);
alignment(1);
Fontsize(16);
boldFont(2);
doublewidth();
write(arryTitle);
backtonormal();
nextline();
Fontsize(0);
write(arryTrx);
alignment(0);
write(arrySubtitle);
write(arryBody1);
alignment(1);
write(arryFooter);
write(arryspace1);
write(arryspace1);
write(arryspace1);
write(arryspace1);
insertData(company_id,
subcompany_id,
terminal_id,
setting_control_no,
Cardno,
Balance,
transaction_no,
trace_no,
device_serial);
setting_last_transaction_no += 1;
ref_trace_no += 1;
updateTicket(String.valueOf(setting_last_transaction_no),
String.valueOf(ref_trace_no));
DBBackup();
end();
btnCheckBalance.setEnabled(true);
btnCheckBalance.setClickable(true);
Intent intent2 = new Intent(getContext(), UpdateSendingServices.class);
getActivity().startService(intent2);
} else {
//OpenNoPaper();
}
}
PrinterInterface.close();
}
});
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
totalBalance.setText("P 0.00");
btnCheckBalance.setEnabled(true);
btnCheckBalance.setClickable(true);
}
});
prettyDialog.dismiss();
}
})
.show();
I expect that it will not print twice even I clicked the "YES" pretty dialog button.
i think you can just do a trick like this
create a count variable count=0;. In button click, validate condition such that if(count==0) show dialog and make count = 1. (with this dialog will not open second time) while dismissing dialog make count = 0 again.
I think this will work
Hope it helps.
if(count == 0){
count = 1 ;
//showdialog process
}
and right before dismiss()
......
count = 0;
prettyDialog.dismiss();
Helo, I've got this code, which query the instances in calendarcontract:
Uri uri = Uri.parse(CalendarContract.Instances.CONTENT_URI + "/" +
Long.toString(from) + "/" +
Long.toString(to));
String[] mProjection =
{
CalendarContract.Instances._ID,
CalendarContract.Instances.EVENT_ID,
CalendarContract.Instances.CALENDAR_ID,
CalendarContract.Instances.TITLE,
CalendarContract.Instances.EVENT_LOCATION,
CalendarContract.Instances.DESCRIPTION,
CalendarContract.Instances.EVENT_COLOR,
CalendarContract.Instances.DTSTART,
CalendarContract.Instances.DTEND,
CalendarContract.Instances.EVENT_TIMEZONE,
CalendarContract.Instances.EVENT_END_TIMEZONE,
CalendarContract.Instances.DURATION,
CalendarContract.Instances.ALL_DAY,
CalendarContract.Instances.RRULE,
CalendarContract.Instances.RDATE,
CalendarContract.Instances.EXDATE
};
ContentResolver cr2 = this.c.getContentResolver();
String selection2 = "( " + selection_allcalendars + " (" + CalendarContract.Instances.RRULE + " IS NOT NULL) AND (deleted != 1) AND (" + CalendarContract.Instances.ALL_DAY + " = 0))";
Cursor cur2 = cr2.query(uri, mProjection, selection2, null, CalendarContract.Instances.DTSTART + " ASC");
How can I remove double instances from query? I want to use a "GROUP BY" clause, but I don't know how to do that.
Please help me :-)
Thanks!
Edit:
I want to group by EVENT_ID, because I get multiple entries. This ist the whole code I use for recurring events:
ContentResolver cr2 = this.c.getContentResolver();
String selection2 = "( " + selection_allcalendars + " (" + CalendarContract.Instances.RRULE + " IS NOT NULL) AND (deleted != 1) AND (" + CalendarContract.Instances.ALL_DAY + " = 0))";
Cursor cur2 = cr2.query(uri, mProjection, selection2, null, CalendarContract.Instances.DTSTART + " ASC");
ArrayList<String> checkexists = new ArrayList<>();
while (cur2.moveToNext()) {
String eventid = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.EVENT_ID));
if(checkexists.contains(eventid)) {
}
else {
checkexists.add(eventid);
String rrule = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.RRULE));
TimeZone tz = TimeZone.getTimeZone("Europe/Berlin");
Long dtstart;
try {
dtstart = Long.parseLong(cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.DTSTART)));
dtstart = tz.getOffset(dtstart) + dtstart;
} catch (NumberFormatException e) {
dtstart = 0l;
}
Long dtend;
try {
dtend = dtstart + RFC2445ToMilliseconds(cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.DURATION)));
/* dtend = Long.parseLong(cur.getString(cur.getColumnIndex(CalendarContract.Events.DTEND)));
dtend = tz.getOffset(dtend) + dtend; */
} catch (NumberFormatException e) {
dtend = 0l;
}
Calendar cal4 = Calendar.getInstance();
cal4.setTimeInMillis(dtstart);
LocalDate localdate = new LocalDate(cal4.get(Calendar.YEAR), cal4.get(Calendar.MONTH) + 1, cal4.get(Calendar.DAY_OF_MONTH));
long calendar_id = Long.valueOf(cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.CALENDAR_ID)));
String id = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances._ID));
String title = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.TITLE));
String eventlocation = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.EVENT_LOCATION));
String description = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.DESCRIPTION));
String eventcolor = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.EVENT_COLOR));
String eventtimezone = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.EVENT_TIMEZONE));
String eventtimezone_end = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.EVENT_END_TIMEZONE));
String duration = cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.DURATION));
int allday = Integer.valueOf(cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.ALL_DAY)));
rrule = "RRULE:" + rrule;
long lastrecurrencetime;
if(rrule.contains("UNTIL")) {
lastrecurrencetime = RruleHelper.getUntil(rrule).getTimeInMillis();
}
else {
lastrecurrencetime = -1;
}
//System.out.println("EEE: " + title + " " + rrule);
try {
ArrayList<ReadEvent> recurrenceevents = new ArrayList<>();
for (LocalDate date : LocalDateIteratorFactory.createLocalDateIterable(rrule, localdate, true)) {
// System.out.println("GGG:" + title + " " + i);
Calendar newcal_from = Calendar.getInstance();
newcal_from.setTimeInMillis(dtstart);
newcal_from.set(Calendar.DAY_OF_MONTH, date.getDayOfMonth());
newcal_from.set(Calendar.MONTH, date.getMonthOfYear() - 1);
newcal_from.set(Calendar.YEAR, date.getYear());
long dtstart_new = newcal_from.getTimeInMillis();
long dtend_new = dtstart_new + RFC2445ToMilliseconds(cur2.getString(cur2.getColumnIndex(CalendarContract.Instances.DURATION)));
if (dtstart_new >= from && dtstart_new <= to) {
ReadEvent newreadevent = new ReadEvent(calendar_id, id, eventid, title, eventlocation, description, eventcolor, dtstart_new, dtend_new, eventtimezone, eventtimezone_end, duration, allday, rrule);
newreadevent.setFirstReccurenceTime(dtstart);
newreadevent.setLastReccurenceTime(lastrecurrencetime);
if(!checkIfAlreadyExits(readevent, newreadevent)) {
//newreadevent.setReccurenceCount(i);
readevent.add(newreadevent);
}
}
if (dtstart_new > to) {
break;
}
}
} catch (Exception e) {
}
}
}
Here I attached my code. When if stateVector contains the statename I need to check the that entire row only, not all the icd and dicd vector value. How I need to do that?
In my code its checking all vectors once the statename matched with any other or icdid it's showing it's available.
public class LCDEdits
{
#SuppressWarnings("unchecked")
public String validateICD_CPT(String cptCode, String stateName, String icdCode) throws Exception
{
/**** Variable Initialization ***/
String lcdRes = null;
StringBuffer lcdSql = null;
// String error = null;
java.sql.Connection con = null;
java.sql.PreparedStatement poStmt1 = null;
DBConfig db1 = null;
ResultSet rs = null;
JSONObject JObj = new JSONObject();
try
{
lcdSql = new StringBuffer(" SELECT cpt.hcpc_code, cpt.lcd_id, statepri.state_abbr, icd.icd10_id, ");
lcdSql.append(" dicd.icd10_id_dont FROM lcd_cpt cpt ");
lcdSql.append(" LEFT JOIN lcd_statepri statepri ON(cpt.lcd_id = statepri.lcd_id) ");
//lcdSql.append(" LEFT JOIN lcd_statesec statesec ON( cpt.lcd_id = statesec.lcd_id) ");
lcdSql.append(" LEFT JOIN lcd_icd_support icd ON( cpt.lcd_id = icd.lcd_id) ");
lcdSql.append(" LEFT JOIN lcd_icd_dont_support dicd ON( cpt.lcd_id = dicd.lcd_id) ");
lcdSql.append(" WHERE hcpc_code = ? ");
db1 = new DBConfig();
con = db1.openConn();
poStmt1 = con.prepareStatement(lcdSql.toString());
poStmt1.setString(1, cptCode);
rs = poStmt1.executeQuery();
Vector<String> stateVector = new Vector<String>();
Vector<String> icdVector = new Vector<String>();
Vector<String> dicdVector = new Vector<String>();
while(rs.next())
{
stateVector.add(rs.getString("state_abbr") );
// icdVector.add(rs.getString("icd10_id") );
// dicdVector.add(rs.getString("icd10_id_dont") );
//stateVector.add(rs.getString("sec_state_abbr") );
}
if(stateVector.contains(stateName))
{
if(icdVector.contains(icdCode))
{
// String lcd_icd = lcd_Id;
lcdRes = "CPT-Code is Available in LCD Database.";
// lcdRes1 = "As for the LCD-Code " +lcd_icd+ ", the CPT-Code " + cptCode + " is supported the Diagnosis " +icdCode+ " in the state of " +stateName+ ".";
}
else if(dicdVector.contains(icdCode))
{
lcdRes = "Medicare is not interest to pay Amount for this CPT-Code.";
// lcdRes1 = "As for the LCD-Code " +lcd_Id+ ", the CPT-Code " +cptCode+ " is not supported the Diagnosis " +icdCode+ " in the state of " +stateName+ ".";
}
else
{
lcdRes = "CPT-Code is not available in the LCD-Database.";
// lcdRes1 = "As for the LCD-Code " +lcd_Id+ ", the CPT-Code " +cptCode+ " is not applicable for the Diagnosis " +icdCode+ " in the state of " +stateName+ ".";
}
}
else
{
// String lcd_state = lcd_Id;
lcdRes = "State not matched with LCD-Code.";
// lcdRes1 = "As for the LCD-Code " +lcd_state+ ", the CPT-Code " +cptCode+ " is not applicable in the state of " +stateName+ ".";
}
JObj.put("status", "success");
JObj.put("res_msg", lcdRes);
// JObj.put("dis_msg", lcdRes1);
}
catch(Exception ex) {
ex.printStackTrace();
JObj.put("status", "failed");
}
finally {
rs.close();
poStmt1.close();
db1.closeConnection(con);
}
return JObj.toString();
}
}
First, separate the reading from the database and the processing of the data.
Vector stateVector = null;
try {
Reading data from database
} catch (the problems) {
And handle them
} finally {
close the connection
}
then check if you have some data:
if (stateVector != null {
// get the data you want, probably with a loop construct
}
I am building a tag reader for inventory purpose. Using the for loop to iterate through the tags to count/total the ids. I get an error on my return line "tagsFound cannot be resolved into a variable". How do i use the variable inside the for loop and then access it outside the loop?
public String[] getTags(AlienClass1Reader reader)throws AlienReaderException{
int coneCount = 0;
int drumCount = 0;
// Open a connection to the reader
reader.open();
// Ask the reader to read tags and print them
Tag tagList[] = reader.getTagList();
if (tagList == null) {
System.out.println("No Tags Found");
} else {
System.out.println("Tag(s) found: " + tagList.length);
for (int i=0; i<tagList.length; i++) {
Tag tag = tagList[i];
System.out.println("ID:" + tag.getTagID() +
", Discovered:" + tag.getDiscoverTime() +
", Last Seen:" + tag.getRenewTime() +
", Antenna:" + tag.getAntenna() +
", Reads:" + tag.getRenewCount()
);
//tagFound[i]= "" + tag.getTagID();
String phrase = tag.getTagID();
tagFound[i] = phrase;
String delims = "[ ]+";
String[] tokens = phrase.split(delims);
if (tokens[0].equals("0CCE") && tokens[3].equals("1001")){drumCount++;}
if (tokens[0].equals("0CCE") && tokens[3].equals("1004")){coneCount++;}
String[] tagsFound;
tagsFound[i] = tag.getTagID();
}
System.out.println("Cones= " + coneCount);
System.out.println("Drums= " + drumCount);
// Close the connection
reader.close();
return tagsFound;
}
}
public String[] getTags(AlienClass1Reader reader)throws AlienReaderException{
int coneCount = 0;
int drumCount = 0;
// Open a connection to the reader
reader.open();
// Ask the reader to read tags and print them
Tag tagList[] = reader.getTagList();
if (tagList == null) {
System.out.println("No Tags Found");
} else {
System.out.println("Tag(s) found: " + tagList.length);
String[] tagsFound = new String[tagList.length];
for (int i=0; i<tagList.length; i++) {
tagsFound = "";
Tag tag = tagList[i];
System.out.println("ID:" + tag.getTagID() +
", Discovered:" + tag.getDiscoverTime() +
", Last Seen:" + tag.getRenewTime() +
", Antenna:" + tag.getAntenna() +
", Reads:" + tag.getRenewCount()
);
//tagFound[i]= "" + tag.getTagID();
String phrase = tag.getTagID();
tagFound[i] = phrase;
String delims = "[ ]+";
String[] tokens = phrase.split(delims);
if (tokens[0].equals("0CCE") && tokens[3].equals("1001")){drumCount++;}
if (tokens[0].equals("0CCE") && tokens[3].equals("1004")){coneCount++;}
tagsFound[i] = tag.getTagID();
}
System.out.println("Cones= " + coneCount);
System.out.println("Drums= " + drumCount);
// Close the connection
reader.close();
return tagsFound;
}
}
the returned array will have empty strings in the positions where the tag does not satisfy the criteria.
I have a String = "abc model 123 abcd1862893007509396 abcd2862893007509404", if I provide space between abcd1 & number eg. abcd1 862893007509396 my code will work fine, but if there is no space like abcd1862893007509396, I will get java.lang.ArrayIndexOutOfBoundsException, please help ?:
PFB the code :
String text = "";
final String suppliedKeyword = "abc model 123 abcd1862893007509396 abcd2862893007509404";
String[] keywordarray = null;
String[] keywordarray2 = null;
String modelname = "";
String[] strIMEI = null;
if ( StringUtils.containsIgnoreCase( suppliedKeyword,"model")) {
keywordarray = suppliedKeyword.split("(?i)model");
if (StringUtils.containsIgnoreCase(keywordarray[1], "abcd")) {
keywordarray2 = keywordarray[1].split("(?i)abcd");
modelname = keywordarray2[0].trim();
if (keywordarray[1].trim().contains(" ")) {
strIMEI = keywordarray[1].split(" ");
for (int i = 0; i < strIMEI.length; i++) {
if (StringUtils.containsIgnoreCase(strIMEI[i],"abcd")) {
text = text + " " + strIMEI[i] + " "
+ strIMEI[i + 1];
System.out.println(text);
}
}
} else {
text = keywordarray2[1];
}
}
}
After looking at your code the only thing i can consider for cause of error is
if (StringUtils.containsIgnoreCase(strIMEI[i],"abcd")) {
text = text + " " + strIMEI[i] + " "
+ strIMEI[i + 1];
System.out.println(text);
}
You are trying to access strIMEI[i+1] which will throw an error if your last element in strIMEI contains "abcd".