Skip to content

Commit

Permalink
fix: remove hardcoded domain in list script
Browse files Browse the repository at this point in the history
add: Similars Books in popup UI
  • Loading branch information
khanhas committed Feb 1, 2021
1 parent 3424868 commit 653cd3d
Show file tree
Hide file tree
Showing 6 changed files with 992 additions and 883 deletions.
2 changes: 1 addition & 1 deletion backend/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fetch(listURL, fetchOptions).then(res => res.text()).then(html => {
}

return {
url: "https://b-ok.global" + $(ele).find('h3 a').attr('href'),
url: $(ele).find('h3 a').attr('href'),
img: imageUrl,
name: $(ele).find('h3').text().trim(),
author: $(ele).find('div.authors').text().trim(),
Expand Down
20 changes: 13 additions & 7 deletions backend/metadata.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const cheerio = require("cheerio");
const { fetchOptions } = require("./common");
const { domain, fetchOptions } = require("./common");
const fetch = require("node-fetch");

if (process.argv.length < 3) {
console.error("No link");
return;
}
fetch(process.argv[2], fetchOptions).then(a => a.text()).then(html => {
fetch(domain + process.argv[2], fetchOptions).then(a => a.text()).then(html => {
const $ = cheerio.load(html, { _useHtmlParser2: true });

const author = $(`[itemprop="author"]`)
Expand All @@ -30,17 +30,23 @@ fetch(process.argv[2], fetchOptions).then(a => a.text()).then(html => {
description = detail;
}

let downloadURL = $(".dlButton").attr("href");
if (downloadURL === "#") {
downloadURL = "";
let dlUrl = $(".dlButton").attr("href");
if (dlUrl === "#") {
dlUrl = "";
}

const similars = $("#bMosaicBox .brick").get().map(a => ({
url: $(a).find("a").attr("href"),
img: $(a).find("img").attr("src"),
}));

process.stdout.write(JSON.stringify({
name: $("h1").text().trim(),
author,
imgFile: $(".details-book-cover").attr("href"),
img: $(".details-book-cover").attr("href"),
description,
downloadURL,
dlUrl,
similars,
}));
})
.catch(err => {
Expand Down
326 changes: 207 additions & 119 deletions qml/BookPopup.qml
Original file line number Diff line number Diff line change
@@ -1,120 +1,208 @@
import QtQuick 2.5
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.0

Item {
property var model;

property Popup popup: Popup {
id: bookPopup
width: 1000
height: 1300
x: (parent.width / 2) - (width / 2)
y: (parent.height / 2) - (height / 2) + 150
closePolicy: Popup.CloseOnPressOutside
dim: true
Overlay.modeless: Rectangle {
color: "#505050f0"
MouseArea {
anchors.fill: parent
}
}

Image {
id: bookImage
fillMode: Image.PreserveAspectFit
smooth: true
source: model ? model.imgFile : ""
width: 400
height: 400 * 1.5
x: parent.width / 2 - 400 / 2
y: -(parent.height / 2 - height / 2)
ProgressBar {
visible: parent.progress < 1.0
value: parent.progress
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
bottomMargin: 80
}
}
}
Text {
id: bookName
text: model ? model.name : ""
width: parent.width - 90
x: 30
anchors.top: bookImage.bottom
anchors.topMargin: 30
font.family:"Maison Neue"
font.styleName: "Bold"
font.pixelSize: 40
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
}

Text {
id: bookAuthor
text: model ? model.author : ""
width: bookName.width
x: bookName.x
anchors.top: bookName.bottom
anchors.topMargin: 20
font.family:"Maison Neue"
font.styleName: "Medium"
font.pixelSize: 35
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
}

Flickable {
anchors.top: bookAuthor.bottom
anchors.topMargin: 30
anchors.leftMargin: 100
anchors.rightMargin: 100
x: 30
width: bookPopup.width - 80
height: parent.height - bookAuthor.y - bookAuthor.height - 110
contentHeight: bookDesc.height
clip: true
flickableDirection: Flickable.VerticalFlick
boundsBehavior: Flickable.StopAtBounds

Text {
id: bookDesc
textFormat: Text.RichText
text: model ? model.desc : ""
font.family:"EB Garamond"
font.styleName: "Medium"
font.pixelSize: 30
width: parent.width
wrapMode: Text.Wrap
}
}

Rectangle {
width: 300
height: 80
x: parent.width - 260
y: parent.height - 30
color: "black"
Text {
anchors.centerIn: parent
text: !model || !model.dlUrl ? "Unavailable" : model.status
font.family:"Maison Neue"
font.styleName: "Medium"
font.pixelSize: 30
color: "white"
}
MouseArea {
anchors.fill: parent
onClicked: {
if(!model || !model.dlUrl || model.status !== "Download") {
return
}
model.download();
}
}
}
}
import QtQuick 2.5
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.11

Item {
id: popupRoot
property var model;
property bool isBusy;

property Popup popup: Popup {
id: bookPopup
width: 1000
height: 1300
x: (parent.width / 2) - (width / 2)
y: (parent.height / 2) - (height / 2) + 150
closePolicy: Popup.CloseOnPressOutside
dim: true
padding: 40

Overlay.modeless: Rectangle {
color: "#90505050"
MouseArea {
anchors.fill: parent
}
}

onOpened: bar.currentIndex = 0;

contentChildren: [
Image {
id: bookImage
fillMode: Image.PreserveAspectFit
smooth: true
source: model ? model.imgFile : ""
width: 400
height: 400 * 1.5
anchors.horizontalCenter: parent.horizontalCenter
y: -(parent.height / 2 - height / 2)
ProgressBar {
visible: parent.progress < 1.0
value: parent.progress
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
bottomMargin: 80
}
}
},
Text {
id: bookName
text: model ? model.name : ""
anchors {
left: parent.left; right: parent.right
top: bookImage.bottom
topMargin: 30
}
font.family:"Maison Neue"
font.styleName: "Bold"
font.pixelSize: 40
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
},
Text {
id: bookAuthor
text: model ? model.author : ""
anchors {
left: parent.left; right: parent.right
top: bookName.bottom
topMargin: 20
}
font.family:"Maison Neue"
font.styleName: "Medium"
font.pixelSize: 35
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
},
TabBar {
id: bar
visible: !isBusy
anchors {
left: parent.left; right: parent.right
top: bookAuthor.bottom
topMargin: 30
}
font.pixelSize: 25
TabButton {
contentItem: Label {
text: "Details"
color: bar.currentIndex == 0 ? "black" : "gray"
font.underline: bar.currentIndex == 0
horizontalAlignment: Text.AlignHCenter
}
background: Rectangle {}
}
TabButton {
contentItem: Label {
text: "Similar books"
color: bar.currentIndex == 1 ? "black" : "gray"
font.underline: bar.currentIndex == 1
horizontalAlignment: Text.AlignHCenter
}
background: Rectangle {}
}
},
StackLayout {
id: stack
anchors {
left: parent.left; right: parent.right
top: bar.bottom
topMargin: 30
bottom: parent.bottom
bottomMargin: 30
}
currentIndex: bar.currentIndex
Item {
Flickable {
anchors.fill: parent
contentHeight: bookDesc.height
clip: true
flickableDirection: Flickable.VerticalFlick
boundsBehavior: Flickable.StopAtBounds

Text {
id: bookDesc
textFormat: Text.RichText
text: model ? model.desc : ""
font.family:"EB Garamond"
font.styleName: "Medium"
font.pixelSize: 30
width: parent.width
wrapMode: Text.Wrap
}
}
}
Item {
GridView {
id: recGrid
anchors.fill: parent
boundsBehavior: Flickable.StopAtBounds
cellHeight: stack.height / 2
cellWidth: cellHeight / 1.5
model: popupRoot.model ? popupRoot.model.similars : []
flickableDirection: Flickable.HorizontalFlick
flow: GridView.TopToBottom
clip: true
snapMode: GridView.SnapToRow
flickDeceleration: 0
delegate: Item {
id: itemRoot
width: recGrid.cellWidth
height: recGrid.cellHeight
Image {
id: image
fillMode: Image.PreserveAspectCrop
source: model.modelData.imgFile
anchors.fill: itemRoot
anchors.margins: 10
}
MouseArea {
anchors.fill: itemRoot
onClicked: {
model.modelData.getDetail(popupRoot);
bar.currentIndex = 0;
popupRoot.model = model.modelData;
}
}
}
}
}
},
Image {
z: 1
source: "png/loading"
visible: isBusy
width: 60
height: 60
anchors.centerIn: parent
}
]

Rectangle {
id: download
visible: !isBusy
width: 300
height: 80
x: parent.width - 220
y: parent.height
color: "black"
Text {
anchors.centerIn: parent
text: !model || !model.dlUrl ? "Unavailable" : model.status
font.family:"Maison Neue"
font.styleName: "Medium"
font.pixelSize: 30
color: "white"
}
MouseArea {
anchors.fill: parent
onClicked: {
if(!model || !model.dlUrl || model.status !== "Download") {
return
}
model.download();
}
}
}
}
}
Loading

0 comments on commit 653cd3d

Please sign in to comment.