<commit_before>package de.danoeh.antennapod.core.syndication.namespace;

import android.text.TextUtils;
import android.util.Log;

import org.xml.sax.Attributes;

import java.util.concurrent.TimeUnit;

import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
import de.danoeh.antennapod.core.syndication.util.SyndTypeUtils;

/** Processes tags from the http://search.yahoo.com/mrss/ namespace. */
public class NSMedia extends Namespace {
	private static final String TAG = "NSMedia";

	public static final String NSTAG = "media";
	public static final String NSURI = "http://search.yahoo.com/mrss/";

	private static final String CONTENT = "content";
	private static final String DOWNLOAD_URL = "url";
	private static final String SIZE = "fileSize";
	private static final String MIME_TYPE = "type";
	private static final String DURATION = "duration";
	private static final String DEFAULT = "isDefault";

	@Override
	public SyndElement handleElementStart(String localName, HandlerState state,
										  Attributes attributes) {
		if (CONTENT.equals(localName)) {
			String url = attributes.getValue(DOWNLOAD_URL);
			String type = attributes.getValue(MIME_TYPE);
			String defaultStr = attributes.getValue(DEFAULT);
			boolean validType;
			boolean isDefault = false;
			if (SyndTypeUtils.enclosureTypeValid(type)) {
				validType = true;
			} else {
				type = SyndTypeUtils.getValidMimeTypeFromUrl(url);
				validType = type != null;
			}

			if (defaultStr == "true")
				isDefault = true;

			if (state.getCurrentItem() != null &&
					(state.getCurrentItem().getMedia() == null || isDefault) &&
					url != null && validType) {
				long size = 0;
				String sizeStr = attributes.getValue(SIZE);
				try {
					size = Long.parseLong(sizeStr);
				} catch (NumberFormatException e) {
					Log.e(TAG, "Size \"" + sizeStr + "\" could not be parsed.");
				}

				int durationMs = 0;
				String durationStr = attributes.getValue(DURATION);
				if (!TextUtils.isEmpty(durationStr)) {
					try {
						long duration = Long.parseLong(durationStr);
						durationMs = (int) TimeUnit.MILLISECONDS.convert(duration, TimeUnit.SECONDS);
					} catch (NumberFormatException e) {
						Log.e(TAG, "Duration \"" + durationStr + "\" could not be parsed");
					}
				}
				FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
				if (durationMs > 0) {
					media.setDuration(durationMs);
				}
				state.getCurrentItem().setMedia(media);
			}
		}
		return new SyndElement(localName, this);
	}

	@Override
	public void handleElementEnd(String localName, HandlerState state) {

	}
}
<commit_msg>Support mrss' thumbnail<commit_after>package de.danoeh.antennapod.core.syndication.namespace;

import android.text.TextUtils;
import android.util.Log;

import org.xml.sax.Attributes;

import java.util.concurrent.TimeUnit;

import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
import de.danoeh.antennapod.core.syndication.util.SyndTypeUtils;

/** Processes tags from the http://search.yahoo.com/mrss/ namespace. */
public class NSMedia extends Namespace {
	private static final String TAG = "NSMedia";

	public static final String NSTAG = "media";
	public static final String NSURI = "http://search.yahoo.com/mrss/";

	private static final String CONTENT = "content";
	private static final String DOWNLOAD_URL = "url";
	private static final String SIZE = "fileSize";
	private static final String MIME_TYPE = "type";
	private static final String DURATION = "duration";
	private static final String DEFAULT = "isDefault";

	private static final String IMAGE = "thumbnail";
	private static final String IMAGE_URL = "url";

	@Override
	public SyndElement handleElementStart(String localName, HandlerState state,
										  Attributes attributes) {
		if (CONTENT.equals(localName)) {
			String url = attributes.getValue(DOWNLOAD_URL);
			String type = attributes.getValue(MIME_TYPE);
			String defaultStr = attributes.getValue(DEFAULT);
			boolean validType;
			boolean isDefault = false;
			if (SyndTypeUtils.enclosureTypeValid(type)) {
				validType = true;
			} else {
				type = SyndTypeUtils.getValidMimeTypeFromUrl(url);
				validType = type != null;
			}

			if (defaultStr == "true")
				isDefault = true;

			if (state.getCurrentItem() != null &&
					(state.getCurrentItem().getMedia() == null || isDefault) &&
					url != null && validType) {
				long size = 0;
				String sizeStr = attributes.getValue(SIZE);
				try {
					size = Long.parseLong(sizeStr);
				} catch (NumberFormatException e) {
					Log.e(TAG, "Size \"" + sizeStr + "\" could not be parsed.");
				}

				int durationMs = 0;
				String durationStr = attributes.getValue(DURATION);
				if (!TextUtils.isEmpty(durationStr)) {
					try {
						long duration = Long.parseLong(durationStr);
						durationMs = (int) TimeUnit.MILLISECONDS.convert(duration, TimeUnit.SECONDS);
					} catch (NumberFormatException e) {
						Log.e(TAG, "Duration \"" + durationStr + "\" could not be parsed");
					}
				}
				FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
				if (durationMs > 0) {
					media.setDuration(durationMs);
				}
				state.getCurrentItem().setMedia(media);
			}
		} else if (IMAGE.equals(localName)) {
			String url = attributes.getValue(IMAGE_URL);
			if (url != null) {
				FeedImage image = new FeedImage();
				image.setDownload_url(url);

				if (state.getCurrentItem() != null) {
					image.setOwner(state.getCurrentItem());
					state.getCurrentItem().setImage(image);
				} else {
					if (state.getFeed().getImage() == null) {
						image.setOwner(state.getFeed());
						state.getFeed().setImage(image);
					}
				}
			}
		}
		return new SyndElement(localName, this);
	}

	@Override
	public void handleElementEnd(String localName, HandlerState state) {

	}
}

{'fraction_non_alphanumeric': 0.1200203424309205, 'fraction_numerical': 0.0010171215460247499, 'mean_word_length': 3.773462783171521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6723491', 'n_tokens_mistral': 2152, 'n_tokens_neox': 1799, 'n_words': 435}