コード例 #1
0
ファイル: youtube.js プロジェクト: StrategicGains/Hilary
    youtube.video(id, function(err, data) {
        if (err) {
            log().error({'err': err}, 'Could not talk to the youtube api.');
            return callback({'code': 500, 'msg': err.message});
        }


        if (data && data.thumbnail && data.thumbnail.hqDefault) {
            var opts = {
                'displayName': data.title,
                'description': data.description
            };

            // Download it.
            var imageUrl = data.thumbnail.hqDefault;
            var path = ctx.baseDir + '/youtube.jpg';
            PreviewUtil.downloadRemoteFile(imageUrl, path, function(err, path) {
                if (err) {
                    return callback(err);
                }

                LinkProcessorUtil.generatePreviewsFromImage(ctx, path, opts, callback);
            });
        } else {
            return callback(false, true);
        }
    });
コード例 #2
0
ファイル: slideshare.js プロジェクト: Coenego/Hilary
        parseString(body, function (err, result) {
            if (err || result.SlideShareServiceError) {
                return callback(err || {'code': 500, 'msg': result.SlideShareServiceError.Message});

            // Ignore this image if it has no thumbnail.
            } else if (!(result.Slideshow && result.Slideshow.ThumbnailURL && result.Slideshow.ThumbnailURL.length > 0)) {
                return callback(null, true);
            }

            var opts = {};
            if (result.Slideshow && result.Slideshow.Title && result.Slideshow.Title.length > 0) {
                opts.displayName = result.Slideshow.Title[0];
            }
            if (result.Slideshow && result.Slideshow.Description && result.Slideshow.Description.length > 0) {
                opts.description = result.Slideshow.Description[0];
            }

            // Download it.
            var imageUrl = 'http:' + result.Slideshow.ThumbnailURL[0];
            var path = ctx.baseDir + '/slideshare.jpg';
            PreviewUtil.downloadRemoteFile(imageUrl, path, function(err, path) {
                if (err) {
                    return callback(err);
                }

                LinkProcessorUtil.generatePreviewsFromImage(ctx, path, opts, callback);
            });
        });
コード例 #3
0
ファイル: slideshare.js プロジェクト: GatechVIP/Hilary
    ss.getSlideshowByURL(contentObj.link, function(response) {
        if (!response || response.SlideShareServiceError) {
            log().error({'err': response.SlideShareServiceError}, 'Failed to interact with the SlideShare API');
            return callback({'code': 500, 'msg': 'Failed to interact with the SlideShare API'});

        // Ignore this image if it has no thumbnail
        } else if (!response.Slideshow || !response.Slideshow.ThumbnailURL) {
            return callback(null, true);
        }

        var result = response.Slideshow;

        // Try to get some optional metadata about this slideshow such as the title and/or description. The display name
        // will only be overridden with the title retrieved from SlideShare when the content item's display name has not been set
        // by the user (i.e. the SlideShare URL is used as the displayName). The description retrieved from SlideShare will only be
        // set on the content item when the content item has no description
        var opts = {};
        if (result.Title && result.Title.length > 0) {
            opts.displayName = result.Title[0];
        }
        if (result.Description && result.Description.length > 0) {
            opts.description = result.Description[0];
        }

        // Download the thumbnail
        var imageUrl = 'http:' + result.ThumbnailURL[0];
        var path = ctx.baseDir + '/slideshare.jpg';
        PreviewUtil.downloadRemoteFile(imageUrl, path, function(err, path) {
            if (err) {
                return callback(err);
            }

            LinkProcessorUtil.generatePreviewsFromImage(ctx, path, opts, callback);
        });
    });
コード例 #4
0
ファイル: test-previews.js プロジェクト: Coenego/Hilary
            it('verify remote files can be downloaded', function() {
                var tmpPath = Tempfile.createTempFile();
                PreviewUtil.downloadRemoteFile('http://localhost:2000/api/me', tmpPath.path, function(err, path) {
                    assert.ok(!err);
                    IO.readFile(path, function(err, data) {
                        assert.ok(!err);

                        // Verify there is some data there.
                        assert.ok(data);

                        // Verify we don't leak the global session into the download fetcher.
                        data = JSON.parse(data);
                        assert.ok(data.anon);
                    });
                });
            });