Added a new RandomIndexedComic + fixed a bug in classes.json and Misfile

This commit is contained in:
applications4android 2012-12-16 23:23:02 +05:30
parent 562d489a8c
commit f328f499c0
5 changed files with 230 additions and 254 deletions

View File

@ -131,7 +131,7 @@
{"class":"GoComics.BroomHilda", "name":"Broom Hilda", "pref":"broomhildaPref"}, {"class":"GoComics.BroomHilda", "name":"Broom Hilda", "pref":"broomhildaPref"},
{"class":"GoComics.TheBuckets", "name":"The Buckets", "pref":"thebucketsPref"}, {"class":"GoComics.TheBuckets", "name":"The Buckets", "pref":"thebucketsPref"},
{"class":"GoComics.Buni", "name":"Buni", "pref":"buniPref"}, {"class":"GoComics.Buni", "name":"Buni", "pref":"buniPref"},
{"class":"GoComics.CaféconLeche", "name":"Café con Leche", "pref":"cafeconlechePref"}, {"class":"GoComics.CafeconLeche", "name":"Cafe con Leche", "pref":"cafeconlechePref"},
{"class":"GoComics.CalvinandHobbes", "name":"Calvin and Hobbes", "pref":"calvinandhobbesPref"}, {"class":"GoComics.CalvinandHobbes", "name":"Calvin and Hobbes", "pref":"calvinandhobbesPref"},
{"class":"GoComics.Candorville", "name":"Candorville", "pref":"candorvillePref"}, {"class":"GoComics.Candorville", "name":"Candorville", "pref":"candorvillePref"},
{"class":"GoComics.Cathy", "name":"Cathy", "pref":"cathyPref"}, {"class":"GoComics.Cathy", "name":"Cathy", "pref":"cathyPref"},

View File

