Last active
July 8, 2021 13:07
-
-
Save groupdocs-cloud-gists/69f9d2423eff85bcf955086d8fc33655 to your computer and use it in GitHub Desktop.
Extract Metadata of MP3 Files using REST API in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Extract Metadata of MP3 Files using REST API in Java | |
1. Extract Metadata of MP3 Files using REST API in Java | |
2. Metadata Extraction by Matching Exact Phrase using Java | |
3. Metadata Extraction by Regular Expression using Java | |
4. Extract Metadata by Property Name using Java | |
5. Extract Metadata by Property Value using Java |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String clientId = "da0c487d-c1c0-45ae-b7bf-43eaf53c5ad5"; | |
String clientSecret = "479db2b01dcb93a3d4d20efb16dea971"; | |
String myStorage = ""; | |
Configuration configuration = new Configuration(clientId, clientSecret); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// initialize api | |
MetadataApi apiInstance = new MetadataApi(configuration); | |
// create match option | |
MatchOptions matchOptions = new MatchOptions(); | |
matchOptions.setExactPhrase(true); | |
// create name option | |
NameOptions nameOptions = new NameOptions(); | |
nameOptions.setValue("MimeType"); | |
nameOptions.setMatchOptions(matchOptions); | |
// define search criteria | |
SearchCriteria searchCriteria = new SearchCriteria(); | |
searchCriteria.setNameOptions(nameOptions); | |
// define extract options | |
ExtractOptions options = new ExtractOptions(); | |
options.setSearchCriteria(searchCriteria); | |
// provide input file | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("sample.mp3"); | |
options.setFileInfo(fileInfo); | |
// create extract request | |
ExtractRequest request = new ExtractRequest(options); | |
ExtractResult response = apiInstance.extract(request); | |
// show results | |
for (MetadataProperty entry : response.getProperties()) { | |
System.out.println(entry.getName() + ": " + entry.getValue()); | |
if (entry.getTags() == null) | |
continue; | |
for (Tag tagItem : entry.getTags()) { | |
System.out.println( | |
"Tag for property: name - " + tagItem.getName() + ", category - " + tagItem.getCategory()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// initialize api | |
MetadataApi apiInstance = new MetadataApi(configuration); | |
// create name option | |
NameOptions nameOptions = new NameOptions(); | |
nameOptions.setValue("Artist"); | |
// define search criteria | |
SearchCriteria searchCriteria = new SearchCriteria(); | |
searchCriteria.setNameOptions(nameOptions); | |
// provide input file | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("sample.mp3"); | |
// define extract options | |
ExtractOptions options = new ExtractOptions(); | |
options.setSearchCriteria(searchCriteria); | |
options.setFileInfo(fileInfo); | |
// create extract request | |
ExtractRequest request = new ExtractRequest(options); | |
ExtractResult response = apiInstance.extract(request); | |
for (MetadataProperty entry : response.getProperties()) { | |
System.out.println(entry.getName() + ": " + entry.getValue()); | |
if (entry.getTags() == null) | |
continue; | |
for (Tag tagItem : entry.getTags()) { | |
System.out.println( | |
"Tag for property: name - " + tagItem.getName() + ", category - " + tagItem.getCategory()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// initialize api | |
MetadataApi apiInstance = new MetadataApi(configuration); | |
// create value options | |
ValueOptions valueOptions = new ValueOptions(); | |
valueOptions.setValue("Impact Moderato"); | |
valueOptions.setType("string"); | |
// define search criteria | |
SearchCriteria searchCriteria = new SearchCriteria(); | |
searchCriteria.setValueOptions(valueOptions); | |
// provide input file | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("sample.mp3"); | |
// define extract options | |
ExtractOptions options = new ExtractOptions(); | |
options.setSearchCriteria(searchCriteria); | |
options.setFileInfo(fileInfo); | |
// create extract request | |
ExtractRequest request = new ExtractRequest(options); | |
ExtractResult response = apiInstance.extract(request); | |
for (MetadataProperty entry : response.getProperties()) { | |
System.out.println(entry.getName() + ": " + entry.getValue()); | |
if (entry.getTags() == null) | |
continue; | |
for (Tag tagItem : entry.getTags()) { | |
System.out.println( | |
"Tag for property: name - " + tagItem.getName() + ", category - " + tagItem.getCategory()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// initialize api | |
MetadataApi apiInstance = new MetadataApi(configuration); | |
// create match option | |
MatchOptions matchOptions = new MatchOptions(); | |
matchOptions.setIsRegex(true); | |
// create name option | |
NameOptions nameOptions = new NameOptions(); | |
nameOptions.setValue("^Co.*"); | |
nameOptions.setMatchOptions(matchOptions); | |
// define search criteria | |
SearchCriteria searchCriteria = new SearchCriteria(); | |
searchCriteria.setNameOptions(nameOptions); | |
// define extract options | |
ExtractOptions options = new ExtractOptions(); | |
options.setSearchCriteria(searchCriteria); | |
// provide input file | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("sample.mp3"); | |
options.setFileInfo(fileInfo); | |
// create extract request | |
ExtractRequest request = new ExtractRequest(options); | |
ExtractResult response = apiInstance.extract(request); | |
for (MetadataProperty entry : response.getProperties()) { | |
System.out.println(entry.getName() + ": " + entry.getValue()); | |
if (entry.getTags() == null) | |
continue; | |
for (Tag tagItem : entry.getTags()) { | |
System.out.println( | |
"Tag for property: name - " + tagItem.getName() + ", category - " + tagItem.getCategory()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// initialize api | |
MetadataApi apiInstance = new MetadataApi(configuration); | |
// define extract options | |
ExtractOptions options = new ExtractOptions(); | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("sample.mp3"); | |
options.setFileInfo(fileInfo); | |
// create extract request | |
ExtractRequest request = new ExtractRequest(options); | |
ExtractResult response = apiInstance.extract(request); | |
// show results | |
for (MetadataPackage metaPackage : response.getMetadataTree().getInnerPackages()) { | |
for(MetadataProperty entry : metaPackage.getPackageProperties()) { | |
System.out.println(entry.getName() + ": " + entry.getValue()); | |
if (entry.getTags() == null) | |
continue; | |
for (Tag tagItem : entry.getTags()) { | |
System.out.println( | |
"Tag for property: name - " + tagItem.getName() + ", category - " + tagItem.getCategory()); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api initialization | |
FileApi apiInstance = new FileApi(clientId, clientSecret); | |
// input file | |
File fileStream = new File("C:\\Files\\sample.mp3"); | |
// create file upload request | |
UploadFileRequest request = new UploadFileRequest("sample.mp3", fileStream, myStorage); | |
// upload file | |
FilesUploadResult response = apiInstance.uploadFile(request); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment