Package com.tagtraum.ubermusic.discogs
Class Discogs
- java.lang.Object
-
- com.tagtraum.core.WebService
-
- com.tagtraum.ubermusic.discogs.Discogs
-
- All Implemented Interfaces:
UberMusic
public class Discogs extends WebService implements UberMusic
Rudimentary implementation for the Discogs API.- Author:
- Hendrik Schreiber
- See Also:
- Discogs API
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDiscogs.Resource
-
Field Summary
-
Fields inherited from class com.tagtraum.core.WebService
HTTP_METHOD_GET, HTTP_METHOD_POST, HTTP_METHOD_PUT
-
-
Constructor Summary
Constructors Constructor Description Discogs()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description URLcreateReleaseSearchURL(AudioSong song)Creates a URL that resembles a release search action on the Discogs website.static URLcreateWebURL(String uri)ArtistgetArtist(long id)Looks up an artist by id.DiscogsOfflinegetDiscogsOffline()DiscogsReleasegetMaster(long id)Looks up a master by id.DiscogsReleasegetRelease(long id)Looks up a release by id.protected voidhandleStatusCode(HttpURLConnection httpURLConnection, int statusCode)Handles standard responses to status codes.List<AudioSong>lookup(AudioSong song)Looks up metadata for a song.static voidmain(String[] args)protected URLConnectionopenConnection(URL url)Opens URLConnection and logs errors.List<Artist>searchArtist(String artistName)Searches Discogs for artist data.List<Artist>searchArtist(String artistName, int page)Searches Discogs for artist data.List<DiscogsRelease>searchRelease(String releaseName)Searches Discogs for release data.List<DiscogsRelease>searchRelease(String releaseName, int page)Searches Discogs for release data.voidsetDiscogsOffline(DiscogsOffline discogsOffline)static StringstripIndex(String name)Strip things like "(2)" from "Oasis (2)".-
Methods inherited from class com.tagtraum.core.WebService
cacheResource, clearCache, getCache, getConnectTimeOut, getDomFactory, getJSONArray, getJSONArray, getJSONObject, getJSONObject, getJSONObjectWithPayload, getMaxAge, getReadTimeOut, getRequestDelay, getSSLSocketFactory, getUserAgent, getXmlDocument, getXmlObject, isAcceptGzipContentEncoding, openConnection, openInputStream, readURL, setAcceptGzipContentEncoding, setCache, setConnectTimeOut, setDomFactory, setMaxAge, setNextAllowedConnection, setReadTimeOut, setRequestDelay, setSSLSocketFactory, setUserAgent, toParameterString, useCacheOnly, waitForTurn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.tagtraum.ubermusic.UberMusic
getArtists, getSimilarArtists, lookup, lookup
-
-
-
-
Method Detail
-
stripIndex
public static String stripIndex(String name)
Strip things like "(2)" from "Oasis (2)".- Parameters:
name- name- Returns:
- stripped name
-
getDiscogsOffline
public DiscogsOffline getDiscogsOffline()
-
setDiscogsOffline
public void setDiscogsOffline(DiscogsOffline discogsOffline)
-
createReleaseSearchURL
public URL createReleaseSearchURL(AudioSong song)
Creates a URL that resembles a release search action on the Discogs website.
This method does not use the open API and therefore the URL may become invalid due to changes on the Discogs website we can't control.
- Parameters:
song- song to search for- Returns:
- URL searching for the song
- See Also:
OperatingSystem.openWithExternalApplication(java.net.URL)
-
lookup
public List<AudioSong> lookup(AudioSong song) throws IOException
Description copied from interface:UberMusicLooks up metadata for a song.- Specified by:
lookupin interfaceUberMusic- Parameters:
song- song (query by example)- Returns:
- reference songs, empty list, if the metadata is unavailable
- Throws:
IOException- IOException
-
getRelease
public DiscogsRelease getRelease(long id) throws IOException
Looks up a release by id.- Parameters:
id- id- Returns:
- release or null if not found
- Throws:
IOException
-
getMaster
public DiscogsRelease getMaster(long id) throws IOException
Looks up a master by id.- Parameters:
id- id- Returns:
- release or null if not found
- Throws:
IOException
-
getArtist
public Artist getArtist(long id) throws IOException
Looks up an artist by id.- Parameters:
id- artist id- Returns:
- artist or null if not found
- Throws:
IOException
-
searchRelease
public List<DiscogsRelease> searchRelease(String releaseName) throws IOException
Searches Discogs for release data.- Parameters:
releaseName- album name- Returns:
- an incomplete Release object - only name and id may be usable
- Throws:
IOException
-
searchRelease
public List<DiscogsRelease> searchRelease(String releaseName, int page) throws IOException
Searches Discogs for release data.- Parameters:
releaseName- album namepage- result page (one page is roughly 20 entries long)- Returns:
- an incomplete Release object - only name and id may be usable
- Throws:
IOException
-
searchArtist
public List<Artist> searchArtist(String artistName) throws IOException, SAXException, ParserConfigurationException
Searches Discogs for artist data.- Parameters:
artistName- the artist's name- Returns:
- an incomplete Artist object - only name and id may be usable
- Throws:
IOExceptionSAXExceptionParserConfigurationException
-
searchArtist
public List<Artist> searchArtist(String artistName, int page) throws IOException
Searches Discogs for artist data.- Parameters:
artistName- the artist's namepage- result page (one page is roughly 20 entries long)- Returns:
- an incomplete Artist object - only name and id may be usable
- Throws:
IOException
-
openConnection
protected URLConnection openConnection(URL url) throws IOException
Description copied from class:WebServiceOpens URLConnection and logs errors.- Overrides:
openConnectionin classWebService- Parameters:
url- URL to connect to- Returns:
- opened URL connection
- Throws:
IOException- See Also:
WebService.openConnection(URL, String, Map, InputStream)
-
handleStatusCode
protected void handleStatusCode(HttpURLConnection httpURLConnection, int statusCode) throws IOException
Description copied from class:WebServiceHandles standard responses to status codes.- Overrides:
handleStatusCodein classWebService- Parameters:
httpURLConnection- http url connectionstatusCode- status code- Throws:
IOException
-
main
public static void main(String[] args)
-
-