Skip to content

Commit

Permalink
fix bilibili search
Browse files Browse the repository at this point in the history
  • Loading branch information
AncientLysine committed Mar 20, 2016
1 parent f3aad30 commit 7b6d256
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 94 deletions.
45 changes: 21 additions & 24 deletions src/Access/Seek.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ namespace
iter->setEditable(false);
}
}

QString toRichText(QString text)
{
return text.isEmpty() ? text : Qt::convertFromPlainText(text);
}
}

Seek::Seek(QObject *parent) : QObject(parent), d_ptr(new SeekPrivate(this))
Expand Down Expand Up @@ -167,7 +162,7 @@ Seek::Seek(QObject *parent) : QObject(parent), d_ptr(new SeekPrivate(this))

const QByteArray &data = reply->readAll();
auto page = QTextCodec::codecForHtml(data, QTextCodec::codecForName("UTF-8"))->toUnicode(data);
QStringList list = page.split("<li class=\"list", QString::SkipEmptyParts);
QStringList list = page.split("<li class=\"video", QString::SkipEmptyParts);

if (list.isEmpty()) {
emit stateChanged(task.state = None);
Expand All @@ -179,12 +174,9 @@ Seek::Seek(QObject *parent) : QObject(parent), d_ptr(new SeekPrivate(this))
QRegularExpressionMatch m;
r.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);

