package com.todoist.mediaparser.mediaparser;

import com.todoist.mediaparser.util.MediaType;

import java.util.regex.Pattern;

public class DeviantartParser extends BaseOEmbedMediaParserWithContent {
	private static Pattern sMatchingPattern;

	DeviantartParser(String url) {
		super(url);
	}

	@Override
	public MediaType getContentMediaType() {
		return MediaType.OTHER;
	}

	@Override
	protected Pattern getMatchingPattern() {
		if(sMatchingPattern == null) {
			sMatchingPattern = Pattern.compile(
					"https?://(?:www\\.)?" +
							"(?:[\\w-]+\\.deviantart\\.com/(?:art/|[^/]+#/d)|fav\\.me/|sta\\.sh/)" +
							"[\\w-]+/?",
					Pattern.CASE_INSENSITIVE
			);
		}
		return sMatchingPattern;
	}

	@Override
	protected String getOEmbedUrlTemplate() {
		return "http://backend.deviantart.com/oembed?url=%s&format=json";
	}

	@Override
	protected String getOEmbedContentUrlName() {
		return "url";
	}

	@Override
	protected String getOEmbedThumbnailUrlName() {
		return "thumbnail_url";
	}
}

@@ -39,16 +39,62 @@
 arser;%0A%0A
+import com.fasterxml.jackson.core.JsonParser;%0A
 import c
@@ -133,16 +133,44 @@
 aType;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -765,24 +765,667 @@
 attern;%0A%09%7D%0A%0A
+%09@Override%0A%09protected String createThumbnailUrl(int smallestSide) %7B%0A%09%09try %7B%0A%09%09%09JsonParser jsonParser = JSON_FACTORY.createParser(getOEmbedResponse());%0A%09%09%09int thumbnailWidth = Integer.valueOf(getValueForName(jsonParser, %22thumbnail_width%22));%0A%09%09%09int thumbnailHeight = Integer.valueOf(getValueForName(jsonParser, %22thumbnail_height%22));%0A%09%09%09jsonParser.close();%0A%0A%09%09%09if(Math.min(thumbnailWidth, thumbnailHeight) %3C smallestSide)%0A%09%09%09%09return createContentUrl();%0A%09%09%7D catch(MissingValueForNameException %7C NumberFormatException e) %7B%0A%09%09%09/* Ignore. */%0A%09%09%7D catch(IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09return super.createThumbnailUrl(smallestSide);%0A%09%7D%0A%0A
 %09@Override%0A%09

Support larger thumbnails on deviantart.com