3
* Copyright (C) 2008 W. Xaver
4
* W.Xaver[at]googlemail.com
5
* http://zdfmediathk.sourceforge.net/
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
package mediathek.controller.filmeLaden.suchen.sender;
22
import java.text.SimpleDateFormat;
23
import java.util.Date;
24
import java.util.Locale;
25
import mediathek.controller.filmeLaden.suchen.FilmeSuchenSender;
26
import mediathek.controller.io.GetUrl;
27
import mediathek.daten.Daten;
28
import mediathek.daten.DatenFilm;
29
import mediathek.tool.GuiFunktionen;
30
import mediathek.tool.Konstanten;
31
import mediathek.tool.Log;
32
import mediathek.tool.MVStringBuilder;
34
public class MediathekBr extends MediathekReader implements Runnable {
36
public static final String SENDER = "BR";
37
private SimpleDateFormat sdfIn = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMANY); // "date": "2013-07-06 13:00:00",
39
public MediathekBr(FilmeSuchenSender ssearch, int startPrio) {
40
super(ssearch, /* name */ SENDER, /* threads */ 2, /* urlWarten */ 500, startPrio);
45
//new Thread(new ThemaLaden()).start();
48
th = new Thread(new ThemaLaden());
49
th.setName(nameSenderMReader);
51
if (filmeSuchenSender.senderAllesLaden) {
52
th = new Thread(new ArchivLaden(1, 100));
53
th.setName(nameSenderMReader);
55
th = new Thread(new ArchivLaden(101, 200));
56
th.setName(nameSenderMReader);
58
th = new Thread(new ArchivLaden(201, 300));
59
th.setName(nameSenderMReader);
61
th = new Thread(new ArchivLaden(301, 400));
62
th.setName(nameSenderMReader);
67
private class ThemaLaden implements Runnable {
70
public synchronized void run() {
75
} catch (Exception ex) {
76
Log.fehlerMeldung(-203069877, Log.FEHLER_ART_MREADER, "MediathekBr.JsonLaden.run", ex, "");
78
meldungThreadUndFertig();
82
private class ArchivLaden implements Runnable {
86
public ArchivLaden(int aanfang, int eende) {
92
public synchronized void run() {
93
meldungAddMax(ende - anfang);
96
archivSuchen(anfang, ende);
97
} catch (Exception ex) {
98
Log.fehlerMeldung(-203069877, Log.FEHLER_ART_MREADER, "MediathekBr.JsonLaden.run", ex, "");
100
meldungThreadUndFertig();
104
private void jsonSuchen() {
105
//"date": "2013-07-13 13:00:00",
106
//"description": "Pflanzentricks - Wie erreicht eine Pflanze, was sie will?",
108
//"image": "http://mediathek-video.br.de/listra/sendungsbilder/xenius_xl.jpg",
109
//"title": "X:enius",
112
// "bitrate": 700000,
113
// "url": "http://hbbtv.b7.br.gl-systemhaus.de/b7/konks/1373715065-b7konks_nc_203101728_107154.mp4"
116
// "bitrate": 200000,
117
// "url": "http://hbbtv.b7.br.gl-systemhaus.de/b7/konks/1373715063-b7konks_nc_203101728_107153.mp4"
120
// "bitrate": 2000000,
121
// "url": "http://hbbtv.b7.br.gl-systemhaus.de/b7/konks/1373715066-b7konks_nc_203101728_107155.mp4"
123
final String URL_JSON = "http://rd.gl-systemhaus.de/br/b7/nc/jsonp/latestarchive.json";
124
final String DATE = "\"date\": \"";
125
final String DESCRIPTION = "\"description\": \"";
126
final String DURATION = "\"duration\": \"";
127
final String IMAGE = "\"image\": \"";
128
final String THEMA = "\"title\": \"";
129
final String URL__ = "\"xl\":";
130
final String URL = "\"url\": \"";
131
final String URL_KLEIN__ = "\"l\":";
132
final String URL_KLEIN = "\"url\": \"";
133
String date, datum, zeit, thema, titel, description, duration, image, url, url_klein;
135
MVStringBuilder seite1 = new MVStringBuilder(Konstanten.STRING_BUFFER_START_BUFFER);
136
GetUrl getUrl = new GetUrl(wartenSeiteLaden);
137
seite1 = getUrl.getUri(nameSenderMReader, URL_JSON, Konstanten.KODIERUNG_UTF, 3/*max Versuche*/, seite1, URL_JSON);
138
if (seite1.length() == 0) {
139
Log.fehlerMeldung(-302590789, Log.FEHLER_ART_MREADER, "MediathekBr.jsonSuchen", "Leere Seite: " + URL_JSON);
146
while (!Daten.filmeLaden.getStop() && (pos = seite1.indexOf(DATE, pos)) != -1) {
159
pos += DATE.length();
160
posStop = seite1.indexOf(DATE, pos);
162
if ((pos2 = seite1.indexOf("\"", pos1)) != -1) {
163
date = seite1.substring(pos1, pos2);
164
datum = convertDatumJson(date);
165
zeit = convertZeitJson(date);
167
description = seite1.extract(DESCRIPTION, "\"", pos, posStop);
168
final String TRENNER = " - ";
169
if (description.contains(TRENNER)) {
170
titel = description.substring(0, description.indexOf(TRENNER)).trim();
171
description = description.substring(description.indexOf(TRENNER) + TRENNER.length()).trim();
172
} else if (description.length() > 25) {
173
titel = description.substring(0, 25).trim() + "...";
178
duration = seite1.extract(DURATION, "\"", pos, posStop);
179
if (!duration.equals("")) {
181
dauer = Long.parseLong(duration) * 60;
182
} catch (Exception ex) {
183
Log.fehlerMeldung(-304973047, Log.FEHLER_ART_MREADER, "MediathekBR.jsonSuchen", ex, "duration: " + duration);
186
thema = seite1.extract(THEMA, "\"", pos, posStop);
187
image = seite1.extract(IMAGE, "\"", pos, posStop);
188
url = seite1.extract(URL__, URL, "\"", pos, posStop);
189
url_klein = seite1.extract(URL_KLEIN__, URL_KLEIN, "\"", pos, posStop);
190
if (url.isEmpty() & !url_klein.isEmpty()) {
193
} else if (url.isEmpty()) {
196
thema = GuiFunktionen.utf8(thema);
197
titel = GuiFunktionen.utf8(titel);
198
description = GuiFunktionen.utf8(description);
199
// public DatenFilm(String ssender, String tthema, String filmWebsite, String ttitel, String uurl, String datum, String zeit,
200
// long duration, String description, String thumbnailUrl, String imageUrl, String[] keywords) {
201
DatenFilm film = new DatenFilm(nameSenderMReader, thema, "http://www.br.de/mediathek/index.html", titel, url, ""/*rtmpURL*/, datum, zeit,
202
dauer, description, image, new String[]{});
203
film.addUrlKlein(url_klein, "");
205
meldung(film.arr[DatenFilm.FILM_URL_NR]);
206
} catch (Exception ex) {
207
Log.fehlerMeldung(-902483073, Log.FEHLER_ART_MREADER, "MediathekBR.jsonSuchen", ex, "");
212
private void archivSuchen(int start, int ende) {
213
// http://www.br.de/service/suche/archiv102.html?documentTypes=video&page=1&sort=date
214
final String MUSTER_ADRESSE_1 = "http://www.br.de/service/suche/archiv102.html?documentTypes=video&page=";
215
final String MUSTER_ADRESSE_2 = "&sort=date";
216
final String MUSTER_START = "<div class=\"teaser search_result\">";
217
MVStringBuilder seiteArchiv1 = new MVStringBuilder(Konstanten.STRING_BUFFER_START_BUFFER);
218
MVStringBuilder seiteArchiv2 = new MVStringBuilder(Konstanten.STRING_BUFFER_START_BUFFER);
219
GetUrl getUrl = new GetUrl(wartenSeiteLaden);
220
for (int i = start; i <= ende; ++i) {
221
if (Daten.filmeLaden.getStop()) {
224
String adresse = MUSTER_ADRESSE_1 + i + MUSTER_ADRESSE_2;
225
meldungProgress(adresse);
226
seiteArchiv1 = getUrl.getUri(nameSenderMReader, adresse, Konstanten.KODIERUNG_UTF, 2 /* versuche */, seiteArchiv1, "" /* Meldung */);
227
if (seiteArchiv1.length() == 0) {
228
Log.fehlerMeldung(-912036478, Log.FEHLER_ART_MREADER, MediathekBr.class.getName() + ".addToList_addr", "Leere Seite für URL: " + adresse);
230
int pos = 0, stop = 0;
231
String url, titel, thema, datum, beschreibung;
232
while (!Daten.filmeLaden.getStop() && (pos = seiteArchiv1.indexOf(MUSTER_START, pos)) != -1) {
233
pos += MUSTER_START.length();
234
stop = seiteArchiv1.indexOf(MUSTER_START, pos);
235
url = seiteArchiv1.extract("<a href=\"", "\"", pos, stop);
236
thema = seiteArchiv1.extract("teaser_overline\">", "<", pos, stop).trim();
237
if (thema.endsWith(":")) {
238
thema = thema.substring(0, thema.lastIndexOf(":"));
240
titel = seiteArchiv1.extract("teaser_title\">", "<", pos, stop);
241
// <p class="search_date">23.08.2013 | BR-alpha</p>
242
datum = seiteArchiv1.extract("search_date\">", "<", pos, stop);
243
if (datum.contains("|")) {
244
datum = datum.substring(0, datum.indexOf("|")).trim();
246
beschreibung = seiteArchiv1.extract("<p>", "<", pos, stop);
247
if (url.equals("")) {
248
Log.fehlerMeldung(-636987451, Log.FEHLER_ART_MREADER, MediathekBr.class.getName() + ".addToList_addr", "keine URL: " + adresse);
250
url = "http://www.br.de" + url;
251
archivAdd1(getUrl, seiteArchiv2, url, thema, titel, datum, beschreibung);
257
private void archivAdd1(GetUrl getUrl, MVStringBuilder seiteArchiv2, String urlThema, String thema, String titel, String datum, String beschreibung) {
258
// http://www.br.de/service/suche/archiv102.html?documentTypes=video&page=1&sort=date
260
seiteArchiv2 = getUrl.getUri(nameSenderMReader, urlThema, Konstanten.KODIERUNG_UTF, 1 /* versuche */, seiteArchiv2, "" /* Meldung */);
261
if (seiteArchiv2.length() == 0) {
262
Log.fehlerMeldung(-912036478, Log.FEHLER_ART_MREADER, MediathekBr.class.getName() + ".addToList_addr", "Leere Seite für URL: " + urlThema);
264
String url, urlFilm = "", urlFilmKlein = "", groesse = "", duration = "", bild = "";
266
url = seiteArchiv2.extract("setup({dataURL:'", "'");
267
bild = seiteArchiv2.extract("setup({dataURL:'", "\" src=\"", "\"");
268
if (!bild.isEmpty()) {
269
bild = "http://www.br.de" + bild;
271
if (url.equals("")) {
272
Log.fehlerMeldung(-834215987, Log.FEHLER_ART_MREADER, MediathekBr.class.getName() + ".archivAdd1", "keine URL: " + urlThema);
274
url = "http://www.br.de" + url;
275
seiteArchiv2 = getUrl.getUri(nameSenderMReader, url, Konstanten.KODIERUNG_UTF, 1 /* versuche */, seiteArchiv2, "" /* Meldung */);
276
if (seiteArchiv2.length() == 0) {
277
Log.fehlerMeldung(-397123654, Log.FEHLER_ART_MREADER, MediathekBr.class.getName() + ".addToList_addr", "Leere Seite für URL: " + urlThema);
279
// <asset type="STANDARD">
281
if ((start = seiteArchiv2.indexOf("<asset type=\"STANDARD\">")) != -1) {
282
urlFilmKlein = seiteArchiv2.extract("<serverPrefix>", "<", start) + seiteArchiv2.extract("<fileName>", "<", start);
283
// <readableSize>281 MB</readableSize>
284
groesse = seiteArchiv2.extract("<readableSize>", "<", start);
286
if ((start = seiteArchiv2.indexOf("<asset type=\"PREMIUM\">")) != -1) {
287
urlFilm = seiteArchiv2.extract("<serverPrefix>", "<", start) + seiteArchiv2.extract("<fileName>", "<", start);
288
if (!urlFilm.isEmpty()) {
289
groesse = seiteArchiv2.extract("<readableSize>", "<", start);
292
if (groesse.contains("MB")) {
293
groesse = groesse.replace("MB", "").trim();
295
// <duration>00:44:15</duration>
296
duration = seiteArchiv2.extract("<duration>", "<");
297
if (!duration.equals("")) {
299
String[] parts = duration.split(":");
301
for (int i = parts.length - 1; i >= 0; i--) {
302
dauer += Long.parseLong(parts[i]) * power;
305
} catch (Exception ex) {
306
Log.fehlerMeldung(-304973047, Log.FEHLER_ART_MREADER, "MediathekBR.jsonSuchen", ex, "duration: " + duration);
309
if (urlFilm.isEmpty()) {
310
urlFilm = urlFilmKlein;
312
if (urlFilm.equals("")) {
313
Log.fehlerMeldung(-978451236, Log.FEHLER_ART_MREADER, MediathekBr.class.getName() + ".archivAdd1", "keine URL: " + urlThema);
314
} else if (dauer == 0 || dauer > 600) {
315
// nur anlegen, wenn länger als 10 Minuten, sonst nur Schnipsel
316
//public DatenFilm(String ssender, String tthema, String filmWebsite, String ttitel, String uurl, String uurlRtmp,
317
//String datum, String zeit, long dauerSekunden, String description, String thumbnailUrl, String imageUrl, String[] keywords) {
318
DatenFilm film = new DatenFilm(nameSenderMReader, thema, urlThema, titel, urlFilm, "",
319
datum, "", dauer, beschreibung, bild, new String[]{});
320
if (!urlFilmKlein.isEmpty()) {
321
film.addUrlKlein(urlFilmKlein, "");
324
Integer.parseInt(groesse);
325
film.arr[DatenFilm.FILM_GROESSE_NR] = groesse;
326
} catch (Exception ex) {
335
private String convertDatumJson(String datum) {
337
return new SimpleDateFormat("dd.MM.yyyy").format(sdfIn.parse(datum));
338
} catch (Exception ex) {
339
Log.fehlerMeldung(-963297249, Log.FEHLER_ART_MREADER, "MediathekBR.convertDatum", ex);
344
private String convertZeitJson(String datum) {
346
return new SimpleDateFormat("HH:mm:ss").format(sdfIn.parse(datum));
347
} catch (Exception ex) {
348
Log.fehlerMeldung(-963297249, Log.FEHLER_ART_MREADER, "MediathekBR.convertDatum", ex);
353
public String convertDatum(String datum) {
354
// <beginnPlan>2010-12-09T10:55:00</beginnPlan>
356
SimpleDateFormat sdfIn = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
357
Date filmDate = sdfIn.parse(datum);
358
SimpleDateFormat sdfOut;
359
sdfOut = new SimpleDateFormat("dd.MM.yyyy");
360
datum = sdfOut.format(filmDate);
361
} catch (Exception ex) {
362
Log.fehlerMeldung(-210365944, Log.FEHLER_ART_MREADER, "MediathekBr.convertDatum", ex, "");
367
public String convertTime(String datum) {
368
// <beginnPlan>2010-12-09T10:55:00</beginnPlan>
370
SimpleDateFormat sdfIn = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
371
Date filmDate = sdfIn.parse(datum);
372
SimpleDateFormat sdfOut;
373
sdfOut = new SimpleDateFormat("HH:mm:ss");
374
datum = sdfOut.format(filmDate);
375
} catch (Exception ex) {
376
Log.fehlerMeldung(-573690176, Log.FEHLER_ART_MREADER, "MediatheBr.convertTime", ex, "");