Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

add 420chan support #782

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.floens.chan.core.site.sites.arisuchan.Arisuchan;
import org.floens.chan.core.site.sites.chan4.Chan4;
import org.floens.chan.core.site.sites.chan420.Chan420;
import org.floens.chan.core.site.sites.chan8.Chan8;
import org.floens.chan.core.site.sites.dvach.Dvach;
import org.floens.chan.core.site.sites.lainchan.Lainchan;
Expand All @@ -38,6 +39,7 @@ public class SiteRegistry {

static {
URL_HANDLERS.add(Chan4.URL_HANDLER);
URL_HANDLERS.add(Chan420.URL_HANDLER);
URL_HANDLERS.add(Chan8.URL_HANDLER);
URL_HANDLERS.add(Lainchan.URL_HANDLER);
URL_HANDLERS.add(Arisuchan.URL_HANDLER);
Expand All @@ -56,5 +58,6 @@ public class SiteRegistry {
SITE_CLASSES.put(3, Arisuchan.class);
SITE_CLASSES.put(4, Sushichan.class);
SITE_CLASSES.put(5, Dvach.class);
SITE_CLASSES.put(6, Chan420.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Clover - 4chan browser https://github.com/Floens/Clover/
* Copyright (C) 2014 Floens
*
* 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
* (at your option) 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 org.floens.chan.core.site.common.taimaba;

import org.floens.chan.core.site.SiteAuthentication;
import org.floens.chan.core.site.common.CommonSite;
import org.floens.chan.core.site.common.MultipartHttpCall;
import org.floens.chan.core.site.http.Reply;
import org.floens.chan.core.site.http.ReplyResponse;
import org.jsoup.Jsoup;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import okhttp3.Response;

import static android.text.TextUtils.isEmpty;

public class TaimabaActions extends CommonSite.CommonActions {
public TaimabaActions(CommonSite commonSite) {
super(commonSite);
}

int threadNo = 0;
String password = null;

@Override
public void setupPost(Reply reply, MultipartHttpCall call) {
//pass threadNo & password with correct variables
threadNo = reply.loadable.no;
password = reply.password;

call.parameter("fart", Integer.toString((int) Math.random() * 15000 + 5000));

call.parameter("board", reply.loadable.board.code);
call.parameter("task", "post");

if (reply.loadable.isThreadMode()) {
call.parameter("parent", String.valueOf(reply.loadable.no));
}

call.parameter("password", reply.password);
call.parameter("field1", reply.name);

if (!isEmpty(reply.subject)) {
call.parameter("field3", reply.subject);
}

call.parameter("field4", reply.comment);

if (reply.file != null) {
call.fileParameter("file", reply.fileName, reply.file);
}

if (reply.options.equals("sage")) {
call.parameter("sage", "on");
}
}

@Override
public void handlePost(ReplyResponse replyResponse, Response response, String result) {
Matcher err = errorPattern().matcher(result);
if (err.find()) {
replyResponse.errorMessage = Jsoup.parse(err.group(1)).body().text();
} else {
replyResponse.threadNo = threadNo;
replyResponse.password = password;
replyResponse.posted = true;
}
}

public Pattern errorPattern() {
return Pattern.compile("<pre.*?>([\\s\\S]*?)</pre>");
}

@Override
public SiteAuthentication postAuthenticate() {
return SiteAuthentication.fromNone();
}
}
Loading