added Menage a 3 to the list of comics also updated the alphabetical order of MegaTokyo.

This commit is contained in:
C. Albert 2013-01-07 14:31:48 -08:00
parent 88df90ca62
commit acb4ac1671
2 changed files with 173 additions and 1 deletions

View File

@ -32,6 +32,8 @@
{"class":"JoeAndMonkey", "name":"Joe And Monkey", "pref":"joeandmonkeyPref"},
{"class":"LeastICouldDo", "name":"Least I Could Do", "pref":"leasticoulddoPref"},
{"class":"LookingForGroup", "name":"Looking For Group", "pref":"lookingforgroupPref"},
{"class":"MegaTokyo", "name":"MegaTokyo", "pref":"megatokyoPref", "new":"1"},
{"class":"MenageA3", "name":"Menage a 3", "pref":"menagea3Pref", "new":"1"},
{"class":"Misfile", "name":"Misfile", "pref":"misfilePref"},
{"class":"MotherGooseandGrimm", "name":"Mother Goose & Grimm", "pref":"mothergooseandgrimmPref"},
{"class":"OOTS", "name":"Order of the Stick", "pref":"ootsPref"},
@ -60,7 +62,6 @@
{"class":"Wondermark", "name":"Wondermark", "pref":"wondermarkPref"},
{"class":"Wulffmorgenthaler", "name":"Wulffmorgenthaler", "pref":"wulffmorgenthalerPref"},
{"class":"Xkcd", "name":"Xkcd", "pref":"xkcdPref"},
{"class":"MegaTokyo", "name":"MegaTokyo", "pref":"megatokyoPref", "new":"1"},
{"class":"Yafgc", "name":"Yet Another Fantasy Gamer Comic", "pref":"yafgcPref"},
{"class":"Zap", "name":"Zap!", "pref":"zapPref"},
{"class":"Channelate", "name":"Channelate", "pref":"channelatePref"},

View File

@ -0,0 +1,171 @@
package com.blogspot.applications4android.comicreader.comics;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.blogspot.applications4android.comicreader.comictypes.ArchivedComic;
import com.blogspot.applications4android.comicreader.core.Bound;
import com.blogspot.applications4android.comicreader.core.Downloader;
import com.blogspot.applications4android.comicreader.core.Strip;
//This comic does not have numbers to work with each URL is the title of the comic.
//So we will use the archive to get the comics is order.
public class MenageA3 extends ArchivedComic {
@Override
public String getComicWebPageUrl() {
return "http://www.ma3comic.com/strips-ma3/";
}
@Override
protected String[] getAllComicUrls(BufferedReader reader)
throws IOException {
ArrayList<String> m_com = new ArrayList<String>();
String str, str_temp;
String search = "http://www.ma3comic.com/strips-ma3";
int i;
while ((str = reader.readLine()) != null) {
i = str.indexOf(search);
if (i != -1) {
if (!str.contains("ARCHIVE")) {
str_temp = str;
str_temp = str_temp.replaceAll(".*?href=\"", "");
;
str_temp = str_temp.replaceAll("\".*$", "");
m_com.add(str_temp);
}
}
}
String[] m_com_urls = new String[m_com.size()];
m_com.toArray(m_com_urls);
return m_com_urls;
}
@Override
protected void fetchAllComicUrls() {
if (mComicUrls == null) {
try {
ArrayList<String> all_vols = new ArrayList<String>();
// Archive has volumes that update no according to calendar
// So find number of archives first.
ArrayList<String> vol_urls = getNumOfVols();
for (String currentVol : vol_urls) {
URI u = null;
try {
u = new URI(currentVol);
} catch (Exception e) {
} // This should never occur!!
BufferedReader reader = Downloader.openConnection(u);
String[] urls = getAllComicUrls(reader);
for (int i = 0; i <= urls.length - 1; i++) {
all_vols.add(urls[i]);
}
reader.close();
}
mComicUrls = new String[all_vols.size()];
all_vols.toArray(mComicUrls);
} catch (Exception e) {
e.printStackTrace();
return;
}
}
mBound = new Bound(0, (long) (mComicUrls.length - 1));
}
private ArrayList<String> getNumOfVols() {
String str;
String search = "http://www.menagea3.net/archive/volume";
String mArchiveStr = "http://www.ma3comic.com/archive";
ArrayList<String> vol_urls = new ArrayList<String>();
Pattern p = Pattern.compile(search + "\\d");
try {
URI u = null;
try {
u = new URI(mArchiveStr);
} catch (Exception e) {
} // This should never occur!!
BufferedReader reader = Downloader.openConnection(u);
int i;
while ((str = reader.readLine()) != null) {
i = str.indexOf(search);
if (i != -1) {
Matcher m = p.matcher(str);
while (m.find()) {
if (!vol_urls.contains(m.group())) {
vol_urls.add(m.group());
}
}
}
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
return vol_urls;
}
return vol_urls;
}
private int countOccurrences(String str, String pattern) {
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(str);
int count = 0;
while (m.find()) {
count += 1;
}
return count;
}
@Override
protected String getLatestStripUrl() {
fetchAllComicUrls();
return getStripUrlFromId(mComicUrls.length - 1);
}
@Override
protected String getArchiveUrl() {
return "http://www.ma3comic.com/archive/volume";
}
@Override
protected boolean htmlNeeded() {
return true;
}
@Override
protected String parse(String url, BufferedReader reader, Strip strip)
throws IOException {
String str;
String final_str = null;
String final_title = null;
while ((str = reader.readLine()) != null) {
// This gets the location of the image
int index1 = str.indexOf("comics/mat");
if (index1 != -1) {
final_str = str;
}
// This gets the location of the title
int index2 = str.indexOf("<title>M&eacute;nage");
if (index2 != -1) {
final_title = str;
}
}
// Pattern matching to remove unwanted characters.
final_str = final_str.replaceAll(".*img src=\"", "");
final_str = final_str.replaceAll("\".*", "");
final_title = final_title.replaceAll(".*.::", "");
final_title = final_title.replaceAll("</title>.*", "");
strip.setTitle("Ménage à 3 :" + final_title);
return final_str;
}
}