QStringList bang = list.takeFirst().split("<div class=\"list\">");
QString type;
QStringList bang = list.takeFirst().split("<li class=\"synthetical");
if (bang.size() > 0) {
r.setPattern("(?<=<h2 class=\"main\">).*?(?=</h2>)");
m = r.match(bang.takeFirst());
type = Utils::decodeXml(m.captured());
bang.removeFirst();
}
for (const QString &item : bang) {
QList<QStandardItem *> line;
Expand All @@ -207,11 +199,12 @@ Seek::Seek(QObject *parent) : QObject(parent), d_ptr(new SeekPrivate(this))
m = r.match(item, m.capturedEnd());
line[3]->setText(Utils::decodeXml(m.captured().trimmed()));

r.setPattern("(?<=<p>).*?(?=</p>)");
m = r.match(item, m.capturedEnd());
line[3]->setToolTip(toRichText(Utils::decodeXml(m.captured())));

line[4]->setText(type);
r.setPattern("(?<=>).*?(?=</div>)");
m = r.match(item, item.indexOf("class=\"des", m.capturedEnd()));
QString d = m.captured().trimmed();
d.replace("<em class=\"keyword\">", "<font color=red>").replace("</em>", "</font>");
d = "<p>" + d + "</p>";
line[3]->setToolTip(d);

disableEditing(line);
task.model->appendRow(line);
Expand All @@ -238,16 +231,20 @@ Seek::Seek(QObject *parent) : QObject(parent), d_ptr(new SeekPrivate(this))
request.setAttribute(QNetworkRequest::User, (quintptr)line[0]);
d->remain += d->manager.get(request);

r.setPattern("(?<=>).*?(?=</a>)");
m = r.match(item, item.indexOf("<a class=\"tag", m.capturedEnd()));
r.setPattern("(?<=>).*?(?=</span>)");
m = r.match(item, item.indexOf("class=\"type", m.capturedEnd()));
line[4]->setText(Utils::decodeXml(m.captured()));

m = r.match(item, item.indexOf("title=\"", m.capturedEnd()));
r.setPattern("(?<=>).*?(?=</a>)");
m = r.match(item, item.indexOf("class=\"title", m.capturedEnd()));
line[3]->setText(Utils::decodeXml(m.captured().trimmed()));

r.setPattern("(?<=intro\">).*?(?=</p>)");
m = r.match(item, m.capturedEnd());
line[3]->setToolTip(toRichText(Utils::decodeXml(m.captured())));
r.setPattern("(?<=>).*?(?=</div>)");
m = r.match(item, item.indexOf("class=\"des", m.capturedEnd()));
QString d = m.captured().trimmed();
d.replace("<em class=\"keyword\">", "<font color=red>").replace("</em>", "</font>");
d = "<p>" + d + "</p>";
line[3]->setToolTip(d);

r.setPattern("(?<=i>).*?(?=</span>)");
m = r.match(item, item.indexOf("playtime", m.capturedEnd()));
Expand All @@ -256,7 +253,7 @@ Seek::Seek(QObject *parent) : QObject(parent), d_ptr(new SeekPrivate(this))
m = r.match(item, item.indexOf("subtitle", m.capturedEnd()));
line[2]->setText(m.captured().simplified());

r.setPattern("(?<=>).*(?=</a>)");
r.setPattern("(?<=>).*?(?=</a>)");
m = r.match(item, item.indexOf("uper", m.capturedEnd()));
line[5]->setText(Utils::decodeXml(m.captured()));

Expand Down Expand Up @@ -354,7 +351,7 @@ Seek::Seek(QObject *parent) : QObject(parent), d_ptr(new SeekPrivate(this))
line << new QStandardItem(Utils::decodeXml(item["username"].toString()));
line[0]->setData(item["contentId"].toString(), Qt::UserRole);
line[0]->setSizeHint(QSize(0, task.cover.height() + 3));
line[3]->setToolTip(toRichText(item["description"].toString()));
line[3]->setToolTip("<p>" + item["description"].toString() + "</p>");

QNetworkRequest request(QUrl(item["titleImg"].toString()));
request.setAttribute(QNetworkRequest::User, (quintptr)line[0]);
Expand Down
3 changes: 2 additions & 1 deletion src/Render/ARender.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ public slots:
virtual QList<quint8 *> getBuffer();
virtual void releaseBuffer();
virtual void setBuffer(QString &chroma, QSize size, int alignment, QList<QSize> *bufferSize = 0);
virtual ISprite *getSprite(const Comment &comment) = 0;

void setBackground(QString path);
void setMusic(bool music);
void setDisplayTime(double t);
void setVideoAspectRatio(double ratio);
void setPixelAspectRatio(double ratio);
void draw();

virtual ISprite *getSprite(const Comment &comment) = 0;
virtual quintptr getHandle() = 0;
virtual void resize(QSize size) = 0;
virtual QSize getBufferSize() = 0;
Expand Down
69 changes: 69 additions & 0 deletions src/Render/OpenGLRender/WindowPrivate.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,74 @@
#include "Common.h"
#include "WindowPrivate.h"
#include <QAbstractScrollArea>
#include <functional>

namespace
{
class OWindow :public QOpenGLWindow
{
public:
explicit OWindow(OpenGLOpaqueRenderPrivate *render) :
render(render)
{
window = nullptr;
QTimer::singleShot(0, [this]() {
window = lApp->mainWidget()->backingStore()->window();
});
connect(this, &OWindow::frameSwapped, std::bind(&OpenGLRenderPrivate::onSwapped, render));
}

private:
QWindow *window;
OpenGLOpaqueRenderPrivate *const render;

void initializeGL()
{
render->initialize();
}

void paintGL()
{
render->paint(this);
}

bool event(QEvent *e)
{
switch (e->type()) {
case QEvent::KeyPress:
case QEvent::KeyRelease:
case QEvent::Enter:
case QEvent::Leave:
case QEvent::MouseMove:
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
case QEvent::Wheel:
case QEvent::DragEnter:
case QEvent::DragMove:
case QEvent::DragLeave:
case QEvent::Drop:
case QEvent::ContextMenu:
return window ? qApp->sendEvent(window, e) : false;
default:
return QOpenGLWindow::event(e);
}
}

};

/* only QMdiSubWindow & QAbstractScrollArea
will make windowcontainer to create native widgets.
*/
class FParent :public QAbstractScrollArea
{
public:
explicit FParent(QWidget *parent) :
QAbstractScrollArea(parent)
{
}
};
}

OpenGLWindowRenderPrivate::OpenGLWindowRenderPrivate()
{
Expand Down
72 changes: 3 additions & 69 deletions src/Render/OpenGLRender/WindowPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,11 @@

#include "OpaquePrivate.h"
#include "../../Local.h"
#include <QAbstractScrollArea>
#include <QWidget>
#include <QOpenGLWindow>
#include <functional>

class OpenGLWindowRenderPrivate :public OpenGLOpaqueRenderPrivate
{
private:
class OWindow :public QOpenGLWindow
{
public:
explicit OWindow(OpenGLOpaqueRenderPrivate *render) :
render(render)
{
window = nullptr;
QTimer::singleShot(0, [this](){
window = lApp->mainWidget()->backingStore()->window();
});
connect(this, &OWindow::frameSwapped, std::bind(&OpenGLRenderPrivate::onSwapped, render));
}

private:
QWindow *window;
OpenGLOpaqueRenderPrivate *const render;

void initializeGL()
{
render->initialize();
}

void paintGL()
{
render->paint(this);
}

bool event(QEvent *e)
{
switch (e->type()){
case QEvent::KeyPress:
case QEvent::KeyRelease:
case QEvent::Enter:
case QEvent::Leave:
case QEvent::MouseMove:
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
case QEvent::Wheel:
case QEvent::DragEnter:
case QEvent::DragMove:
case QEvent::DragLeave:
case QEvent::Drop:
case QEvent::ContextMenu:
return window ? qApp->sendEvent(window, e) : false;
default:
return QOpenGLWindow::event(e);
}
}

};

/* only QMdiSubWindow & QAbstractScrollArea
will make windowcontainer to create native widgets.
*/
class FParent :public QAbstractScrollArea
{
public:
explicit FParent(QWidget *parent) :
QAbstractScrollArea(parent)
{
}
};

public:
OpenGLWindowRenderPrivate();

Expand Down Expand Up @@ -104,6 +38,6 @@ class OpenGLWindowRenderPrivate :public OpenGLOpaqueRenderPrivate

private:
QWidget *widget;
FParent *middle;
OWindow *window;
QWidget *middle;
QOpenGLWindow *window;
};

0 comments on commit 7b6d256

Please sign in to comment.