~ubuntu-branches/ubuntu/trusty/mediathekview/trusty

« back to all changes in this revision

Viewing changes to src/mediathek/controller/filmeLaden/suchen/sender/MediathekBr.java

  • Committer: Package Import Robot
  • Author(s): Markus Koschany
  • Date: 2014-01-07 17:25:52 UTC
  • mfrom: (4.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140107172552-vkv6uixpou3sa5og
Tags: 4-1
* Imported Upstream version 4.
* Declare compliance with Standards-Version 3.9.5.
* Correct a mistake in the last changelog entry.
  - build-dependencies <-> dependencies
* Override lintian warning:incompatible-java-bytecode-format Java7 because
  Java7 is the current default JRE for Jessie. MediathekView also requires
  Java7 to run and is incompatible with Java6 or earlier.
* debian/control: Add libjackson2-core-java, libtimingframework-java and
  libxz-java to Build-Depends-Indep.
* Drop README.source. Now upstream provides a source tarball.
* Refresh modify-ant-build-system.patch.
* debian/rules: Remove get-orig-source target. No longer needed.
* Update mediathekview.manifest. Add new required libraries to classpath.
* Update debian/watch for new versioning scheme.
* Update debian/copyright for new release. Add BSD-3-clause license.
* Update man pages and remove unsupported options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * MediathekView
3
 
 * Copyright (C) 2008 W. Xaver
4
 
 * W.Xaver[at]googlemail.com
5
 
 * http://zdfmediathk.sourceforge.net/
6
 
 *
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
10
 
 * any later version.
11
 
 *
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.
16
 
 *
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/>.
19
 
 */
20
 
package mediathek.controller.filmeLaden.suchen.sender;
21
 
 
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;
33
 
 
34
 
public class MediathekBr extends MediathekReader implements Runnable {
35
 
 
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", 
38
 
 
39
 
    public MediathekBr(FilmeSuchenSender ssearch, int startPrio) {
40
 
        super(ssearch, /* name */ SENDER, /* threads */ 2, /* urlWarten */ 500, startPrio);
41
 
    }
42
 
 
43
 
    @Override
44
 
    void addToList() {
45
 
        //new Thread(new ThemaLaden()).start();
46
 
        meldungStart();
47
 
        Thread th;
48
 
        th = new Thread(new ThemaLaden());
49
 
        th.setName(nameSenderMReader);
50
 
        th.start();
51
 
        if (filmeSuchenSender.senderAllesLaden) {
52
 
            th = new Thread(new ArchivLaden(1, 100));
53
 
            th.setName(nameSenderMReader);
54
 
            th.start();
55
 
            th = new Thread(new ArchivLaden(101, 200));
56
 
            th.setName(nameSenderMReader);
57
 
            th.start();
58
 
            th = new Thread(new ArchivLaden(201, 300));
59
 
            th.setName(nameSenderMReader);
60
 
            th.start();
61
 
            th = new Thread(new ArchivLaden(301, 400));
62
 
            th.setName(nameSenderMReader);
63
 
            th.start();
64
 
        }
65
 
    }
66
 
 
67
 
    private class ThemaLaden implements Runnable {
68
 
 
69
 
        @Override
70
 
        public synchronized void run() {
71
 
            meldungAddMax(1);
72
 
            meldungAddThread();
73
 
            try {
74
 
                jsonSuchen();
75
 
            } catch (Exception ex) {
76
 
                Log.fehlerMeldung(-203069877, Log.FEHLER_ART_MREADER, "MediathekBr.JsonLaden.run", ex, "");
77
 
            }
78
 
            meldungThreadUndFertig();
79
 
        }
80
 
    }
81
 
 
82
 
    private class ArchivLaden implements Runnable {
83
 
 
84
 
        int anfang, ende;
85
 
 
86
 
        public ArchivLaden(int aanfang, int eende) {
87
 
            anfang = aanfang;
88
 
            ende = eende;
89
 
        }
90
 
 
91
 
        @Override
92
 
        public synchronized void run() {
93
 
            meldungAddMax(ende - anfang);
94
 
            meldungAddThread();
95
 
            try {
96
 
                archivSuchen(anfang, ende);
97
 
            } catch (Exception ex) {
98
 
                Log.fehlerMeldung(-203069877, Log.FEHLER_ART_MREADER, "MediathekBr.JsonLaden.run", ex, "");
99
 
            }
100
 
            meldungThreadUndFertig();
101
 
        }
102
 
    }
103
 
 
104
 
    private void jsonSuchen() {
105
 
        //"date": "2013-07-13 13:00:00", 
106
 
        //"description": "Pflanzentricks - Wie erreicht eine Pflanze, was sie will?", 
107
 
        //"duration": "25", 
108
 
        //"image": "http://mediathek-video.br.de/listra/sendungsbilder/xenius_xl.jpg", 
109
 
        //"title": "X:enius", 
110
 
        //"videos": {
111
 
        //"l": {
112
 
        //  "bitrate": 700000, 
113
 
        //  "url": "http://hbbtv.b7.br.gl-systemhaus.de/b7/konks/1373715065-b7konks_nc_203101728_107154.mp4"
114
 
        //}, 
115
 
        //"m": {
116
 
        //  "bitrate": 200000, 
117
 
        //  "url": "http://hbbtv.b7.br.gl-systemhaus.de/b7/konks/1373715063-b7konks_nc_203101728_107153.mp4"
118
 
        //}, 
119
 
        //"xl": {
120
 
        //  "bitrate": 2000000, 
121
 
        //  "url": "http://hbbtv.b7.br.gl-systemhaus.de/b7/konks/1373715066-b7konks_nc_203101728_107155.mp4"
122
 
        //}
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;
134
 
        long dauer;
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);
140
 
            return;
141
 
        }
142
 
        int pos, posStop;
143
 
        int pos1;
144
 
        int pos2;
145
 
        pos = 0;
146
 
        while (!Daten.filmeLaden.getStop() && (pos = seite1.indexOf(DATE, pos)) != -1) {
147
 
            date = "";
148
 
            datum = "";
149
 
            zeit = "";
150
 
            thema = "";
151
 
            titel = "";
152
 
            description = "";
153
 
            duration = "";
154
 
            image = "";
155
 
            url = "";
156
 
            url_klein = "";
157
 
            dauer = 0;
158
 
            try {
159
 
                pos += DATE.length();
160
 
                posStop = seite1.indexOf(DATE, pos);
161
 
                pos1 = pos;
162
 
                if ((pos2 = seite1.indexOf("\"", pos1)) != -1) {
163
 
                    date = seite1.substring(pos1, pos2);
164
 
                    datum = convertDatumJson(date);
165
 
                    zeit = convertZeitJson(date);
166
 
                }
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() + "...";
174
 
                } else {
175
 
                    titel = description;
176
 
                    description = "";
177
 
                }
178
 
                duration = seite1.extract(DURATION, "\"", pos, posStop);
179
 
                if (!duration.equals("")) {
180
 
                    try {
181
 
                        dauer = Long.parseLong(duration) * 60;
182
 
                    } catch (Exception ex) {
183
 
                        Log.fehlerMeldung(-304973047, Log.FEHLER_ART_MREADER, "MediathekBR.jsonSuchen", ex, "duration: " + duration);
184
 
                    }
185
 
                }
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()) {
191
 
                    url = url_klein;
192
 
                    url_klein = "";
193
 
                } else if (url.isEmpty()) {
194
 
                    continue;
195
 
                }
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, "");
204
 
                addFilm(film);
