I was feeling left out so I decided to make a small contribution. I added an image size description to Alex's discogs boo script. It seems all art from that site is high quality, so I didn't write in an image size filter. Also I couldn't figure out the fancy image overlay like the Amazon script, so it's just in the title....baby steps. The discogs script was very different from Amazon, so I couldn't modify the overlay code.
PS - I'm no programmer at all, so each new piece of fb2k that I try out I'm learning the coding from scratch. So you'll have to forgive my amateur results
namespace CoverSources
import System
import System.Text
import System.Text.RegularExpressions
import util
class Discogs:
static SourceName as string:
get: return "Discogs"
static SourceVersion as decimal:
get: return 0.1
static def GetThumbs(coverart,artist,album):
query as string = artist + " " + album
query.Replace(' ','+')
obidResults = GetPage(String.Format("http://www.discogs.com/search?type=all&q={0}", EncodeUrl(query)))
//Get obids
obidRegex = Regex("<a href=\"/release/(?<obid>\\d+)\"><span[^>]+>[^-]+- (?:</?em>|(?<name>[^<-]+))+</span>", RegexOptions.Multiline)
obidMatches = obidRegex.Matches(obidResults)
coverart.SetCountEstimate(obidMatches.Count) //Probably more than this, as some releases might have multiple images
for obidMatch as Match in obidMatches:
//Construct the release name by joining up all the captures of the "name" group
releaseNameBuilder = StringBuilder()
for namePart in obidMatch.Groups["name"].Captures:
releaseNameBuilder.Append(namePart)
releaseName = releaseNameBuilder.ToString()
//Get the image results
imageResults = GetPage(String.Format("http://www.discogs.com/viewimages?what=R&obid={0}&showpending=1", obidMatch.Groups["obid"].Value))
imageRegex = Regex("<img src=\"(?<url>http://www\\.discogs\\.com/image/R-\\d+-\\d+.jpe?g)\" width=\"(?<width>\\d+)\" height=\"(?<height>\\d+)\"")
imageMatches = imageRegex.Matches(imageResults)
for imageMatch as Match in imageMatches:
imgwide = imageMatch.Groups["width"].Value
imghigh = imageMatch.Groups["height"].Value
label = System.String.Format("{0} ({1} x {2})", releaseName, imgwide, imghigh)
coverart.AddThumb(imageMatch.Groups["url"].Value, label, Int32.Parse(imageMatch.Groups["width"].Value), Int32.Parse(imageMatch.Groups["height"].Value), imageMatch.Groups["url"].Value)
static def GetResult(param):
return param
EDIT:
I figured out the image overlay for discogs. Here's the updated script.
namespace CoverSources
import System
import System.Xml
import System.Drawing
import System.Text
import System.Text.RegularExpressions
import util
class Discogs:
static ThumbSize = Size(150, 150)
static SourceName as string:
get: return "Discogs"
static SourceVersion as decimal:
get: return 0.1
static def GetThumbs(coverart,artist,album):
query as string = artist + " " + album
query.Replace(' ','+')
obidResults = GetPage(String.Format("http://www.discogs.com/search?type=all&q={0}", EncodeUrl(query)))
//Get obids
obidRegex = Regex("<a href=\"/release/(?<obid>\\d+)\"><span[^>]+>[^-]+- (?:</?em>|(?<name>[^<-]+))+</span>", RegexOptions.Multiline)
obidMatches = obidRegex.Matches(obidResults)
coverart.SetCountEstimate(obidMatches.Count) //Probably more than this, as some releases might have multiple images
for obidMatch as Match in obidMatches:
//Construct the release name by joining up all the captures of the "name" group
releaseNameBuilder = StringBuilder()
for namePart in obidMatch.Groups["name"].Captures:
releaseNameBuilder.Append(namePart)
releaseName = releaseNameBuilder.ToString()
//Get the image results
imageResults = GetPage(String.Format("http://www.discogs.com/viewimages?what=R&obid={0}&showpending=1", obidMatch.Groups["obid"].Value))
imageRegex = Regex("<img src=\"(?<url>http://www\\.discogs\\.com/image/R-\\d+-\\d+.jpe?g)\" width=\"(?<width>\\d+)\" height=\"(?<height>\\d+)\"")
imageMatches = imageRegex.Matches(imageResults)
for imageMatch as Match in imageMatches:
large = System.Drawing.Bitmap.FromStream(GetPageStream(imageMatch.Groups["url"].Value))
caption = System.String.Format("{0} x {1}", large.Width, large.Height)
thumb = Bitmap(large, ThumbSize)
large.Dispose()
g = Graphics.FromImage(thumb)
f = Font(SystemFonts.DefaultFont, FontStyle.Bold)
g.DrawString(caption, f, Brushes.White, 1,1 )
g.DrawString(caption, f, Brushes.Black, 0,0 )
f.Dispose()
g.Dispose()
coverart.AddThumb(thumb, releaseName, Int32.Parse(imageMatch.Groups["width"].Value), Int32.Parse(imageMatch.Groups["height"].Value), imageMatch.Groups["url"].Value)
static def GetResult(param):
return param