@ -2,36 +2,63 @@ package com.blogspot.applications4android.comicreader.comics;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import android.util.Log; import com.blogspot.applications4android.comicreader.comictypes.RandomIndexedComic;
import com.blogspot.applications4android.comicreader.comictypes.IndexedComic;
import com.blogspot.applications4android.comicreader.core.Downloader;
import com.blogspot.applications4android.comicreader.core.Strip; import com.blogspot.applications4android.comicreader.core.Strip;
import com.blogspot.applications4android.comicreader.exceptions.ComicLatestException; import com.blogspot.applications4android.comicreader.exceptions.ComicLatestException;
public class Cyanide extends RandomIndexedComic {
public class Cyanide extends IndexedComic {
private int mNextId = -1;
private int mPrevId = -1;
private static final String RAND_URL = "http://www.explosm.net/comics/random/";
private static final String[] DONT_CACHE = new String[]{RAND_URL};
@Override @Override
protected String getFrontPageUrl() { protected int getFirstId() {
return "http://www.explosm.net/comics/"; return 15;
} }
@Override @Override
public String getComicWebPageUrl() { protected String getRandUrl() {
return "http://www.explosm.net/"; return "http://www.explosm.net/comics/random/";
} }
@Override @Override
protected int parseForLatestId(BufferedReader reader) throws IOException, ComicLatestException { protected int getNextStripId(BufferedReader br, String url) {
int id = -1;
try {
String str;
String final_next = null;
while ((str = br.readLine()) != null) {
if(str.indexOf("case 39") != -1) {
final_next = br.readLine();
}
}
setNextId(parseForNextId(final_next, getLatestId()));
}
catch(Exception e) {
e.printStackTrace();
}
return id;
}
@Override
protected int getPreviousStripId(BufferedReader br, String url) {
int id = -1;
try {
String str;
String final_prev = null;
while ((str = br.readLine()) != null) {
if(str.indexOf("case 37") != -1) {
final_prev = br.readLine();
}
}
setPreviousId(parseForPrevId(final_prev, getFirstId()));
}
catch(Exception e) {
e.printStackTrace();
}
return id;
}
@Override
protected int parseForLatestId(BufferedReader reader) throws ComicLatestException, IOException {
String str; String str;
String final_str = null; String final_str = null;
while((str = reader.readLine()) != null) { while((str = reader.readLine()) != null) {
@ -50,44 +77,6 @@ public class Cyanide extends IndexedComic {
return Integer.parseInt(final_str); return Integer.parseInt(final_str);
} }
@Override
protected String getNextStripUrl() {
int id = mNextId;
if(id < getFirstId()) {
try {
id = _getNextStripId(new URI(getCurrentStrip().uid()));
}
catch (URISyntaxException e) { // this should never occur!
e.printStackTrace();
}
}
return getStripUrlFromId(id);
}
@Override
protected String getPreviousStripUrl() {
int id = mPrevId;
if(id < getFirstId()) {
try {
id = _getPrevStripId(new URI(getCurrentStrip().uid()));
}
catch (URISyntaxException e) { // this should never occur!
e.printStackTrace();
}
}
return getStripUrlFromId(id);
}
@Override
protected int getFirstId() {
return 15;
}
@Override
protected String getRandomStripUrl() {
return RAND_URL;
}
@Override @Override
public String getStripUrlFromId(int num) { public String getStripUrlFromId(int num) {
return "http://www.explosm.net/comics/" + num; return "http://www.explosm.net/comics/" + num;
@ -99,14 +88,23 @@ public class Cyanide extends IndexedComic {
return Integer.parseInt(str); return Integer.parseInt(str);
} }
@Override
protected String getFrontPageUrl() {
return "http://www.explosm.net/comics/";
}
@Override
public String getComicWebPageUrl() {
return "http://www.explosm.net/";
}
@Override @Override
protected boolean htmlNeeded() { protected boolean htmlNeeded() {
return true; return true;
} }
@Override @Override
protected String parse(String url, BufferedReader reader, Strip strip) protected String parse(String url, BufferedReader reader, Strip strip) throws IOException {
throws IOException {
boolean comic_found = true; boolean comic_found = true;
String str; String str;
String final_str = null; String final_str = null;
@ -133,111 +131,31 @@ public class Cyanide extends IndexedComic {
final_prev = reader.readLine(); final_prev = reader.readLine();
} }
} }
Log.d("CYanide", "comic_found="+comic_found);
/*
if(!comic_found) {
String msg = "Failed to find the comic for URL="+strip.m_comic_url.toExternalForm();
ComicNotFoundException cnf = new ComicNotFoundException(msg);
throw cnf;
}
if((final_str == null) || (final_title == null)) {
String msg = "Failed to find the stripURL for URL="+strip.m_comic_url.toExternalForm();
msg += " final_str="+final_str+" final_title="+final_title;
ComicParseException cpe = new ComicParseException(msg);
throw cpe;
}
*/
final_str = final_str.replaceAll(".*Cyanide and Happiness, a daily webcomic\" src=\"",""); final_str = final_str.replaceAll(".*Cyanide and Happiness, a daily webcomic\" src=\"","");
final_str = final_str.replaceAll("\".*",""); final_str = final_str.replaceAll("\".*","");
final_title = final_title.replaceAll(".*<title>",""); final_title = final_title.replaceAll(".*<title>","");
final_title = final_title.replaceAll(" - Explosm.*",""); final_title = final_title.replaceAll(" - Explosm.*","");
strip.setTitle(final_title); strip.setTitle(final_title);
strip.setText("-NA-"); strip.setText("-NA-");
if(final_next != null) { // set the next and previous comic IDs from the current url's html data
final_next = final_next.replaceAll(".*comics/", ""); setPreviousId(parseForPrevId(final_prev, -1));
final_next = final_next.replaceAll("/\".*", ""); setNextId(parseForNextId(final_next, -1));
mNextId = Integer.parseInt(final_next);
}
else {
mNextId = -1;
}
if(final_prev != null) {
final_prev = final_prev.replaceAll(".*comics/", "");
final_prev = final_prev.replaceAll("/\".*", "");
mPrevId = Integer.parseInt(final_prev);
}
else {
mPrevId = -1;
}
return final_str; return final_str;
} }
@Override @Override
protected String[] urlsNotForCaching() { protected int parseForPrevId(String line, int def) {
return DONT_CACHE; if(line == null) {
return def;
}
line = line.replaceAll(".*comics/", "");
line = line.replaceAll("/\".*", "");
return Integer.parseInt(line);
} }
/** @Override
* Get the next strip id protected int parseForNextId(String line, int def) {
* @param url url from which to parse return parseForPrevId(line, def);
* @return desired id
*/
private int _getNextStripId(URI url) {
int id = -1;
try {
BufferedReader reader = Downloader.openConnection(url);
String str;
String final_next = null;
while ((str = reader.readLine()) != null) {
if(str.indexOf("case 39") != -1) {
final_next = reader.readLine();
}
}
reader.close();
if(final_next != null) {
final_next = final_next.replaceAll(".*comics/", "");
final_next = final_next.replaceAll("/\".*", "");
id = Integer.parseInt(final_next);
}
else {
id = mLatestId;
}
}
catch(Exception e) {
e.printStackTrace();
}
return id;
} }
/**
* Get the previous strip id
* @param url url from which to parse
* @return desired id
*/
private int _getPrevStripId(URI url) {
int id = -1;
try {
BufferedReader reader = Downloader.openConnection(url);
String str;
String final_prev = null;
while ((str = reader.readLine()) != null) {
if(str.indexOf("case 37") != -1) {
final_prev = reader.readLine();
}
}
reader.close();
if(final_prev != null) {
final_prev = final_prev.replaceAll(".*comics/", "");
final_prev = final_prev.replaceAll("/\".*", "");
id = Integer.parseInt(final_prev);
}
else {
id = getFirstId();
}
}
catch(Exception e) {
e.printStackTrace();
}
return id;
}
} }

