package de.christinecoenen.code.programguide.plugins.parliament;


import android.util.Log;

import org.joda.time.DateTime;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;
import org.jsoup.select.Elements;

import de.christinecoenen.code.programguide.model.Show;

class ParliamentParser {

	private static final String TAG = ParliamentParser.class.getSimpleName();

	static Show parse(String xml) {
		Document document = Jsoup.parse(xml, "", Parser.xmlParser());
		Elements showNodes = document.select("sendung");

		for (Element show : showNodes) {
			// is it the right show?
			String startUnix = show.select("anfangUnix").text();
			String endUnix = show.select("endeUnix").text();
			DateTime start = new DateTime(Long.parseLong(startUnix) * 1000);
			DateTime end = new DateTime(Long.parseLong(endUnix) * 1000);
			Log.d(TAG, start + " - " + end);

			if (start.isBeforeNow() && end.isAfterNow()) {
				return parseShow(show, start, end);
			}
		}

		// may happen in the time between shows
		return Show.getIntermission();
	}

	private static Show parseShow(Element showElement, DateTime start, DateTime end) {
		String title = showElement.select("langtitel").text();

		Show show = new Show();
		show.setTitle(title);
		show.setStartTime(start);
		show.setEndTime(end);

		return show;
	}
}

@@ -64,34 +64,8 @@
 ;%0A%0A%0A
-import android.util.Log;%0A%0A
 impo
@@ -330,16 +330,45 @@
 rser %7B%0A%0A
+%09@SuppressWarnings(%22unused%22)%0A
 %09private
@@ -890,44 +890,8 @@
 00);
-%0A%09%09%09Log.d(TAG, start + %22 - %22 + end);
 %0A%0A%09%09
@@ -1207,16 +1207,261 @@
 .text();
+%0A%09%09String subtitle;%0A%0A%09%09Element liveElement = showElement.select(%22live%22).first();%0A%09%09if (liveElement.hasText()) %7B%0A%09%09%09subtitle = liveElement.text();%0A%09%09%7D else %7B%0A%09%09%09subtitle = %22Aufzeichnung vom %22 + showElement.select(%22aufzeichnungsdatum%22).text();%0A%09%09%7D
 %0A%0A%09%09Show
@@ -1504,16 +1504,46 @@
 title);%0A
+%09%09show.setSubtitle(subtitle);%0A
 %09%09show.s

Add subtitle to parlamentsfernsehen