77import org .jsoup .nodes .Element ;
88import org .jsoup .select .Elements ;
99
10+ import java .io .File ;
11+ import java .util .ArrayList ;
1012import java .util .HashMap ;
13+ import java .util .List ;
1114
1215import open .furaffinity .client .abstractClasses .abstractPage ;
1316
1417public class submitSubmissionPart2 extends open .furaffinity .client .abstractClasses .abstractPage {
15- private static String pagePath = "/submit/" ;
18+ private static final String pagePath = "/submit/upload /" ;
1619
17- private HashMap < String , String > params = new HashMap <>() ;
18- private open . furaffinity . client . submitPages . submitSubmissionPart1 submitSubmissionPart1 ;
20+ private final String sourceFilePath ;
21+ private final String thumbnailFilePath ;
1922
20- public submitSubmissionPart2 (Context context , abstractPage .pageListener pageListener , open .furaffinity .client .submitPages .submitSubmissionPart1 submitSubmissionPart1 ) {
23+ private String submissionKey = "" ;
24+ private HashMap <String , String > rating = new HashMap <>();
25+ private HashMap <String , String > cat = new HashMap <>();
26+ private HashMap <String , String > aType = new HashMap <>();
27+ private HashMap <String , String > species = new HashMap <>();
28+ private HashMap <String , String > gender = new HashMap <>();
29+
30+ private final open .furaffinity .client .submitPages .submitSubmissionPart1 submitSubmissionPart1 ;
31+
32+ public submitSubmissionPart2 (Context context , abstractPage .pageListener pageListener , open .furaffinity .client .submitPages .submitSubmissionPart1 submitSubmissionPart1 , String sourceFilePath , String thumbnailFilePath ) {
2133 super (context , pageListener );
2234 this .submitSubmissionPart1 = submitSubmissionPart1 ;
35+ this .sourceFilePath = sourceFilePath ;
36+ this .thumbnailFilePath = thumbnailFilePath ;
2337 }
2438
2539 public static String getPagePath () {
@@ -28,30 +42,80 @@ public static String getPagePath() {
2842
2943 @ Override
3044 protected Boolean processPageData (String html ) {
45+ boolean result = true ;
3146 Document doc = Jsoup .parse (html );
3247
33- Element myformForm = doc .selectFirst ("form[name=myform]" );
34-
35- if (myformForm != null ) {
36- params = new HashMap <>();
37-
38- Elements hiddenInputs = myformForm .select ("input[type=hidden]" );
48+ Element finalizeForm = doc .selectFirst ("form[id=myform]" );
49+ if (finalizeForm != null ) {
50+ Element keyInput = finalizeForm .selectFirst ("input[name=key]" );
51+ if (keyInput != null ) {
52+ submissionKey = keyInput .attr ("value" );
53+ } else {
54+ result = false ;
55+ }
56+ } else {
57+ result = false ;
58+ }
3959
40- if (hiddenInputs != null ) {
41- for (Element hiddenInput : hiddenInputs ) {
42- params .put (hiddenInput .attr ("name" ), hiddenInput .attr ("value" ));
60+ Element catSelect = doc .selectFirst ("select[name=cat]" );
61+ Element atypeSelect = doc .selectFirst ("select[name=atype]" );
62+ Element speciesSelect = doc .selectFirst ("select[name=species]" );
63+ Element genderSelect = doc .selectFirst ("select[name=gender]" );
64+ Elements ratingInputs = doc .select ("input[name=rating]" );
65+
66+ cat = open .furaffinity .client .utilities .html .getDropDownOptions (catSelect );
67+ aType = open .furaffinity .client .utilities .html .getDropDownOptions (atypeSelect );
68+ species = open .furaffinity .client .utilities .html .getDropDownOptions (speciesSelect );
69+ gender = open .furaffinity .client .utilities .html .getDropDownOptions (genderSelect );
70+
71+ if (ratingInputs != null ) {
72+ for (Element ratingInput : ratingInputs ) {
73+ Element nextDiv = ratingInput .nextElementSibling ();
74+ if (nextDiv != null ) {
75+ rating .put (ratingInput .attr ("value" ), nextDiv .text ());
4376 }
44- return true ;
4577 }
4678 }
47- return false ;
79+
80+ return result ;
4881 }
4982
5083 @ Override
5184 protected Boolean doInBackground (Void ... voids ) {
52- HashMap <String , String > postParams = new HashMap <>();
53- postParams .put ("part" , "2" );
54- postParams .put ("submission_type" , submitSubmissionPart1 .getSubmissionTypeCurrent ());
85+ HashMap <String , String > simplePostParams = new HashMap <>();
86+ simplePostParams .put ("MAX_FILE_SIZE" , submitSubmissionPart1 .getMaxFileSize ());
87+ simplePostParams .put ("key" , submitSubmissionPart1 .getSubmissionKey ());
88+ simplePostParams .put ("submission_type" , submitSubmissionPart1 .getSubmissionTypeCurrent ());
89+
90+ List <HashMap <String , String >> postParams = new ArrayList <>();
91+
92+ for (String key : simplePostParams .keySet ()) {
93+ HashMap <String , String > newParam = new HashMap <>();
94+ newParam .put ("name" , key );
95+ newParam .put ("value" , simplePostParams .get (key ));
96+ postParams .add (newParam );
97+ }
98+
99+ File sourceFile = new File (sourceFilePath );
100+ if (sourceFile .exists ()) {
101+ HashMap <String , String > newParam = new HashMap <>();
102+ newParam .put ("name" , "submission" );
103+ newParam .put ("filePath" , sourceFile .getPath ());
104+ postParams .add (newParam );
105+ }
106+
107+ File thumbnailFile = new File (thumbnailFilePath );
108+ if (thumbnailFile .exists ()) {
109+ HashMap <String , String > newParam = new HashMap <>();
110+ newParam .put ("name" , "thumbnail" );
111+ newParam .put ("filePath" , thumbnailFile .getPath ());
112+ postParams .add (newParam );
113+ } else {
114+ HashMap <String , String > newParam = new HashMap <>();
115+ newParam .put ("name" , "thumbnail" );
116+ newParam .put ("filePath" , "" );
117+ postParams .add (newParam );
118+ }
55119
56120 String html = webClient .sendPostRequest (open .furaffinity .client .utilities .webClient .getBaseUrl () + pagePath , postParams );
57121 if (webClient .getLastPageLoaded () && html != null ) {
@@ -60,7 +124,25 @@ protected Boolean doInBackground(Void... voids) {
60124 return false ;
61125 }
62126
63- public HashMap <String , String > getParams () {
64- return params ;
127+ public String getSubmissionKey () { return submissionKey ; }
128+
129+ public HashMap <String , String > getCat () {
130+ return cat ;
131+ }
132+
133+ public HashMap <String , String > getaType () {
134+ return aType ;
135+ }
136+
137+ public HashMap <String , String > getSpecies () {
138+ return species ;
139+ }
140+
141+ public HashMap <String , String > getGender () {
142+ return gender ;
143+ }
144+
145+ public HashMap <String , String > getRating () {
146+ return rating ;
65147 }
66148}
0 commit comments