package com.todoist.mediaparser.mediaparser;

import com.todoist.mediaparser.util.MediaType;

import java.util.regex.Pattern;

public class SlideShareParser extends BaseOEmbedMediaParser {
	private static Pattern sMatchingPattern;

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

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

	@Override
	protected Pattern getMatchingPattern() {
		if(sMatchingPattern == null) {
			sMatchingPattern = Pattern.compile(
					"https?://(?:www\\.)?slideshare\\.net/[\\w\\-]+/[\\w\\-]+",
					Pattern.CASE_INSENSITIVE
			);
		}
		return sMatchingPattern;
	}

	@Override
	protected String createThumbnailUrl(int smallestSide) {
		// The "thumbnail" value doesn't include the protocol, it starts with "//".
		String thumbnailUrl = super.createThumbnailUrl(smallestSide);
		return thumbnailUrl != null ? "http:" + thumbnailUrl : null;
	}

	@Override
	protected String getOEmbedUrlTemplate() {
		return "http://www.slideshare.net/api/oembed/2?url=%s&format=json";
	}

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

@@ -54,44 +54,160 @@
 com.
-todoist.mediaparser.util.MediaType;%0A
+fasterxml.jackson.core.JsonParser;%0Aimport com.todoist.mediaparser.util.MediaType;%0Aimport com.todoist.mediaparser.util.Size;%0A%0Aimport java.io.IOException;
 %0Aimp
@@ -339,16 +339,56 @@
 Pattern;
+%0A%09private static Size%5B%5D sAvailableSizes;
 %0A%0A%09Slide
@@ -849,209 +849,1420 @@
 %7B%0A%09%09
-// The %22thumbnail%22 value doesn't include the protocol, it starts with %22//%22.%0A%09%09String thumbnailUrl = super.createThumbnailUrl(smallestSide);%0A%09%09return thumbnailUrl != null ? %22http:%22 + thumbnailUrl : null
+String thumbnailUrl = super.createThumbnailUrl(smallestSide);%0A%09%09if(thumbnailUrl != null) %7B%0A%09%09%09try %7B%0A%09%09%09%09JsonParser jsonParser = JSON_FACTORY.createParser(getOEmbedResponse());%0A%09%09%09%09int thumbnailWidth = Integer.valueOf(getValueForName(jsonParser, %22thumbnail_width%22));%0A%09%09%09%09int thumbnailHeight = Integer.valueOf(getValueForName(jsonParser, %22thumbnail_height%22));%0A%09%09%09%09jsonParser.close();%0A%0A%09%09%09%09Size size = null;%0A%09%09%09%09if(Math.min(thumbnailWidth, thumbnailHeight) %3C smallestSide) %7B%0A%09%09%09%09%09Size%5B%5D availableSizes = getAvailableSizes();%0A%09%09%09%09%09for(Size availableSize : availableSizes) %7B%0A%09%09%09%09%09%09if(availableSize.smallestSide %3E= smallestSide) %7B%0A%09%09%09%09%09%09%09size = availableSize;%0A%09%09%09%09%09%09%09break;%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%09if(size == null)%0A%09%09%09%09%09%09size = availableSizes%5BavailableSizes.length - 1%5D;%0A%09%09%09%09%7D%0A%0A%09%09%09%09System.out.println(%22Size! %22 + size);%0A%09%09%09%09if(size != null)%0A%09%09%09%09%09thumbnailUrl = thumbnailUrl.replaceFirst(%22thumbnail%5C%5C.jpg%22, %22thumbnail-%22 + size.key + %22.jpg%22);%0A%09%09%09%7D catch(MissingValueForNameException %7C NumberFormatException e) %7B%0A%09%09%09/* Ignore. */%0A%09%09%09%7D catch(IOException e) %7B%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%0A%0A%09%09%09// The %22thumbnail%22 value doesn't include the protocol, it starts with %22//%22.%0A%09%09%09return %22http:%22 + thumbnailUrl;%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%7D%0A%0A%09private Size%5B%5D getAvailableSizes() %7B%0A%09%09if(sAvailableSizes == null) %7B%0A%09%09%09sAvailableSizes = new Size%5B%5D %7B%0A%09%09%09%09%09new Size(%223%22, 240),%0A%09%09%09%09%09new Size(%224%22, 576)%0A%09%09%09%7D;%0A%09%09%7D%0A%09%09return sAvailableSizes
 ;%0A%09%7D

Support larger thumbnails on slideshare.net