205
 
                meldung(film.arr[DatenFilm.FILM_URL_NR]);
206
 
            } catch (Exception ex) {
207
 
                Log.fehlerMeldung(-902483073, Log.FEHLER_ART_MREADER, "MediathekBR.jsonSuchen", ex, "");
208
 
            }
209
 
        }
210
 
    }
211
 
 
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()) {
222
 
                break;
223
 
            }
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);
229
 
            }
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(":"));
239
 
                }
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();
245
 
                }
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);
249
 
                } else {
250
 
                    url = "http://www.br.de" + url;
251
 
                    archivAdd1(getUrl, seiteArchiv2, url, thema, titel, datum, beschreibung);
252
 
                }
253
 
            }
254
 
        }
255
 
    }
256
 
 
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
259
 
        meldung(urlThema);
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);
263
 
        }
264
 
        String url, urlFilm = "", urlFilmKlein = "", groesse = "", duration = "", bild = "";
265
 
        long dauer = 0;
266
 
        url = seiteArchiv2.extract("setup({dataURL:'", "'");
267
 
        bild = seiteArchiv2.extract("setup({dataURL:'", "\" src=\"", "\"");
268
 
        if (!bild.isEmpty()) {
269
 
            bild = "http://www.br.de" + bild;
270
 
        }
271
 
        if (url.equals("")) {
272
 
            Log.fehlerMeldung(-834215987, Log.FEHLER_ART_MREADER, MediathekBr.class.getName() + ".archivAdd1", "keine URL: " + urlThema);
273
 
        } else {
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);
278
 
            }
279
 
            // <asset type="STANDARD">
280
 
            int start;
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);
285
 
            }
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);
290
 
                }
291
 
            }
292
 
            if (groesse.contains("MB")) {
293
 
                groesse = groesse.replace("MB", "").trim();
294
 
            }
295
 
            // <duration>00:44:15</duration>
296
 
            duration = seiteArchiv2.extract("<duration>", "<");
297
 
            if (!duration.equals("")) {
298
 
                try {
299
 
                    String[] parts = duration.split(":");
300
 
                    long power = 1;
301
 
                    for (int i = parts.length - 1; i >= 0; i--) {
302
 
                        dauer += Long.parseLong(parts[i]) * power;
303
 
                        power *= 60;
304
 
                    }
305
 
                } catch (Exception ex) {
306
 
                    Log.fehlerMeldung(-304973047, Log.FEHLER_ART_MREADER, "MediathekBR.jsonSuchen", ex, "duration: " + duration);
307
 
                }
308
 
            }
309
 
            if (urlFilm.isEmpty()) {
310
 
                urlFilm = urlFilmKlein;
311
 
            }
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, "");
322
 
                }
323
 
                try {
324
 
                    Integer.parseInt(groesse);
325
 
                    film.arr[DatenFilm.FILM_GROESSE_NR] = groesse;
326
 
                } catch (Exception ex) {
327
 
                    // dann wars nix
328
 
                }
329
 
                addFilm(film);
330
 
 
331
 
            }
332
 
        }
333
 
    }
334
 
 
335
 
    private String convertDatumJson(String datum) {
336
 
        try {
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);
340
 
        }
341
 
        return "";
342
 
    }
343
 
 
344
 
    private String convertZeitJson(String datum) {
345
 
        try {
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);
349
 
        }
350
 
        return "";
351
 
    }
352
 
 
353
 
    public String convertDatum(String datum) {
354
 
        //      <beginnPlan>2010-12-09T10:55:00</beginnPlan>
355
 
        try {
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, "");
363
 
        }
364
 
        return datum;
365
 
    }
366
 
 
367
 
    public String convertTime(String datum) {
368
 
        //      <beginnPlan>2010-12-09T10:55:00</beginnPlan>
369
 
        try {
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, "");
377
 
        }
378
 
        return datum;
379
 
    }
380
 
}