1 Commits

Author SHA1 Message Date
cf7ba2e8f5 Fix OBS general GET reply handling 2021-08-08 18:55:53 -05:00
7 changed files with 14 additions and 85 deletions

View File

@ -1,41 +0,0 @@
from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.parse import urlparse, parse_qs
import threading
import obspython as obs
def set_current_scene(scene_name):
scenes = obs.obs_frontend_get_scenes()
for scene in scenes:
name = obs.obs_source_get_name(scene)
if name == scene_name:
obs.obs_frontend_set_current_scene(scene)
return 0
return 1
class RqstHandler(BaseHTTPRequestHandler):
def do_GET(self):
up = urlparse(self.path)
if up.path == '/Scene':
qc = parse_qs(up.query)
set_current_scene(qc.get('name', [''])[0])
self.send_response(200)
self.end_headers()
elif up.path == '/ping':
self.send_response(200)
self.end_headers()
def log_message(self, format, *args):
pass
def run(name):
httpd = HTTPServer(('127.0.0.1', 9302), RqstHandler)
httpd.serve_forever()
t = threading.Thread(target=run, args=(1,), daemon=True)
t.start()

View File

@ -20,16 +20,16 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) {
const auto mainWidget = new QWidget(this);
const auto rootLyt = new QVBoxLayout;
const auto controlsLayout = new QGridLayout;
m_slideView = new SlideView(this);
const auto slideView = new SlideView(this);
setCentralWidget(mainWidget);
mainWidget->setLayout(rootLyt);
rootLyt->addWidget(m_slideView);
rootLyt->addWidget(slideView);
rootLyt->addLayout(controlsLayout);
// setup slide controls
const auto btnPrevSong = new QPushButton(tr("Previous Song (Left)"), this);
const auto btnPrevSlide = new QPushButton(tr("Previous Slide (Up)"), this);
const auto btnNextSlide = new QPushButton(tr("Next Slide (Down)"), this);
const auto btnNextSong = new QPushButton(tr("Next Song (Right)"), this);
const auto btnNextSong = new QPushButton(tr("Next Song (Right))"), this);
const auto btnBlankSlides = new QPushButton(tr("Blank Slides (,)"), this);
const auto btnShowSlides = new QPushButton(tr("Show Slides (.)"), this);
controlsLayout->addWidget(btnPrevSlide, 0, 0);
@ -52,12 +52,12 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) {
connect(btnBlankSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::blankScreen);
connect(btnBlankSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::hideSlides);
connect(btnShowSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::showSlides);
connect(&m_openlpClient, &OpenLPClient::pollUpdate, m_slideView, &SlideView::pollUpdate);
connect(&m_openlpClient, &OpenLPClient::songListUpdate, m_slideView, &SlideView::songListUpdate);
connect(&m_openlpClient, &OpenLPClient::slideListUpdate, m_slideView, &SlideView::slideListUpdate);
connect(&m_openlpClient, &OpenLPClient::pollFailed, m_slideView, &SlideView::reset);
connect(m_slideView, &SlideView::songChanged, &m_openlpClient, &OpenLPClient::changeSong);
connect(m_slideView, &SlideView::slideChanged, &m_openlpClient, &OpenLPClient::changeSlide);
connect(&m_openlpClient, &OpenLPClient::pollUpdate, slideView, &SlideView::pollUpdate);
connect(&m_openlpClient, &OpenLPClient::songListUpdate, slideView, &SlideView::songListUpdate);
connect(&m_openlpClient, &OpenLPClient::slideListUpdate, slideView, &SlideView::slideListUpdate);
connect(&m_openlpClient, &OpenLPClient::pollFailed, slideView, &SlideView::reset);
connect(slideView, &SlideView::songChanged, &m_openlpClient, &OpenLPClient::changeSong);
connect(slideView, &SlideView::slideChanged, &m_openlpClient, &OpenLPClient::changeSlide);
// setup scene selector
const auto btnObsHideSlides = new QPushButton(tr("Hide Slides in OBS (;)"), mainWidget);
const auto btnObsShowSlides = new QPushButton(tr("Show Slides in OBS (')"), mainWidget);
@ -71,7 +71,6 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) {
connect(btnObsShowSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::showSlides);
// setup status bar
setStatusBar(new QStatusBar(this));
connect(&m_openlpClient, &OpenLPClient::songChanged, this, &MainWindow::refreshStatusBar);
connect(&m_openlpClient, &OpenLPClient::pollUpdate, this, &MainWindow::openLpConnectionInit);
connect(&m_obsClient, &OBSClient::pollUpdate, this, &MainWindow::obsConnectionInit);
refreshStatusBar();
@ -108,7 +107,5 @@ void MainWindow::obsConnectionLost() {
void MainWindow::refreshStatusBar() {
const auto openLpStatus = m_openLpConnected ? tr("OpenLP: Connected") : tr("OpenLP: Not Connected");
const auto obsStatus = m_obsConnected ? tr("OBS: Connected") : tr("OBS: Not Connected");
const auto nextSong = m_openlpClient.getNextSong();
const auto nextSongTxt = m_openLpConnected ? " | Next Song: " + nextSong : "";
statusBar()->showMessage(openLpStatus + " | " + obsStatus + nextSongTxt);
statusBar()->showMessage(openLpStatus + " | " + obsStatus);
}

View File

@ -21,7 +21,6 @@ class MainWindow: public QMainWindow {
private:
OBSClient m_obsClient;
OpenLPClient m_openlpClient;
class SlideView *m_slideView = nullptr;
bool m_openLpConnected = false;
bool m_obsConnected = false;

View File

@ -24,15 +24,6 @@ OpenLPClient::OpenLPClient(QObject *parent): QObject(parent) {
connect(m_pollingNam, &QNetworkAccessManager::finished, this, &OpenLPClient::handlePollResponse);
}
QString OpenLPClient::getNextSong() {
const auto currentSong = m_songNameMap[m_currentSongId];
const auto songIdx = m_songList.indexOf(currentSong) + 1;
if (songIdx < m_songList.size()) {
return m_songList[songIdx];
}
return "";
}
void OpenLPClient::nextSlide() {
get("/api/controller/live/next");
}
@ -126,7 +117,6 @@ void OpenLPClient::handlePollResponse(QNetworkReply *reply) {
if (m_currentSongId != songId) {
requestSlideList();
m_currentSongId = songId;
emit songChanged(songId);
}
emit pollUpdate(m_songNameMap[songId], slide);
}
@ -140,18 +130,18 @@ void OpenLPClient::handleSongListResponse(QNetworkReply *reply) {
if (data.isEmpty()) {
return;
}
QStringList songList;
auto doc = QJsonDocument::fromJson(data);
auto items = doc.object()["results"].toObject()["items"].toArray();
m_songNameMap.clear();
m_songList.clear();
for (const auto &item : items) {
auto song = item.toObject();
auto name = song["title"].toString();
auto id = song["id"].toString();
m_songNameMap[id] = name;
m_songList.push_back(name);
songList.push_back(name);
}
emit songListUpdate(m_songList);
emit songListUpdate(songList);
}
void OpenLPClient::handleSlideListResponse(QNetworkReply *reply) {

View File

@ -30,17 +30,13 @@ class OpenLPClient: public QObject {
QNetworkAccessManager *m_slideListNam = new QNetworkAccessManager(this);
QTimer m_pollTimer;
QHash<QString, QString> m_songNameMap;
QStringList m_songList;
int m_currentServiceId = -1;
QString m_currentSongId;
public:
explicit OpenLPClient(QObject *parent = nullptr);
[[nodiscard]]
QString getNextSong();
public slots:
public slots:
void nextSlide();
void prevSlide();
@ -84,6 +80,5 @@ class OpenLPClient: public QObject {
void slideListUpdate(QStringList, QStringList);
void songChanged(QString);
};

View File

@ -33,15 +33,6 @@ SlideView::SlideView(QWidget *parent): QWidget(parent) {
connect(m_slideTable, &QTableWidget::currentCellChanged, this, &SlideView::slideChanged);
}
QString SlideView::getNextSong() const {
const auto cnt = m_songSelector->count();
const auto idx = m_songSelector->currentIndex() + 1;
if (idx < cnt) {
return m_songSelector->itemText(idx);
}
return "";
}
void SlideView::pollUpdate(QString songName, int slide) {
if (songName != m_currentSong) {
m_currentSong = songName;

View File

@ -19,8 +19,6 @@ class SlideView: public QWidget {
public:
explicit SlideView(QWidget *parent = nullptr);
QString getNextSong() const;
public slots:
void pollUpdate(QString songId, int slideNum);