Skip to content

Commit

Permalink
Added *EFP Fanfiction*, some bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
GhostWriterTNCS committed Apr 1, 2017
1 parent 4e1c886 commit 5e0af1f
Show file tree
Hide file tree
Showing 20 changed files with 426 additions and 205 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root=true

[*]
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.h linguist-language=C++

###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Story to ebook
# [Story to ebook](https://github.com/GhostWriterTNCS/StoryToEbook)

Download stories and convert them to ebook.

[>> Download page <<](https://github.com/GhostWriterTNCS/StoryToEbook/releases)

Requires [Calibre](https://calibre-ebook.com/) to convert the stories in ebook.

Supported websites:
* [EFP Fanfiction](http://www.efpfanfic.net/)
* [Wattpad](https://www.wattpad.com/)
9 changes: 9 additions & 0 deletions StoryToEbook.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ 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
88 changes: 88 additions & 0 deletions StoryToEbook/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^\<[^Q][^/.>]*\>'
Priority: -2
- Regex: '^\<'
Priority: -1
- Regex: '^\"'
Priority: 0
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 150
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Always
...
72 changes: 40 additions & 32 deletions StoryToEbook/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,73 @@
#include "MainWindow.h"
#include <iostream>
#include "MyCurl.h"
#include "MyUtils.h"
#include <QDir>
#include <QString>
#include <QTextStream>
#include <QComboBox>
#include <QMessageBox>
#include <QDir>
#include <QFileDialog>
#include <QMessageBox>
#include <QProgressDialog>

//Websites:
#include <QString>
#include <QTextStream>
#include "MainWindow.h"
#include "MyCurl.h"
#include "MyUtils.h"
#include "Website.h"
#include "Wattpad.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
ui.setupUi(this);
ui.comboBox->addItems({ "epub", "mobi", "azw3", "pdf", "html" });
ui.comboBox->addItems({"epub", "mobi", "azw3", "pdf", "html"});
ui.currentDir->setText(QDir::currentPath());
}

void MainWindow::on_downloadAndConvert_clicked()
{
MainWindow::~MainWindow() {
// save options
}

void MainWindow::on_downloadAndConvert_clicked() {
QString url = ui.textEdit->toPlainText().trimmed();
if (url.isEmpty()) {
QMessageBox::warning(this, "Error", "You didn't insert any url!");
return;
}

QString website;
if (url.startsWith("https://www.wattpad.com/")) {
website = "Wattpad";
}

ui.statusBar->showMessage("Download story info...");
QStringList list = Website::downloadStoryInfo(website, url);
ui.statusBar->showMessage("Downloading story info...");
QStringList list = Website::downloadStoryInfo(url);
if (list.size() == 0) {
QMessageBox::warning(this, "Error", "I can't download the story.");
return;
}

QString title = Website::title;
if (title.length() > 30)
title = title.mid(0, 30) + "...";

Website::initializeStory();
for (int i = 0; i < list.size(); i++) {
ui.statusBar->showMessage("Download chapter " + QString::number(i + 1) + " of " + QString::number(list.size()) + "...");
if(!Website::downloadChapter(website, list, i))
QMessageBox::warning(this, "Error", "I can't download capther " + QString::number(i + 1) + ".");
if (list.size() > 1)
ui.statusBar->showMessage(title + " | Downloading chapter " + QString::number(i + 1) +
" of " + QString::number(list.size()) + "...");
else
ui.statusBar->showMessage(title + " | Downloading story...");

if (!Website::downloadChapter(list, i))
QMessageBox::warning(this, "Error",
"I can't download capther " + QString::number(i + 1) + ".");
}

ui.statusBar->showMessage("Creating file...");
QString filename = Website::createEbook(ui.comboBox->currentText().trimmed(), ui.checkBox->isChecked(), ui.currentDir->displayText().trimmed());
ui.statusBar->showMessage(title + " | Creating file...");
QString filename =
Website::createEbook(ui.comboBox->currentText().trimmed(), ui.checkBox->isChecked(),
ui.currentDir->displayText().trimmed());

ui.statusBar->clearMessage();
QMessageBox::information(this, "Ok", "<p><b>Download and conversion complete!</b></p>File saved as <i>" + filename + "</i>", true);
QMessageBox::information(this, "Ok",
"<p><b>Download and conversion complete!</b></p>File saved as <i>" +
filename + "</i>",
true);
ui.textEdit->setPlainText("");
}

void MainWindow::on_directoryButton_clicked()
{
QString folder = QFileDialog::getExistingDirectory(this, tr("Open Directory"), ui.currentDir->displayText(),
void MainWindow::on_directoryButton_clicked() {
QString folder = QFileDialog::getExistingDirectory(
this, tr("Open Directory"), ui.currentDir->displayText(),
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (!folder.isEmpty())
ui.currentDir->setText(folder);
Expand Down
10 changes: 3 additions & 7 deletions StoryToEbook/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
#include <QtWidgets/QMainWindow>
#include "ui_MainWindow.h"

class MainWindow : public QMainWindow
{
class MainWindow : public QMainWindow {
Q_OBJECT

public:
MainWindow(QWidget *parent = Q_NULLPTR);
//~MainWindow();
MainWindow(QWidget* parent = Q_NULLPTR);
~MainWindow();
Ui::MainWindowClass ui;

private slots:
void on_downloadAndConvert_clicked();
void on_directoryButton_clicked();

private:
//void download_story();
};
87 changes: 45 additions & 42 deletions StoryToEbook/MyCurl.cpp
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
#include "MyCurl.h"

namespace MyCurl {
QString html; //will hold the url's contents
size_t writeCallback(char* buf, size_t size, size_t nmemb, void* up) { //callback must have this declaration buf is a pointer to the data
//that curl has for us, size*nmemb is the size of the buffer
for (int c = 0; c<size*nmemb; c++) {
html.push_back(buf[c]);
}
return size*nmemb; //tell curl how many bytes we handled
}
QString urlToString(QString url) {
html = "";
CURL* curl;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);
curl_easy_setopt(curl, CURLOPT_URL, url.toStdString().c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); //tell curl to output its progress
curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_global_cleanup();
return html;
}

QString decodeHtml(QString html) {
html = html.replace("&lsquo;", "");
html = html.replace("&rsquo;", "");
html = html.replace("&ldquo;", "");
html = html.replace("&rdquo;", "");
html = html.replace("&amp;", "&");
html = html.replace("–", "");
html = html.replace("√", "v");
html = html.replace("&#33;", "!");
html = html.replace("&#033;", "!");
html = html.replace("&#38;", "&");
html = html.replace("&#038;", "&");
html = html.replace("&#39;", "'");
html = html.replace("&#039;", "'");
html = html.replace("&#333;", "ō");
html = html.replace("&#8730;", "v");
return html;
std::string html; // will hold the url's contents
size_t writeCallback(char* buf, size_t size, size_t nmemb,
void* up) { // callback must have this declaration buf is a pointer to the data
// that curl has for us, size*nmemb is the size of the buffer
for (int c = 0; c < size * nmemb; c++) {
html.push_back(buf[c]);
}
}
return size * nmemb; // tell curl how many bytes we handled
}
QString urlToString(QString url) {
html = "";
CURL* curl;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);
curl_easy_setopt(curl, CURLOPT_URL, url.toStdString().c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); // tell curl to output its progress
curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_global_cleanup();
return QString::fromLocal8Bit(html.c_str());
}

QString decodeHtml(QString html) {
html = html.replace("&lsquo;", "");
html = html.replace("&rsquo;", "");
html = html.replace("&ldquo;", "");
html = html.replace("&rdquo;", "");
html = html.replace("&amp;", "&");
html = html.replace("–", "");
html = html.replace("√", "v");
html = html.replace("&#33;", "!");
html = html.replace("&#033;", "!");
html = html.replace("&#38;", "&");
html = html.replace("&#038;", "&");
html = html.replace("&#39;", "'");
html = html.replace("&#039;", "'");
html = html.replace("&#333;", "ō");
html = html.replace("&#8730;", "");
return html;
}

} // namspace MyCurl
10 changes: 6 additions & 4 deletions StoryToEbook/MyCurl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "curl/curl.h"

namespace MyCurl {
size_t writeCallback(char* buf, size_t size, size_t nmemb, void* up);
QString urlToString(QString url);
QString decodeHtml(QString html);
}

size_t writeCallback(char* buf, size_t size, size_t nmemb, void* up);
QString urlToString(QString url);
QString decodeHtml(QString html);

} // namespace MyCurl
Loading

0 comments on commit 5e0af1f

Please sign in to comment.