View File

@ -44,13 +44,6 @@ public class Misfile extends DailyComic {
strip.setTitle("Misfile: " + date); strip.setTitle("Misfile: " + date);
strip.setText("-NA-"); strip.setText("-NA-");
return final_str; return final_str;
/*
String index = url.replaceAll(".*page=", "");
String url_str = "http://www.misfile.com/overlay.php?pageCalled="+index;
strip.setTitle("Misfile: " + index);
strip.setText("-NA-");
return url_str;
*/
} }
@Override @Override
@ -73,7 +66,7 @@ public class Misfile extends DailyComic {
String[] elements = date.split("-"); String[] elements = date.split("-");
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.parseInt(elements[0])); cal.set(Calendar.YEAR, Integer.parseInt(elements[0]));
cal.set(Calendar.MONTH, Integer.parseInt(elements[1])); cal.set(Calendar.MONTH, Integer.parseInt(elements[1])-1);
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(elements[2])); cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(elements[2]));
return cal; return cal;
} }
@ -82,7 +75,7 @@ public class Misfile extends DailyComic {
public String getUrlFromTime(Calendar cal) { public String getUrlFromTime(Calendar cal) {
return String.format("http://www.misfile.com/?date=%04d-%02d-%02d", return String.format("http://www.misfile.com/?date=%04d-%02d-%02d",
cal.get(Calendar.YEAR), cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH), cal.get(Calendar.MONTH)+1,
cal.get(Calendar.DAY_OF_MONTH)); cal.get(Calendar.DAY_OF_MONTH));
} }
} }

View File

