代码拉取完成,页面将自动刷新
同步操作将从 fword/MusicPlayer_QT5 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "lyrics.h"
#include <QFile>
#include <QDebug>
#include <QRegularExpression>
Lyrics::Lyrics(QString lyricsPath)
{
this->lyrics_path = lyricsPath;
max_size = 0;
}
Lyrics::~Lyrics()
{
}
QList<QString> Lyrics::getListLyricsText()
{
return list_lyrics_text;
}
QVector<int> Lyrics::getListLyricsTime()
{
return list_lyrics_time;
}
bool Lyrics::readLyricsFile(QString lyricsPath)
{
if(lyrics_path == lyricsPath)
return true;
lyrics_path = lyricsPath;
size = 0;
QFile file(lyricsPath);
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QString line = "";
while((line=file.readLine())>0)
{
//qDebug()<<line;
analysisLyricsFile(line);
}
max_size = max_size < size ? size : max_size;
return true;
}
else
{
return false;
}
}
bool Lyrics::analysisLyricsFile(QString line)
{
if(line == NULL || line.isEmpty())
{
qDebug()<<"This line is empty!";
return false;
}
QRegularExpression regularExpression("\\[(\\d+)?:(\\d+\\.\\d+)?\\](.*)?");
int index = 0;
QRegularExpressionMatch match;
match = regularExpression.match(line, index);
if(match.hasMatch())
{
int totalTime;
//qDebug()<<QString::fromStdString(match.captured(2).toStdString());
totalTime = match.captured(1).toInt() * 60000 + match.captured(2).toFloat() * 1000;
QString currentText =QString::fromStdString(match.captured(3).toStdString());
if(size < list_lyrics_time.size())
{
list_lyrics_text[size] = currentText;
list_lyrics_time[size++] = totalTime;
}
else
{
list_lyrics_text.push_back(currentText);
list_lyrics_time.push_back(totalTime);
size++;
}
return true;
}
return false;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。