~ubuntu-branches/ubuntu/saucy/minitube/saucy-proposed

« back to all changes in this revision

Viewing changes to src/youtubesearch.cpp

  • Committer: Package Import Robot
  • Author(s): Jakob Haufe
  • Date: 2012-09-29 02:43:53 UTC
  • mfrom: (2.1.10)
  • Revision ID: package-import@ubuntu.com-20120929024353-cvsvqeewq4p93pb4
Tags: 1.9-1
* New upstream version (Closes: #673696).
* Refresh disable-update-check.
* Refresh proper-tempfiles.
* Use hardening-wrapper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
    this->abortFlag = false;
14
14
 
15
15
    QUrl url("http://gdata.youtube.com/feeds/api/videos/");
 
16
    url.addQueryItem("v", "2");
 
17
 
16
18
    url.addQueryItem("max-results", QString::number(max));
17
19
    url.addQueryItem("start-index", QString::number(skip));
 
20
 
18
21
    if (!searchParams->keywords().isEmpty()) {
19
22
        if (searchParams->keywords().startsWith("http://") ||
20
23
                searchParams->keywords().startsWith("https://")) {
21
24
            url.addQueryItem("q", YouTubeSearch::videoIdFromUrl(searchParams->keywords()));
22
25
        } else url.addQueryItem("q", searchParams->keywords());
23
26
    }
 
27
 
24
28
    if (!searchParams->author().isEmpty())
25
29
        url.addQueryItem("author", searchParams->author());
26
30
 
31
35
    case SearchParams::SortByViewCount:
32
36
        url.addQueryItem("orderby", "viewCount");
33
37
        break;
 
38
    case SearchParams::SortByRating:
 
39
        url.addQueryItem("orderby", "rating");
 
40
        break;
 
41
    }
 
42
 
 
43
    switch (searchParams->duration()) {
 
44
    case SearchParams::DurationShort:
 
45
        url.addQueryItem("duration", "short");
 
46
        break;
 
47
    case SearchParams::DurationMedium:
 
48
        url.addQueryItem("duration", "medium");
 
49
        break;
 
50
    case SearchParams::DurationLong:
 
51
        url.addQueryItem("duration", "long");
 
52
        break;
 
53
    }
 
54
 
 
55
    switch (searchParams->time()) {
 
56
    case SearchParams::TimeToday:
 
57
        url.addQueryItem("time", "today");
 
58
        break;
 
59
    case SearchParams::TimeWeek:
 
60
        url.addQueryItem("time", "this_week");
 
61
        break;
 
62
    case SearchParams::TimeMonth:
 
63
        url.addQueryItem("time", "this_month");
 
64
        break;
 
65
    }
 
66
 
 
67
    switch (searchParams->quality()) {
 
68
    case SearchParams::QualityHD:
 
69
        url.addQueryItem("hd", "true");
 
70
        break;
34
71
    }
35
72
 
36
73
    QObject *reply = The::http()->get(url);
50
87
        qDebug() << "Error parsing XML";
51
88
    }
52
89
    videos = reader.getVideos();
 
90
    suggestions = reader.getSuggestions();
53
91
 
54
92
    foreach (Video *video, videos) {
55
93
        // send it to the model
69
107
    return videos;
70
108
}
71
109
 
 
110
const QStringList & YouTubeSearch::getSuggestions() const {
 
111
    return suggestions;
 
112
}
 
113
 
72
114
void YouTubeSearch::abort() {
73
115
    this->abortFlag = true;
74
116
}
77
119
    QRegExp re = QRegExp("^.*\\?v=([^&]+).*$");
78
120
    if (re.exactMatch(url)) {
79
121
        QString videoId = re.cap(1);
 
122
        videoId.remove('-');
80
123
        return videoId;
81
124
    }
82
125
    return QString();