Skip to content

Commit

Permalink
Read whole stream list rather than search for known qualities (Fix #15).
Browse files Browse the repository at this point in the history
  • Loading branch information
Aldrog committed Aug 4, 2016
1 parent 1c30a5b commit 7d5e01b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
15 changes: 7 additions & 8 deletions sailfish-ui/pages/QualityChooserPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import Sailfish.Silica 1.0
Dialog {
id: page

property var qualities: ["chunked", "high", "medium", "low", "mobile"]
property var qualities //: ["chunked", "high", "medium", "low", "mobile"]
property bool chatOnly
property bool audioOnly

allowedOrientations: Orientation.All

onAccepted: {
streamQuality.value = qualities[qualityChooser.currentIndex]
streamQuality.value = qualityChooser.currentIndex
chatOnly = chatOnlySwitch.checked
audioOnly = audioOnlySwitch.checked
}
Expand Down Expand Up @@ -39,14 +39,13 @@ Dialog {

width: parent.width
label: qsTr("Quality")
currentIndex: qualities.indexOf(streamQuality.value)
currentIndex: streamQuality.value < qualities.selectableQualities.length ? streamQuality.value : (qualities.selectableQualities.length - 1)

menu: ContextMenu {
MenuItem { text: qsTr("Source") }
MenuItem { text: qsTr("High") }
MenuItem { text: qsTr("Medium") }
MenuItem { text: qsTr("Low") }
MenuItem { text: qsTr("Mobile") }
Repeater {
model: qualities.selectableQualities
delegate: MenuItem { text: qualities[modelData].name }
}
}
}

Expand Down
47 changes: 41 additions & 6 deletions sailfish-ui/pages/StreamPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import "../js/httphelper.js" as HTTP
Page {
id: page

property var url
property var urls
property string channel
property string channelDisplay
property bool followed
Expand All @@ -42,23 +42,54 @@ Page {
}
}

function findUrls(list) {
var res = ({selectableQualities: []})
var currentUrlId = ""
var currentUrlName = ""
for (var i in list) {
if(list[i].substring(0, 12) === "#EXT-X-MEDIA") {
currentUrlId = list[i].match(/GROUP-ID="([^"]+)"/)[1]
currentUrlName = list[i].match(/NAME="([^"]+)"/)[1]
if(list[i].indexOf("DEFAULT=YES") >= 0)
res.selectableQualities.push(currentUrlId)
}
if(list[i][0] !== '#' && list[i] !== "") {
res[currentUrlId] = {
name: currentUrlName,
url: list[i]
}
console.log(list[i])
console.log(currentUrlId, res[currentUrlId])
for (var j in res[currentUrlId]) {
console.log(j, res[currentUrlId][j])
}
}
}
console.log(res.selectableQualities)
console.log(streamQuality.value < res.selectableQualities.length ?
res.selectableQualities[streamQuality.value] :
res.selectableQualities[res.selectableQualities.length - 1])
return res
}

function loadStreamInfo() {
HTTP.getRequest("http://api.twitch.tv/api/channels/" + channel + "/access_token", function (tokendata) {
if (tokendata) {
var token = JSON.parse(tokendata)
HTTP.getRequest(encodeURI("http://usher.twitch.tv/api/channel/hls/" + channel + ".json?allow_source=true&allow_audio_only=true&sig=" + token.sig + "&token=" + token.token + "&type=any"), function (data) {
if (data) {
var videourls = data.split('\n')
url = {
urls = findUrls(videourls)
/*{
chunked: findUrl(videourls, "chunked"),
high: findUrl(videourls, "high"),
medium: findUrl(videourls, "medium"),
low: findUrl(videourls, "low"),
mobile: findUrl(videourls, "mobile"),
audio: findUrl(videourls, "audio_only")
}
}*/
video.play()
mainWindow.audioUrl = url.audio
mainWindow.audioUrl = urls.audio_only.url
}
})
}
Expand Down Expand Up @@ -184,7 +215,7 @@ Page {
MenuItem {
text: qsTr("Quality")
onClicked: {
var dialog = pageStack.push(Qt.resolvedUrl("QualityChooserPage.qml"), { chatOnly: chatMode, audioOnly: audioMode, channel: channel })
var dialog = pageStack.push(Qt.resolvedUrl("QualityChooserPage.qml"), { qualities: urls, chatOnly: chatMode, audioOnly: audioMode, channel: channel })
dialog.accepted.connect(function() {
chatMode = dialog.chatOnly
audioMode = dialog.audioOnly
Expand All @@ -205,7 +236,11 @@ Page {
id: video

anchors.fill: parent
source: audioMode ? url["audio"] : url[streamQuality.value]
source: audioMode ? urls["audio"].url :
urls[streamQuality.value < urls.selectableQualities.length ?
urls.selectableQualities[streamQuality.value] :
urls.selectableQualities[urls.selectableQualities.length - 1]
].url

onErrorChanged: console.error("video error:", errorString)

Expand Down
2 changes: 1 addition & 1 deletion src/ircchat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void IrcChat::join(const QString channel) {
sock->write(("PASS " + userpass + "\r\n").toStdString().c_str());
sock->write(("NICK " + username + "\r\n").toStdString().c_str());
// Join channel's chat room
qDebug() << sock->write(("JOIN #" + channel + "\r\n").toStdString().c_str());
sock->write(("JOIN #" + channel + "\r\n").toStdString().c_str());

QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(badgesReceived(QNetworkReply*)));
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void registerSettings(QQuickView *view) {

QMLSettings *streamQuality = new QMLSettings();
streamQuality->setKey("Video/StreamQuality");
streamQuality->setDefaultValue("medium");
streamQuality->setDefaultValue(2);
view->rootContext()->setContextProperty("streamQuality", streamQuality);
}

Expand Down

0 comments on commit 7d5e01b

Please sign in to comment.