~ubuntu-branches/ubuntu/quantal/minitube/quantal

« back to all changes in this revision

Viewing changes to src/video.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jakob Haufe
  • Date: 2010-12-17 00:23:23 UTC
  • mfrom: (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20101217002323-vpwwfdqdp8ady29d
New upstream version (Closes: #606670)

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
void  Video::gotVideoInfo(QByteArray data) {
103
103
    QString videoInfo = QString::fromUtf8(data);
104
104
 
 
105
    // qDebug() << "videoInfo" << videoInfo;
 
106
 
105
107
    // get video token
106
108
    QRegExp re = QRegExp("^.*&token=([^&]+).*$");
107
109
    bool match = re.exactMatch(videoInfo);
118
120
    // qDebug() << "videoToken" << videoToken;
119
121
    this->videoToken = videoToken;
120
122
 
121
 
    /*
122
123
    // get fmt_url_map
123
124
    re = QRegExp("^.*&fmt_url_map=([^&]+).*$");
124
125
    match = re.exactMatch(videoInfo);
129
130
        getVideoInfo();
130
131
        return;
131
132
    }
 
133
 
132
134
    QString fmtUrlMap = re.cap(1);
133
 
 
134
 
    while (fmtUrlMap.contains('%'))
135
 
        fmtUrlMap = QByteArray::fromPercentEncoding(fmtUrlMap.toAscii());
136
 
 
137
 
    qDebug() << "fmtUrlMap" << fmtUrlMap;
 
135
    fmtUrlMap = QByteArray::fromPercentEncoding(fmtUrlMap.toUtf8());
 
136
 
 
137
    QSettings settings;
 
138
    QString definitionName = settings.value("definition").toString();
 
139
    int definitionCode = VideoDefinition::getDefinitionCode(definitionName);
 
140
 
 
141
    // qDebug() << "fmtUrlMap" << fmtUrlMap;
138
142
    QStringList formatUrls = fmtUrlMap.split(",", QString::SkipEmptyParts);
 
143
    QHash<int, QString> urlMap;
139
144
    foreach(QString formatUrl, formatUrls) {
140
145
        int separator = formatUrl.indexOf("|");
141
146
        if (separator == -1) continue;
142
147
        int format = formatUrl.left(separator).toInt();
143
148
        QString url = formatUrl.mid(separator + 1);
144
 
        qDebug() << format << url;
145
 
    }
146
 
    */
147
 
 
148
 
    QSettings settings;
149
 
    QString definitionName = settings.value("definition").toString();
150
 
    int definitionCode = VideoDefinition::getDefinitionCode(definitionName);
151
 
    if (definitionCode == 18) {
152
 
        // This is assumed always available
153
 
        foundVideoUrl(videoToken, 18);
154
 
    } else {
155
 
        findVideoUrl(definitionCode);
156
 
    }
 
149
 
 
150
        if (format == definitionCode) {
 
151
            QUrl videoUrl = QUrl::fromEncoded(url.toUtf8(), QUrl::StrictMode);
 
152
            m_streamUrl = videoUrl;
 
153
            emit gotStreamUrl(videoUrl);
 
154
            loadingStreamUrl = false;
 
155
            return;
 
156
        }
 
157
 
 
158
        urlMap.insert(format, url);
 
159
    }
 
160
 
 
161
    QList<int> definitionCodes = VideoDefinition::getDefinitionCodes();
 
162
    int currentIndex = definitionCodes.indexOf(definitionCode);
 
163
    int previousIndex = 0;
 
164
    while (currentIndex >= 0) {
 
165
        previousIndex = currentIndex - 1;
 
166
        int definitionCode = definitionCodes.at(previousIndex);
 
167
        if (urlMap.contains(definitionCode)) {
 
168
            qDebug() << "Found format" << definitionCode;
 
169
            QString url = urlMap.value(definitionCode);
 
170
            QUrl videoUrl = QUrl::fromEncoded(url.toUtf8(), QUrl::StrictMode);
 
171
            m_streamUrl = videoUrl;
 
172
            emit gotStreamUrl(videoUrl);
 
173
            loadingStreamUrl = false;
 
174
            return;
 
175
        }
 
176
        currentIndex--;
 
177
    }
 
178
 
 
179
    emit errorStreamUrl(tr("Cannot get video stream for %1").arg(m_webpage.toString()));
157
180
 
158
181
}
159
182