Comparing version 0.0.4 to 0.0.5
var cheerio = require("cheerio") | ||
, request = require("request") | ||
impurge = [] | ||
var impurge = []; | ||
@@ -8,11 +8,12 @@ module.exports = impurge; | ||
//pattern used for extraction of the links from the html | ||
imgur_url_pattern = RegExp("^http://((www)|(i)\.)?imgur.com/[./a-zA-Z0-9&,]+","ig") | ||
var imgur_url_pattern = RegExp("^http://((www)|(i)\.)?imgur.com/[./a-zA-Z0-9&,]+","ig"); | ||
//patterns used to check URL patterns | ||
imgur_album_url_pattern = RegExp("^http://(?:www\.)?imgur\.com/a/([a-zA-Z0-9]+)","i") | ||
imgur_hashes_pattern = RegExp("imgur\.com/(([a-zA-Z0-9]{5,7}[&,]?)+)","i") | ||
imgur_image_pattern = RegExp("^http://(www\.)?(i\.)?imgur\.com/.{3,7}\.((jpg)|(gif))","ig") | ||
var imgur_album_url_pattern = RegExp("^http://(?:www\.)?imgur\.com/a/([a-zA-Z0-9]+)","i"); | ||
var imgur_gallery_url_pattern = RegExp("^http://(?:www\.)?imgur\.com/gallery/([a-zA-Z0-9]+)","i"); | ||
var imgur_hashes_pattern = RegExp("imgur\.com/(([a-zA-Z0-9]{5,7}[&,]?)+)","i"); | ||
var imgur_image_pattern = RegExp("^http://(www\.)?(i\.)?imgur\.com/.{3,7}\.((jpg)|(gif))","ig"); | ||
//determines the link provided to module | ||
determine_link_type = function (url, callback) { | ||
var determine_link_type = function (url, callback) { | ||
if ( imgur_image_pattern.exec(url) ) { | ||
@@ -22,10 +23,17 @@ callback(null,'image_url',null,url); | ||
else if ( imgur_album_url_pattern.exec(url) ) { | ||
var match = imgur_album_url_pattern.exec(url) | ||
var match = imgur_album_url_pattern.exec(url); | ||
if (match){ | ||
var hashes = match[1].split(/[,&]/) | ||
} | ||
callback(null,'album_url',hashes); | ||
} | ||
else if ( imgur_gallery_url_pattern.exec(url) ) { | ||
var match = imgur_gallery_url_pattern.exec(url); | ||
if (match){ | ||
var hashes = match[1].split(/[,&]/); | ||
} | ||
callback(null,'album_url',hashes); | ||
} | ||
callback(null,'gallery_url',hashes); | ||
} | ||
else if ( imgur_hashes_pattern.exec(url) ) { | ||
var match = imgur_hashes_pattern.exec(url) | ||
var match = imgur_hashes_pattern.exec(url); | ||
if (match){ | ||
@@ -59,2 +67,5 @@ var hashes = match[1].split(/[,&]/); | ||
} | ||
else if (type === 'gallery_url'){ | ||
var url = 'http://api.imgur.com/2/album/'+id+".json" | ||
} | ||
else { | ||
@@ -67,3 +78,3 @@ callback("unknown_link_error") | ||
} catch (err) { | ||
callback("impurge: JSON parsing error"); | ||
callback("impurge: JSON parsing error w/following URL: "+ url); | ||
} | ||
@@ -70,0 +81,0 @@ |
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "takes any imgur url and returns an array of direct image files", | ||
@@ -17,3 +17,4 @@ "engines": { | ||
"mocha": "*", | ||
"request": "~2.11.4" | ||
"request": "~2.11.4", | ||
"cheerio": "*" | ||
}, | ||
@@ -24,8 +25,5 @@ "devDependencies": { | ||
"keywords": [ | ||
"digitalocean", | ||
"digital", | ||
"ocean", | ||
"api", | ||
"cloud", | ||
"ssd" | ||
"imgur", | ||
"parser", | ||
"image" | ||
], | ||
@@ -32,0 +30,0 @@ "author": "hortinstein", |
@@ -26,6 +26,6 @@ var should = require('should'); | ||
it('should find 2 pictures', function(done){ | ||
impurge.purge("http://imgur.com/a/mj1YZ", function (e,r) { | ||
r.length.should.equal(3); | ||
r[0].should.equal('http://i.imgur.com/elfZxNm.jpg'); | ||
r[1].should.equal('http://i.imgur.com/WKNJN3K.jpg'); | ||
impurge.purge("http://imgur.com/a/9uIQf", function (e,r) { | ||
r.length.should.equal(2); | ||
r[0].should.equal('http://i.imgur.com/Z6ft3xZ.jpg'); | ||
r[1].should.equal('http://i.imgur.com/xSW842C.jpg'); | ||
done(); | ||
@@ -44,4 +44,13 @@ }) | ||
}); | ||
describe('gallery hash url', function () { | ||
it('should find 4 pictures', function(done){ | ||
impurge.purge("http://imgur.com/gallery/Ptn4M", function (e,r) { | ||
r.length.should.equal(4); | ||
r[0].should.equal('http://i.imgur.com/tYx0Ebf.gif'); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5382
141
3
3
+ Addedcheerio@*
+ Addedboolbase@1.0.0(transitive)
+ Addedcheerio@1.0.0(transitive)
+ Addedcheerio-select@2.1.0(transitive)
+ Addedcss-select@5.1.0(transitive)
+ Addedcss-what@6.1.0(transitive)
+ Addeddom-serializer@2.0.0(transitive)
+ Addeddomelementtype@2.3.0(transitive)
+ Addeddomhandler@5.0.3(transitive)
+ Addeddomutils@3.1.0(transitive)
+ Addedencoding-sniffer@0.2.0(transitive)
+ Addedentities@4.5.0(transitive)
+ Addedhtmlparser2@9.1.0(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addednth-check@2.1.1(transitive)
+ Addedparse5@7.2.1(transitive)
+ Addedparse5-htmlparser2-tree-adapter@7.1.0(transitive)
+ Addedparse5-parser-stream@7.1.2(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedundici@6.21.0(transitive)
+ Addedwhatwg-encoding@3.1.1(transitive)
+ Addedwhatwg-mimetype@4.0.0(transitive)