# ###################################################################
# Mp3tag Tag Source for Cover Art from Discogs API (Official)
#
# Search by RELEASE ID
# 
# This file should be stored in your tag sources sources directory
# %APPDATA%\Mp3tag\data\sources
# and requires Mp3tag v2.97b or above.
#
# [2019-11-09] v1.03 CHG: changed to use double pipe symbol as search-by delimiter.
# [2019-09-09] v1.02 CHG: added descriptive syntax for SearchBy parameter.
# [2017-06-30] v1.01 CHG: added fallback detection of secondary images if no primary image exists
# [2017-06-26] v1.00
#
# ###################################################################

[Name]=Discogs.com
[BasedOn]=www.discogs.com
[PreviewUrl]=http://www.discogs.com/release/%s
[AlbumUrl]=https://api.discogs.com/releases/%s
[WordSeparator]=%20
[SearchBy]=Discogs ID||$if2(%DISCOGS_RELEASE_ID%,$if2(%DISCOGS_RELEASE_ID%,$if2(%DISCOGSID%,%DISCOGS-ID%)))||%s
[UserAgent]=1
[Encoding]=url-utf-8

[ParserScriptIndex]=...
#
[ParserScriptAlbum]=...
# ###################################################################
#					A  L  B  U  M
# ###################################################################
json "ON"

json_foreach "images"
	json_select "type"
	if "primary"
		ifnotoutput "TMP_PRIMARY"
			outputto "TMP_PRIMARY"
			json_select "uri"
			say "http://cache.mp3tag.de/coxy"
			sayregexp "(?<=\.com).*"
		endif
	endif
	if "secondary"
		ifnotoutput "TMP_SECONDARY"
			outputto "TMP_SECONDARY"
			json_select "uri"
			say "http://cache.mp3tag.de/coxy"
			sayregexp "(?<=\.com).*"
		endif
	endif
json_foreach_end

outputto "coverurl"
ifoutput "TMP_SECONDARY"
	set "coverurl"
	sayoutput "TMP_SECONDARY"
	set "TMP_SECONDARY"
endif
ifoutput "TMP_PRIMARY"
	set "coverurl"
	sayoutput "TMP_PRIMARY"
	set "TMP_PRIMARY"
endif