import NB from 'nodebrainz' ; import CoverArtArchive from './CoverArtArchive' ; import { CoverArtArchiveResult } from './CoverArtArchive' ; import { MusicbrainzArtistResponse , MusicbrainzReleaseGroupResponse , MusicbrainzTrackResponse , MusicbrainzArtist , MusicbrainzReleaseGroup , MusicbrainzRelease } from './Musicbrainz.types' ; const nb = new NB ( { userAgent : 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0' } ) ; const artistSearch = ( terms ) : Promise < MusicbrainzArtistResponse > => new Promise ( ( resolve , reject ) => { nb . search ( 'artist' , { artist : terms } , ( err , response ) => { err ? reject ( err ) : resolve ( response ) ; } ) ; } ) ; const releaseSearch = ( terms ) : Promise < MusicbrainzReleaseGroupResponse > => new Promise ( ( resolve , reject ) => { nb . search ( 'release-group' , { release : terms } , ( err , response ) => { err ? reject ( err ) : resolve ( response ) ; } ) ; } ) ; const trackSearch = ( terms ) : Promise < MusicbrainzTrackResponse > => new Promise ( ( resolve , reject ) => { nb . search ( 'work' , { work : terms } , ( err , response ) => { err ? reject ( err ) : resolve ( response ) ; } ) ; } ) ; const getCoverForReleaseGroup = ( releaseGroupId ) : Promise < CoverArtArchiveResult > => CoverArtArchive . getCoverForReleaseGroup ( releaseGroupId ) ; const getCoverForRelease = ( releaseId ) : Promise < CoverArtArchiveResult > => CoverArtArchive . getCoverForRelease ( releaseId ) ; const getArtist = ( id ) : Promise < MusicbrainzArtist > => new Promise ( ( resolve , reject ) => { nb . artist ( id , { } , ( err , response ) => { err ? reject ( err ) : resolve ( response ) ; } ) ; } ) ; const getArtistReleases = ( id ) : Promise < MusicbrainzArtist > => new Promise ( ( resolve , reject ) => { nb . artist ( id , { inc : 'releases+release-groups' } , ( err , response ) => { err ? reject ( err ) : resolve ( response ) ; } ) ; } ) ; const getReleaseGroupDetails = ( releaseGroupId ) : Promise < MusicbrainzReleaseGroup > => new Promise ( ( resolve , reject ) => { nb . releaseGroup ( releaseGroupId , { inc : 'releases' } , ( err , response ) => { err ? reject ( err ) : resolve ( response ) ; } ) ; } ) ; const getReleaseDetails = ( releaseId ) : Promise < MusicbrainzRelease > => new Promise ( ( resolve , reject ) => { nb . release ( releaseId , { inc : 'artists+recordings+genres' } , ( err , response ) => { err ? reject ( err ) : resolve ( response ) ; } ) ; } ) ; export { artistSearch , releaseSearch , trackSearch , getCoverForReleaseGroup , getCoverForRelease , getArtist , getArtistReleases , getReleaseGroupDetails , getReleaseDetails } ;