+function view (servers, numServer, callback) {
+ if (!callback) callback = function () {}
+
+ videosUtils.getVideosList(servers[numServer].url, function (err, res) {
+ if (err) throw err
+
+ const videos = res.body.data
+ if (videos.length === 0) return callback()
+
+ const toView = videos[getRandomInt(0, videos.length)].id
+
+ console.log('Viewing video from server ' + numServer)
+ videosUtils.getVideo(servers[numServer].url, toView, callback)
+ })
+}
+
+function like (servers, numServer, callback) {
+ rate(servers, numServer, 'like', callback)
+}
+
+function dislike (servers, numServer, callback) {
+ rate(servers, numServer, 'dislike', callback)
+}
+
+function rate (servers, numServer, rating, callback) {
+ if (!callback) callback = function () {}
+
+ videosUtils.getVideosList(servers[numServer].url, function (err, res) {
+ if (err) throw err
+
+ const videos = res.body.data
+ if (videos.length === 0) return callback()
+
+ const toRate = videos[getRandomInt(0, videos.length)].id
+
+ console.log('Rating (%s) video from server %d', rating, numServer)
+ videosUtils.getVideo(servers[numServer].url, toRate, callback)
+ })
+}
+