Skip to content

Commit

Permalink
Bugfix.
Browse files Browse the repository at this point in the history
  • Loading branch information
GhostWriterTNCS committed Apr 29, 2017
1 parent 7729583 commit edd8e52
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 58 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Requires [Calibre](https://calibre-ebook.com/) to convert the stories in ebook.

### Release notices

Made with [Qt5.8](https://www.qt.io/download-open-source/)
Made with [Qt5.8](https://www.qt.io/download-open-source/)
9 changes: 0 additions & 9 deletions StoryToEbook.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StoryToEbook", "StoryToEbook\StoryToEbook.vcxproj", "{B12702AD-ABFB-343A-A199-8E24837244A3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{09262069-B147-4887-8004-9621DA64B5FB}"
ProjectSection(SolutionItems) = preProject
.gitattributes = .gitattributes
.gitignore = .gitignore
curl LICENSE.txt = curl LICENSE.txt
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Expand Down
2 changes: 1 addition & 1 deletion StoryToEbook/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <QString>
#include <QTextStream>
#include "MainWindow.h"
#include "MyQtUtils.h"
#include "MyUtils.h"
#include "Website.h"

// Websites:
Expand Down
2 changes: 1 addition & 1 deletion StoryToEbook/MyCurl
Submodule MyCurl updated 2 files
+7 −3 MyCurl.cpp
+1 −1 README.md
6 changes: 3 additions & 3 deletions StoryToEbook/MyQtUtils.cpp → StoryToEbook/MyUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "MyCurl.h"
#include "MyQtUtils.h"
#include "MyUtils.h"

namespace MyQtUtils {
namespace MyUtils {

QString readFile(QString filename) {
QFile file(filename);
Expand Down Expand Up @@ -65,4 +65,4 @@ QString redirectedUrlQt(QString url) {
return QString::fromLocal8Bit(MyCurl::redirectedUrl(url.toStdString()).c_str());
}

} // namespace MyQtUtils
} // namespace MyUtils
4 changes: 2 additions & 2 deletions StoryToEbook/MyQtUtils.h → StoryToEbook/MyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QString>
#include <QTextStream>

namespace MyQtUtils {
namespace MyUtils {

QString readFile(QString filename);
QString validateFilename(QString filename);
Expand All @@ -16,4 +16,4 @@ QString advancedReplace(QString str, QString startReplace, QString endReplace, Q
QString urlToQString(QString url);
QString redirectedUrlQt(QString url);

} // namespace MyQtUtils
} // namespace MyUtils
4 changes: 2 additions & 2 deletions StoryToEbook/StoryToEbook.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<ClCompile Include="main.cpp" />
<ClCompile Include="MainWindow.cpp" />
<ClCompile Include="MyCurl\MyCurl.cpp" />
<ClCompile Include="MyQtUtils.cpp" />
<ClCompile Include="MyUtils.cpp" />
<ClCompile Include="QtGeneratedFiles\Debug\moc_MainWindow.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
Expand Down Expand Up @@ -127,7 +127,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="MyCurl\MyCurl.h" />
<ClInclude Include="MyQtUtils.h" />
<ClInclude Include="MyUtils.h" />
<ClInclude Include="QtGeneratedFiles\ui_MainWindow.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Website.h" />
Expand Down
8 changes: 4 additions & 4 deletions StoryToEbook/StoryToEbook.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
<ClCompile Include="websites\EFP.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MyQtUtils.cpp">
<ClCompile Include="MyCurl\MyCurl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MyCurl\MyCurl.cpp">
<ClCompile Include="MyUtils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down Expand Up @@ -98,10 +98,10 @@
<ClInclude Include="websites\EFP.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MyQtUtils.h">
<ClInclude Include="MyCurl\MyCurl.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MyCurl\MyCurl.h">
<ClInclude Include="MyUtils.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions StoryToEbook/Website.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <QFileInfo>
#include "MyQtUtils.h"
#include "MyUtils.h"
#include "Wattpad.h"
#include "Website.h"

Expand All @@ -17,15 +17,15 @@ QString Website::createEbook(QString extension, bool downloadCover, QString fold
folder = folder.replace("/", "\\");
}

Website::title = MyQtUtils::validateFilename(Website::title);
Website::title = MyUtils::validateFilename(Website::title);
if (extension == "html") {
MyQtUtils::writeFile(Website::title + ".html", Website::story);
MyUtils::writeFile(Website::title + ".html", Website::story);
} else {
int i = 0;
QFile file;
while (file.exists(QString::number(i) + ".htm"))
i++;
MyQtUtils::writeFile(QString::number(i) + ".htm", Website::story);
MyUtils::writeFile(QString::number(i) + ".htm", Website::story);

if (downloadCover && !Website::cover.isEmpty()) {
Website::cover = Website::cover.replace(" ", "%20");
Expand Down
24 changes: 12 additions & 12 deletions StoryToEbook/websites/EFP.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include "EFP.h"
#include "MyQtUtils.h"
#include "MyUtils.h"

void EFP::downloadStoryInfo(QString url) {
if (url.contains("sid=")) {
QString id = MyQtUtils::substring(url, "sid=", "&");
QString id = MyUtils::substring(url, "sid=", "&");
url = "http://www.efpfanfic.net/viewstory.php?sid=" + id;

QString s = MyQtUtils::urlToQString(url);
Website::intro = MyQtUtils::substring(s, "<div id=\"anteprima\">", "</div>");
QString s = MyUtils::urlToQString(url);
Website::intro = MyUtils::substring(s, "<div id=\"anteprima\">", "</div>");
Website::intro = "\n\n<center><p class=\"titolo\">Introduzione<br> *** </p></center>\n<p>" +
Website::intro + "</p><br><br>\n";
Website::title =
MyQtUtils::substring(s, "<a href=\"viewstory.php?sid=" + id + "\">", "</a>");
MyUtils::substring(s, "<a href=\"viewstory.php?sid=" + id + "\">", "</a>");

if (s.contains("printsave.php?action=printall&sid="))
list.append("http://www.efpfanfic.net/printsave.php?action=printall&sid=" + id);
Expand All @@ -24,15 +24,15 @@ void EFP::downloadStoryInfo(QString url) {
}

bool EFP::downloadChapter(int chapterIndex) {
QString s = MyQtUtils::urlToQString(list[chapterIndex]);
QString s = MyUtils::urlToQString(list[chapterIndex]);
s.replace(s.indexOf("***</p></center><br>") + 21, 15, "");
s.replace(s.indexOf("</b></center><br><br>") + 21, 0, Website::intro);

Website::author = s;
Website::author = MyQtUtils::substring(Website::author, "uid=", "</a>");
Website::author = MyQtUtils::substring(Website::author, ">");
Website::author = MyUtils::substring(Website::author, "uid=", "</a>");
Website::author = MyUtils::substring(Website::author, ">");

s = MyQtUtils::advancedReplace(s, "</title><table width=\"100%\"", "<center><p class=\"title",
s = MyUtils::advancedReplace(s, "</title><table width=\"100%\"", "<center><p class=\"title",
"</title><center><p class=\"title");
s = s.replace("</td></tr></table>\n<p align=\"right\"><big><a href=\"#top\">Ritorna "
"all'indice</a></big></p><hr>",
Expand All @@ -46,11 +46,11 @@ bool EFP::downloadChapter(int chapterIndex) {
s;

if (s.contains("<img ")) {
Website::cover = MyQtUtils::substring(s, "<img ", ">");
Website::cover = MyUtils::substring(s, "<img ", ">");
if (Website::cover.contains("src='"))
Website::cover = MyQtUtils::substring(Website::cover, "src='", "'");
Website::cover = MyUtils::substring(Website::cover, "src='", "'");
else
Website::cover = MyQtUtils::substring(Website::cover, "src=\"", "\"");
Website::cover = MyUtils::substring(Website::cover, "src=\"", "\"");
}

return true;
Expand Down
38 changes: 19 additions & 19 deletions StoryToEbook/websites/Wattpad.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "MyQtUtils.h"
#include "MyUtils.h"
#include "Wattpad.h"

void Wattpad::downloadStoryInfo(QString url) {
if (url[24].isDigit()) {
url = MyQtUtils::urlToQString(url);
url = MyUtils::urlToQString(url);
if (!url.contains("data-story-id=\"")) {
return;
}
url = MyQtUtils::substring(url, "data-story-id=\"", "\"");
url = MyUtils::substring(url, "data-story-id=\"", "\"");
url = "https://www.wattpad.com/story/" + url + "/parts";
} else if (!url.startsWith("https://www.wattpad.com/story/")) {
return;
Expand All @@ -16,52 +16,52 @@ void Wattpad::downloadStoryInfo(QString url) {
if (!url.contains("/parts")) {
url += "/parts";
}
QString caps = MyQtUtils::urlToQString(url);
QString caps = MyUtils::urlToQString(url);

if (!caps.isEmpty()) {
Website::intro =
(MyQtUtils::substring(caps, "<h2 class=\"description\"><pre>", "</pre>")).trimmed();
(MyUtils::substring(caps, "<h2 class=\"description\"><pre>", "</pre>")).trimmed();
Website::intro = "<div style='text-align:justify'><p>" +
Website::intro.replace("\n", "</p><p>") + "</p></div>";
Website::title = (MyQtUtils::substring(caps, "<h1>", "</h1>")).trimmed();
Website::title = (MyUtils::substring(caps, "<h1>", "</h1>")).trimmed();
Website::title = Website::title.replace("&#x27;", "'");

Website::author = MyQtUtils::substring(caps, "author-info", "</div>");
Website::author = MyUtils::substring(caps, "author-info", "</div>");
Website::author =
(MyQtUtils::substring(Website::author, "<a href=\"/user/", "\"")).trimmed();
(MyUtils::substring(Website::author, "<a href=\"/user/", "\"")).trimmed();

Website::cover = MyQtUtils::substring(caps, "cover cover-lg", "</div>");
Website::cover = MyQtUtils::substring(Website::cover, "src=\"", "\"");
Website::cover = MyUtils::substring(caps, "cover cover-lg", "</div>");
Website::cover = MyUtils::substring(Website::cover, "src=\"", "\"");

caps = MyQtUtils::substring(caps, "class=\"table-of-contents\"", "</ul>");
caps = MyUtils::substring(caps, "class=\"table-of-contents\"", "</ul>");
list = caps.split("</li>");
list.removeLast();
for (int i = 0; i < list.size(); i++) {
list[i] = "https://www.wattpad.com" + MyQtUtils::substring(list[i], "<a href=\"", "\"");
list[i] = "https://www.wattpad.com" + MyUtils::substring(list[i], "<a href=\"", "\"");
}
return;
}
return;
}

bool Wattpad::downloadChapter(int chapterIndex) {
QString temp = MyQtUtils::urlToQString(list[chapterIndex]);
QString temp = MyUtils::urlToQString(list[chapterIndex]);
QString s = "<h1 style=\"text-align: center;\">" +
(MyQtUtils::substring(temp, "<h2>", "</h2>")).trimmed() + "</h1>\n";
(MyUtils::substring(temp, "<h2>", "</h2>")).trimmed() + "</h1>\n";
int p = 2;
while (temp.contains("data-page-number=")) {
temp = MyQtUtils::substring(temp, "data-page-number=", "</div>");
temp = MyUtils::substring(temp, "data-page-number=", "</div>");
if (!temp.contains("</pre>")) {
return false;
}
s += MyQtUtils::substring(temp, "<pre>", "</pre>") + "\n";
if (!MyQtUtils::substring(temp, "", "<pre>").contains("last-page")) {
temp = MyQtUtils::urlToQString(list[chapterIndex] + "/page/" + QString::number(p));
s += MyUtils::substring(temp, "<pre>", "</pre>") + "\n";
if (!MyUtils::substring(temp, "", "<pre>").contains("last-page")) {
temp = MyUtils::urlToQString(list[chapterIndex] + "/page/" + QString::number(p));
p++;
} else
break;
}
s = MyQtUtils::advancedReplace(s, "<p data-p-id=", ">", "<p>");
s = MyUtils::advancedReplace(s, "<p data-p-id=", ">", "<p>");
s = s.replace(" <p", "<p");
Website::story += s + "\n</div>\n";
return true;
Expand Down

0 comments on commit edd8e52

Please sign in to comment.