@ -3,25 +3,57 @@ package com.blogspot.applications4android.comicreader.comics;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import com.blogspot.applications4android.comicreader.comictypes.IndexedComic; import com.blogspot.applications4android.comicreader.comictypes.RandomIndexedComic;
import com.blogspot.applications4android.comicreader.core.Strip; import com.blogspot.applications4android.comicreader.core.Strip;
import com.blogspot.applications4android.comicreader.exceptions.ComicLatestException; import com.blogspot.applications4android.comicreader.exceptions.ComicLatestException;
public class TheDevilsPanties extends RandomIndexedComic {
public class TheDevilsPanties extends IndexedComic {
@Override @Override
protected String getFrontPageUrl() { protected String getRandUrl() {
return "http://thedevilspanties.com/"; return getStripUrlFromId(getFirstId());
} }
@Override @Override
public String getComicWebPageUrl() { protected int getNextStripId(BufferedReader br, String url) {
return "http://thedevilspanties.com/"; int id = -1;
try {
String str;
String final_next = null;
while ((str = br.readLine()) != null) {
if(str.indexOf("navi navi-next") != -1) {
final_next = str;
}
}
setNextId(parseForNextId(final_next, getLatestId()));
}
catch(Exception e) {
e.printStackTrace();
}
return id;
} }
@Override @Override
protected int parseForLatestId(BufferedReader reader) throws IOException, ComicLatestException { protected int getPreviousStripId(BufferedReader br, String url) {
int id = -1;
try {
String str;
String final_prev = null;
while ((str = br.readLine()) != null) {
if(str.indexOf("navi navi-prev") != -1) {
final_prev = str;
}
}
setPreviousId(parseForPrevId(final_prev, getFirstId()));
}
catch(Exception e) {
e.printStackTrace();
}
return id;
}
@Override
protected int parseForLatestId(BufferedReader reader) throws ComicLatestException, IOException {
String str; String str;
String final_str = null; String final_str = null;
while((str = reader.readLine()) != null) { while((str = reader.readLine()) != null) {
@ -50,38 +82,49 @@ public class TheDevilsPanties extends IndexedComic {
return Integer.parseInt(url.replaceAll("http.*archives/", "")); return Integer.parseInt(url.replaceAll("http.*archives/", ""));
} }
@Override
protected String getFrontPageUrl() {
return "http://thedevilspanties.com/";
}
@Override
public String getComicWebPageUrl() {
return "http://thedevilspanties.com/";
}
@Override @Override
protected boolean htmlNeeded() { protected boolean htmlNeeded() {
return true; return true;
} }
@Override @Override
protected String parse(String url, BufferedReader reader, Strip strip) protected String parse(String url, BufferedReader reader, Strip strip) throws IOException {
throws IOException {
String str; String str;
String final_str = null; String final_str = null;
String final_title = null; String final_title = null;
while ((str = reader.readLine()) != null) { String final_next = null;
int index1 = str.indexOf("comicpane"); String final_prev = null;
if (index1 != -1) { while((str = reader.readLine()) != null) {
if(str.indexOf("comicpane") != -1) {
final_str = str; final_str = str;
final_title = str; final_title = str;
} }
else if(str.indexOf("navi navi-prev") != -1) {
final_prev = str;
}
else if(str.indexOf("navi navi-next") != -1) {
final_next = str;
}
} }
/*
if((final_str == null) || (final_title == null)) {
String msg = "Failed to find the comic for URL="+url;
ComicNotFoundException cnf = new ComicNotFoundException(msg);
throw cnf;
}
*/
final_str = final_str.replaceAll(".*src=\"",""); final_str = final_str.replaceAll(".*src=\"","");
final_str = final_str.replaceAll("\".*",""); final_str = final_str.replaceAll("\".*","");
final_title = final_title.replaceAll(".*alt=\"",""); final_title = final_title.replaceAll(".*alt=\"","");
final_title = final_title.replaceAll("\".*",""); final_title = final_title.replaceAll("\".*","");
strip.setTitle("The Devils Panties: "+final_title); strip.setTitle("The Devils Panties: "+final_title);
strip.setText("-NA-"); strip.setText("-NA-");
// set the next and previous comic IDs from the current url's html data
setNextId(parseForNextId(final_next, -1));
setPreviousId(parseForPrevId(final_prev, -1));
return final_str; return final_str;
} }
@ -89,4 +132,25 @@ public class TheDevilsPanties extends IndexedComic {
protected int getFirstId() { protected int getFirstId() {
return 300; return 300;
} }
@Override
protected int parseForPrevId(String line, int def) {
if(line == null) {
return def;
}
line = line.replaceAll(".*href=\"", "");
line = line.replaceAll("\".*", "");
line = line.replaceAll("/archives/", "");
try {
return Integer.parseInt(line);
}
catch(Exception e) {
return def;
}
}
@Override
protected int parseForNextId(String line, int def) {
return parseForPrevId(line, def);
}
} }

View File

@ -55,7 +55,8 @@ public class ComicClassList {
//// NOTE NOTE NOTE NOTE //// //// NOTE NOTE NOTE NOTE ////
/// Before releasing to market, do remember to set the below flag to 'true'!!!!!!!! /// Before releasing to market, do remember to set the below flag to 'true'!!!!!!!!
/** flag which will tell whether to use the below array to filtering the comics! */ /** flag which will tell whether to use the below array to filtering the comics! */
private static boolean FILTER_COMICS = true; private static boolean FILTER_COMICS = false;
/** list of comics that cannot be shown to the users! */ /** list of comics that cannot be shown to the users! */
private static final String[] FILTER_COMICS_LIST = { "Cyanide and Happiness" }; private static final String[] FILTER_COMICS_LIST = { "Cyanide and Happiness" };