Skip to content

Commit

Permalink
Fixed some Null pointer exceptions for #476 and #478
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicklas2751 committed May 26, 2019
1 parent 8e71310 commit 9cb1bbd
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 316 deletions.
21 changes: 1 addition & 20 deletions src/main/java/mServer/crawler/sender/AbstractMediathekZdf.java
@@ -1,22 +1,3 @@
/*
* MediathekView
* Copyright (C) 2008 W. Xaver
* W.Xaver[at]googlemail.com
* http://zdfmediathk.sourceforge.net/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mServer.crawler.sender;

import de.mediathekview.mlib.Config;
Expand All @@ -39,8 +20,8 @@ public abstract class AbstractMediathekZdf extends MediathekReader {

public AbstractMediathekZdf(String aSenderName, FilmeSuchen ssearch, int startPrio) {
super(ssearch, aSenderName, 0 /* threads */, 150 /* urlWarten */, startPrio);
setName("Mediathek" + aSenderName);
senderName = aSenderName;
setName(senderName);
}

private final Phaser phaser = new Phaser();
Expand Down
183 changes: 107 additions & 76 deletions src/main/java/mServer/crawler/sender/newsearch/ZDFEntryTask.java
@@ -1,76 +1,107 @@
package mServer.crawler.sender.newsearch;

import java.util.concurrent.RecursiveTask;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;

import de.mediathekview.mlib.Config;
import de.mediathekview.mlib.tool.Log;

/** Searches all information required for a film */
public class ZDFEntryTask extends RecursiveTask<VideoDTO> {

private static final long serialVersionUID = 1L;

private final ZDFClient client;
private final ZDFEntryDTO zdfEntryDTO;
private final Gson gson;

public ZDFEntryTask(ZDFEntryDTO aEntryDto, String aBaseUrl, String aApiBaseUrl, String aApiHost, ZDFConfigurationDTO aConfig) {
this(aEntryDto, new ZDFClient(aBaseUrl, aApiBaseUrl, aApiHost,aConfig));
}

public ZDFEntryTask(ZDFEntryDTO aEntryDto, ZDFClient zdfClient) {
client = zdfClient;
zdfEntryDTO = aEntryDto;
gson =
new GsonBuilder()
.registerTypeAdapter(VideoDTO.class, new ZDFVideoDTODeserializer())
.registerTypeAdapter(DownloadDTO.class, new ZDFDownloadDTODeserializer())
.create();
}

@Override
protected VideoDTO compute() {

if (zdfEntryDTO == null) {
return null;
}

VideoDTO dto = null;

if (!Config.getStop()) {
try {
// read film details
String infoUrl = zdfEntryDTO.getEntryGeneralInformationUrl();
JsonObject baseObjectInfo = client.execute(infoUrl);
if (baseObjectInfo != null) {
dto = gson.fromJson(baseObjectInfo, VideoDTO.class);
if (dto != null) {
// read download details
String downloadUrl = zdfEntryDTO.getEntryDownloadInformationUrl();
JsonObject baseObjectDownload = client.execute(downloadUrl);
if (baseObjectDownload != null) {
DownloadDTO downloadDto = gson.fromJson(baseObjectDownload, DownloadDTO.class);
dto.setDownloadDto(downloadDto);
} else {
// entry without download infos is not relevant
dto = null;
}
}
}
} catch (Exception ex) {
Log.errorLog(
496583202,
ex,
"Exception parsing "
+ (zdfEntryDTO != null ? zdfEntryDTO.getEntryGeneralInformationUrl() : ""));
dto = null;
}
}

return dto;
}
}
package mServer.crawler.sender.newsearch;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import de.mediathekview.mlib.Config;
import de.mediathekview.mlib.tool.Log;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.RecursiveTask;

/** Searches all information required for a film */
public class ZDFEntryTask extends RecursiveTask<VideoDTO> {

private static final long serialVersionUID = 1L;
public static final String TAG_PROFILE = "profile";
public static final String PROFILE_REDIRECT = "http://zdf.de/rels/moved-permanently";
public static final String TAG_LOCATION = "location";

private final ZDFClient client;
private final ZDFEntryDTO zdfEntryDTO;
private final Gson gson;

public ZDFEntryTask(
ZDFEntryDTO aEntryDto,
String aBaseUrl,
String aApiBaseUrl,
String aApiHost,
ZDFConfigurationDTO aConfig) {
this(aEntryDto, new ZDFClient(aBaseUrl, aApiBaseUrl, aApiHost, aConfig));
}

public ZDFEntryTask(ZDFEntryDTO aEntryDto, ZDFClient zdfClient) {
client = zdfClient;
zdfEntryDTO = aEntryDto;
gson =
new GsonBuilder()
.registerTypeAdapter(VideoDTO.class, new ZDFVideoDTODeserializer())
.registerTypeAdapter(DownloadDTO.class, new ZDFDownloadDTODeserializer())
.create();
}

@Override
protected VideoDTO compute() {

if (zdfEntryDTO == null) {
return null;
}

VideoDTO dto = null;

if (!Config.getStop()) {
try {
// read film details
String infoUrl = zdfEntryDTO.getEntryGeneralInformationUrl();
JsonObject baseObjectInfo = client.execute(infoUrl);
if (baseObjectInfo != null) {
if (isRedirect(baseObjectInfo)) {
baseObjectInfo = loadRedirect(baseObjectInfo, infoUrl);
}
dto = gson.fromJson(baseObjectInfo, VideoDTO.class);
if (dto != null) {
// read download details
String downloadUrl = zdfEntryDTO.getEntryDownloadInformationUrl();
JsonObject baseObjectDownload = client.execute(downloadUrl);
if (baseObjectDownload != null) {
DownloadDTO downloadDto = gson.fromJson(baseObjectDownload, DownloadDTO.class);
dto.setDownloadDto(downloadDto);
} else {
// entry without download infos is not relevant
dto = null;
}
}
}
} catch (Exception ex) {
Log.errorLog(
496583202,
ex,
"Exception parsing "
+ (zdfEntryDTO != null ? zdfEntryDTO.getEntryGeneralInformationUrl() : ""));
dto = null;
}
}

return dto;
}

private JsonObject loadRedirect(JsonObject baseObjectInfo, String oldUrl) {
String newLocation = baseObjectInfo.get(TAG_LOCATION).getAsString();
try {
baseObjectInfo = client.execute(new URL(new URL(oldUrl), newLocation).toString());
} catch (MalformedURLException malformedUrlException) {
Log.errorLog(445648914, "Ein Weiterleitungslink ist fehlerhaft!");
}

return baseObjectInfo;
}

private boolean isRedirect(JsonObject baseObjectInfo) {
return baseObjectInfo.has(TAG_PROFILE)
&& !baseObjectInfo.get(TAG_PROFILE).isJsonNull()
&& baseObjectInfo.get(TAG_PROFILE).getAsString().equals(PROFILE_REDIRECT)
&& baseObjectInfo.has(TAG_LOCATION)
&& !baseObjectInfo.get(TAG_LOCATION).isJsonNull();
}
}

0 comments on commit 9cb1bbd

Please sign in to comment.