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

« back to all changes in this revision

Viewing changes to src/msearch/filmeSuchen/sender/MediathekNdr.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 msearch.filmeSuchen.sender;
 
21
 
 
22
import msearch.filmeSuchen.MSearchFilmeSuchen;
 
23
import java.text.SimpleDateFormat;
 
24
import java.util.Date;
 
25
import msearch.io.MSearchGetUrl;
 
26
import msearch.daten.MSearchConfig;
 
27
import msearch.daten.DatenFilm;
 
28
import msearch.tool.MSearchConst;
 
29
import msearch.tool.MSearchLog;
 
30
import msearch.tool.MSearchStringBuilder;
 
31
 
 
32
public class MediathekNdr extends MediathekReader implements Runnable {
 
33
 
 
34
    public static final String SENDER = "NDR";
 
35
    private MSearchStringBuilder seiteAlle = new MSearchStringBuilder(MSearchConst.STRING_BUFFER_START_BUFFER);
 
36
 
 
37
    public MediathekNdr(MSearchFilmeSuchen ssearch, int startPrio) {
 
38
        super(ssearch, /* name */ SENDER, /* threads */ 4, /* urlWarten */ 500, startPrio);
 
39
    }
 
40
 
 
41
    //-> erste Seite:
 
42
    // <h5><a href="/mediathek/mediatheksuche103_broadcast-30.html">Nordmagazin</a></h5>
 
43
    @Override
 
44
    void addToList() {
 
45
        //<broadcast id="1391" site="ndrfernsehen">45 Min</broadcast>
 
46
        final String ADRESSE = "http://www.ndr.de/mediathek/dropdown101-extapponly.html";
 
47
        final String MUSTER_URL1 = "<h5><a href=\"/mediathek/";
 
48
        listeThemen.clear();
 
49
        meldungStart();
 
50
        MSearchStringBuilder seite = new MSearchStringBuilder(MSearchConst.STRING_BUFFER_START_BUFFER);
 
51
        seite = getUrlIo.getUri(nameSenderMReader, ADRESSE, MSearchConst.KODIERUNG_UTF, 5 /* versuche */, seite, ""/* meldung */);
 
52
        int pos = 0;
 
53
        int pos1;
 
54
        int pos2;
 
55
        String url = "";
 
56
        String thema = "";
 
57
        while ((pos = seite.indexOf(MUSTER_URL1, pos)) != -1) {
 
58
            try {
 
59
                pos += MUSTER_URL1.length();
 
60
                pos1 = pos;
 
61
                if ((pos2 = seite.indexOf("\"", pos)) != -1) {
 
62
                    url = seite.substring(pos1, pos2);
 
63
                }
 
64
                pos1 = seite.indexOf(">", pos);
 
65
                pos2 = seite.indexOf("<", pos);
 
66
                if (pos1 != -1 && pos2 != -1 && pos1 < pos2) {
 
67
                    thema = seite.substring(pos1 + 1, pos2);
 
68
                }
 
69
                if (url.equals("")) {
 
70
                    MSearchLog.fehlerMeldung(-210367600, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.addToList", "keine Url");
 
71
                    continue;
 
72
                }
 
73
                String url_ = "http://www.ndr.de/mediathek/" + url;
 
74
                String[] add = new String[]{url_, thema};
 
75
                if (MSearchConfig.senderAllesLaden) {
 
76
                    if (!alleSeiteSuchen(url_, thema)) {
 
77
                        // dann halt so versuchen
 
78
                        listeThemen.addUrl(add);
 
79
                    }
 
80
                } else {
 
81
                    listeThemen.addUrl(add);
 
82
                }
 
83
            } catch (Exception ex) {
 
84
                MSearchLog.fehlerMeldung(-332945670, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.finden", ex);
 
85
            }
 
86
        }
 
87
        // http://www.ndr.de/mediathek/verpasst109-extapponly_date-20131009_branding-ndrtv.html?verpasstNow=13.10.2013&verpasstDate=09.10.2013&verpasstBrand=ndrtv
 
88
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
 
89
        int maxTage = MSearchConfig.senderAllesLaden ? 30 : 20;
 
90
        for (int i = 0; i < maxTage; ++i) {
 
91
            final String URL = "http://www.ndr.de/mediathek/verpasst109-extapponly_date-";
 
92
            String tag = formatter.format(new Date().getTime() - (1000 * 60 * 60 * 24 * i));
 
93
            String urlString = URL + tag + "_branding-ndrtv.html";
 
94
            listeThemen.addUrl(new String[]{urlString, ""});
 
95
        }
 
96
        if (MSearchConfig.getStop()) {
 
97
            meldungThreadUndFertig();
 
98
        } else if (listeThemen.size() == 0) {
 
99
            meldungThreadUndFertig();
 
100
        } else {
 
101
            meldungAddMax(listeThemen.size());
 
102
            for (int t = 0; t < maxThreadLaufen; ++t) {
 
103
                //new Thread(new ThemaLaden()).start();
 
104
                Thread th = new Thread(new ThemaLaden());
 
105
                th.setName(nameSenderMReader + t);
 
106
                th.start();
 
107
            }
 
108
        }
 
109
    }
 
110
 
 
111
    private boolean alleSeiteSuchen(String strUrlFeed, String tthema) {
 
112
        boolean ret = false;
 
113
        seiteAlle = getUrlIo.getUri(nameSenderMReader, strUrlFeed, MSearchConst.KODIERUNG_UTF, 3 /* versuche */, seiteAlle, "Thema: " + tthema/* meldung */);
 
114
        int pos1;
 
115
        int pos2;
 
116
        try {
 
117
            // http://www.ndr.de/mediathek/mediatheksuche103_broadcast-35.html
 
118
            // http://www.ndr.de/mediathek/mediatheksuche105_broadcast-35_format-video_page-1.html
 
119
            final String WEITER = "Alle zeigen (";
 
120
            if ((pos1 = seiteAlle.indexOf(WEITER)) != -1) {
 
121
                pos1 += WEITER.length();
 
122
                if ((pos2 = seiteAlle.indexOf(")", pos1)) != -1) {
 
123
                    String anz = seiteAlle.substring(pos1, pos2);
 
124
                    try {
 
125
                        int z = Integer.parseInt(anz);
 
126
                        for (int i = 1; i <= z / 10; ++i) {
 
127
                            // geht bei 2 los da das ja schon die erste Seite ist!
 
128
                            String url_ = strUrlFeed.replace(".html", "_format-video_page-" + String.valueOf(i) + ".html");
 
129
                            url_ = url_.replace("mediatheksuche103", "mediatheksuche105");
 
130
                            listeThemen.addUrl(new String[]{url_, tthema});
 
131
                            ret = true;
 
132
                        }
 
133
                    } catch (Exception ex) {
 
134
                        MSearchLog.fehlerMeldung(-913047821, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.feddEinerSeiteSuchen", strUrlFeed);
 
135
                    }
 
136
                }
 
137
            }
 
138
        } catch (Exception ex) {
 
139
            MSearchLog.fehlerMeldung(-643208979, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.feddEinerSeiteSuchen", strUrlFeed);
 
140
        }
 
141
        return ret;
 
142
    }
 
143
 
 
144
    private class ThemaLaden implements Runnable {
 
145
 
 
146
        MSearchGetUrl getUrl = new MSearchGetUrl(wartenSeiteLaden);
 
147
        private MSearchStringBuilder seite1 = new MSearchStringBuilder(MSearchConst.STRING_BUFFER_START_BUFFER);
 
148
        private MSearchStringBuilder seite2 = new MSearchStringBuilder(MSearchConst.STRING_BUFFER_START_BUFFER);
 
149
 
 
150
        @Override
 
151
        public synchronized void run() {
 
152
            try {
 
153
                meldungAddThread();
 
154
                String[] link;
 
155
                while (!MSearchConfig.getStop() && (link = listeThemen.getListeThemen()) != null) {
 
156
                    try {
 
157
                        meldungProgress(link[1]);
 
158
                        feedEinerSeiteSuchen(link[0], link[1] /* thema */);
 
159
                    } catch (Exception ex) {
 
160
                        MSearchLog.fehlerMeldung(-336901211, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.ThemaLaden.run.1", ex);
 
161
                    }
 
162
                }
 
163
            } catch (Exception ex) {
 
164
                MSearchLog.fehlerMeldung(-554632590, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.ThemaLaden.run.2", ex);
 
165
            }
 
166
            meldungThreadUndFertig();
 
167
        }
 
168
 
 
169
        void feedEinerSeiteSuchen(String strUrlFeed, String tthema) {
 
170
            // <h4><a href="/ratgeber/gesundheit/ernaehrung/minuten779.html" title="Zum Video: Wie funktioniert cholesterinsenkende Margarine?">Wie funktioniert cholesterinsenkende Margarine?</a></h4>
 
171
            // <div class="subline">45&nbsp;Min -&nbsp;22.04.2013 22:00</div>
 
172
 
 
173
            final String MUSTER_URL = "<h4><a href=\"/";
 
174
            final String MUSTER_ZEIT = "<div class=\"subline\">";
 
175
            final String MUSTER_DURATION = "<span class=\"runtime\" title=\"Spieldauer\">";
 
176
            seite1 = getUrlIo.getUri(nameSenderMReader, strUrlFeed, MSearchConst.KODIERUNG_UTF, 3 /* versuche */, seite1, "Thema: " + tthema/* meldung */);
 
177
            int pos = 0;
 
178
            int pos1;
 
179
            int pos2;
 
180
            String url;
 
181
            String titel = "";
 
182
            String thema = tthema;
 
183
            String datum = "";
 
184
            String zeit = "";
 
185
            long durationInSeconds = 0;
 
186
            String tmp;
 
187
            int lastPos = 0;
 
188
            try {
 
189
                while (!MSearchConfig.getStop() && (pos = seite1.indexOf(MUSTER_URL, pos)) != -1) {
 
190
                    pos += MUSTER_URL.length();
 
191
                    pos1 = pos;
 
192
                    if ((pos2 = seite1.indexOf("\"", pos1)) == -1) {
 
193
                        continue;
 
194
                    }
 
195
                    url = seite1.substring(pos1, pos2);
 
196
                    if (url.equals("")) {
 
197
                        MSearchLog.fehlerMeldung(-659210274, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.feddEinerSeiteSuchen", "keine Url feedEinerSeiteSuchen" + strUrlFeed);
 
198
                        continue;
 
199
                    }
 
200
                    if ((pos1 = seite1.indexOf(">", pos)) != -1) {
 
201
                        pos1 += 1;
 
202
                        if ((pos2 = seite1.indexOf("<", pos1)) != -1) {
 
203
                            titel = seite1.substring(pos1, pos2);
 
204
                        }
 
205
                    }
 
206
                    if ((pos1 = seite1.indexOf(MUSTER_ZEIT, pos)) != -1) {
 
207
                        pos1 += MUSTER_ZEIT.length();
 
208
                        if ((pos2 = seite1.indexOf("<", pos1)) != -1) {
 
209
                            tmp = seite1.substring(pos1, pos2);
 
210
                            if (tmp.contains("-")) {
 
211
                                tmp = tmp.substring(tmp.lastIndexOf("-") + 1);
 
212
                                tmp = tmp.replaceAll("&nbsp;", "");
 
213
                                try {
 
214
                                    SimpleDateFormat sdfIn = new SimpleDateFormat("dd.MM.yyyy HH:mm");
 
215
                                    Date filmDate = sdfIn.parse(tmp);
 
216
                                    datum = new SimpleDateFormat("dd.MM.yyyy").format(filmDate);
 
217
                                    zeit = new SimpleDateFormat("HH:mm:ss").format(filmDate);
 
218
                                } catch (Exception ex) {
 
219
                                    MSearchLog.fehlerMeldung(-623657941, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.FilmSuchen", "convertDatum: " + strUrlFeed);
 
220
                                }
 
221
                            }
 
222
                        }
 
223
                    }
 
224
                    // Die dauer des filmes kommt vor dem titel über welchen wir hier am
 
225
                    // iterieren sind. Wir müssen also rückwärts suchen. Die url kommt jeweils doppelt
 
226
                    // vor im dokument. Wir werdenden diese als marker zum zurückzu springen:
 
227
                    /*<a href="/fernsehen/sendungen/extra_3/videos/extra5349.html" title="Zum Video: Extra 3 vom 08.05.2013" >
 
228
                     <img width="376" height="212" src="/fernsehen/ehring255_v-zweispaltig.jpg" alt="Moderator Christian Ehring mit einem Schild mit der Aufschrift, wer das umdreht ist doof, in der Hand.  " title="Moderator Christian Ehring mit einem Schild mit der Aufschrift, wer das umdreht ist doof, in der Hand."  /><div class="overlay">
 
229
                     <div class="shiny_line">&nbsp;</div><div class="marker"></div>
 
230
                     <div class="inner">
 
231
                     <span class="icon icon_video" title="Video">Video</span>
 
232
                     <span class="runtime" title="Spieldauer">28:55</span></div>
 
233
                     </div>
 
234
                     </a>
 
235
                     <div class="content">
 
236
                     <h4><a href="/fernsehen/sendungen/extra_3/videos/extra5349.html" title="Zum Video: Extra 3 vom 08.05.2013">Extra 3 vom 08.05.2013</a></h4>
 
237
                     <div class="subline">extra&nbsp;3 -&nbsp;08.05.2013 22:50</div>*/
 
238
                    if ((pos1 = seite1.indexOf(url, lastPos)) != -1) {
 
239
                        if ((pos1 = seite1.indexOf(MUSTER_DURATION, pos1)) != -1) {
 
240
                            pos1 += MUSTER_DURATION.length();
 
241
                            if ((pos2 = seite1.indexOf("<", pos1)) != -1) {
 
242
                                String duration = seite1.substring(pos1, pos2).trim();
 
243
                                try {
 
244
                                    if (!duration.equals("")) {
 
245
                                        String[] parts = duration.split(":");
 
246
                                        long power = 1;
 
247
                                        durationInSeconds = 0;
 
248
                                        for (int i = parts.length - 1; i >= 0; i--) {
 
249
                                            durationInSeconds += Long.parseLong(parts[i]) * power;
 
250
                                            power *= 60;
 
251
                                        }
 
252
                                    }
 
253
                                } catch (Exception ex) {
 
254
                                    MSearchLog.fehlerMeldung(-369015497, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.feddEinerSeiteSuchen", ex, strUrlFeed);
 
255
                                }
 
256
                            }
 
257
                        }
 
258
                    }
 
259
                    filmSuchen(strUrlFeed, thema, titel, "http://www.ndr.de/" + url, datum, zeit, durationInSeconds);
 
260
                    lastPos = pos;
 
261
                }
 
262
            } catch (Exception ex) {
 
263
                MSearchLog.fehlerMeldung(-693219870, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.feddEinerSeiteSuchen", strUrlFeed);
 
264
            }
 
265
        }
 
266
 
 
267
        void filmSuchen(String strUrlThema, String thema, String titel, String filmWebsite, String datum, String zeit, long durationInSeconds) {
 
268
            //playlist: [
 
269
            //{
 
270
            //1: {src:'http://hds.ndr.de/z/2013/0419/TV-20130419-1010-0801.,hi,hq,.mp4.csmil/manifest.f4m', type:"application/f4m+xml"},
 
271
            //2: {src:'http://hls.ndr.de/i/2013/0419/TV-20130419-1010-0801.,lo,hi,hq,.mp4.csmil/master.m3u8', type:"application/x-mpegURL"},
 
272
            //3: {src:'http://media.ndr.de/progressive/2013/0419/TV-20130419-1010-0801.hi.mp4', type:"video/mp4"},
 
273
 
 
274
            // http://media.ndr.de/progressive/2012/0820/TV-20120820-2300-0701.hi.mp4
 
275
            // rtmpt://cp160844.edgefcs.net/ondemand/mp4:flashmedia/streams/ndr/2012/0820/TV-20120820-2300-0701.hq.mp4
 
276
 
 
277
            final String MUSTER_URL = "3: {src:'http://";
 
278
            seite2 = getUrl.getUri_Utf(nameSenderMReader, filmWebsite, seite2, "strUrlThema: " + strUrlThema);
 
279
            //long durationInSeconds = extractDuration(seite2);
 
280
            String description = extractDescription(seite2);
 
281
            String[] keywords = extractKeywords(seite2);
 
282
            String imageUrl = extractImageURL(seite2);
 
283
            meldung(filmWebsite);
 
284
            int pos1;
 
285
            int pos2;
 
286
            String url, tmp;
 
287
            try {
 
288
                if ((pos1 = seite2.indexOf(MUSTER_URL)) != -1) {
 
289
                    pos1 += MUSTER_URL.length();
 
290
                    if ((pos2 = seite2.indexOf("'", pos1)) != -1) {
 
291
                        url = seite2.substring(pos1, pos2);
 
292
                        if (!url.equals("")) {
 
293
                            url = "http://" + url;
 
294
                            if (url.contains("http://media.ndr.de/progressive")) {
 
295
                                if (url.contains("hi.mp4")) {
 
296
                                    url = url.replace("hi.mp4", "hq.mp4");
 
297
                                }
 
298
                            }
 
299
                            if (thema.equals("")) {
 
300
                                thema = seite2.extract("<h1>", "<div class=\"subline\">", "<");
 
301
                                if (thema.contains("|")) {
 
302
                                    thema = thema.substring(0, thema.lastIndexOf("|"));
 
303
                                    thema = thema.trim();
 
304
                                }
 
305
                                if (thema.contains("-")) {
 
306
                                    thema = thema.substring(0, thema.lastIndexOf("-"));
 
307
                                    thema = thema.trim();
 
308
                                }
 
309
                                if (thema.contains("Uhr")) {
 
310
                                    thema = "";
 
311
                                }
 
312
                                if (thema.equals("")) {
 
313
                                    thema = "NDR";
 
314
                                }
 
315
                            }
 
316
                            DatenFilm film = new DatenFilm(nameSenderMReader, thema, filmWebsite, titel, url, ""/*rtmpURL*/, datum, zeit, durationInSeconds, description,
 
317
                                    imageUrl, keywords);
 
318
                            if (url.contains(".hq.")) {
 
319
                                String urlKlein = url.replace(".hq.", ".hi.");
 
320
                                film.addUrlKlein(urlKlein, "");
 
321
                            }
 
322
                            addFilm(film);
 
323
                        } else {
 
324
                            MSearchLog.fehlerMeldung(-623657941, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.FilmSuchen", "keine URL: " + filmWebsite);
 
325
                        }
 
326
                    }
 
327
                } else {
 
328
                    MSearchLog.fehlerMeldung(-698970145, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.FilmSuchen", "keine Url: " + filmWebsite);
 
329
                }
 
330
            } catch (Exception ex) {
 
331
                MSearchLog.fehlerMeldung(-699830157, MSearchLog.FEHLER_ART_MREADER, "MediathekNdr.FilmSuchen", ex);
 
332
            }
 
333
        }
 
334
 
 
335
        private String extractDescription(MSearchStringBuilder page) {
 
336
            String desc = extractString(page, "<meta property=\"og:description\" content=\"", "\"");
 
337
            if (desc == null) {
 
338
                return "";
 
339
            }
 
340
            return desc;
 
341
        }
 
342
 
 
343
        private String[] extractKeywords(MSearchStringBuilder page) {
 
344
            String keywords = extractString(page, "<meta name=\"keywords\"  lang=\"de\" content=\"", "\"");
 
345
            if (keywords == null) {
 
346
                return new String[]{""};
 
347
            }
 
348
            String[] k = keywords.split(",");
 
349
            for (int i = 0; i < k.length; i++) {
 
350
                k[i] = k[i].trim();
 
351
            }
 
352
            return k;
 
353
        }
 
354
 
 
355
        private String extractImageURL(MSearchStringBuilder page) {
 
356
            String image = extractString(page, "<meta property=\"og:image\" content=\"", "\"");
 
357
            if (image == null) {
 
358
                return "";
 
359
            }
 
360
            return image;
 
361
        }
 
362
 
 
363
        private String extractString(MSearchStringBuilder source, String startMarker, String endMarker) {
 
364
            int start = source.indexOf(startMarker);
 
365
            if (start == -1) {
 
366
                return null;
 
367
            }
 
368
            start = start + startMarker.length();
 
369
            int end = source.indexOf(endMarker, start);
 
370
            if (end == -1) {
 
371
                return null;
 
372
            }
 
373
            return source.substring(start, end);
 
374
        }
 
375
    }
 
376
}