Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
only download if new version
Browse files Browse the repository at this point in the history
  • Loading branch information
fent committed Oct 15, 2013
1 parent e6f172d commit 1c8211c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.mp4
*.webm
node_modules
bin/version
38 changes: 21 additions & 17 deletions scripts/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ var http = require('http');
var https = require('https');

var dir = path.join(__dirname, '..', 'bin');
var filename = 'youtube-dl';
var filepath = path.join(dir, filename);
var filepath = path.join(dir, 'youtube-dl');
var verpath = path.join(dir, 'version');


// Make bin dir if it doesn't exists.
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, 484);
}

function onerr(err) {
throw err;
}

// First, look for the download link.
var regexp = /https:\/\/yt-dl\.org\/downloads\/\d{4}\.\d\d\.\d\d\/youtube-dl/;
var regexp = /https:\/\/yt-dl\.org\/downloads\/(\d{4}\.\d\d\.\d\d)\/youtube-dl/;
function getDownloadLink() {
var url = 'http://rg3.github.io/youtube-dl/download.html';
http.get(url, function(res) {
Expand All @@ -28,18 +32,23 @@ function getDownloadLink() {
res.on('end', function() {
var m = regexp.exec(body);
if (m) {
download(m[0]);
// Check if there is a new version available.
var newVersion = m[1];
var oldVersion = fs.existsSync(verpath)
&& fs.readFileSync(verpath, 'utf8');
if (newVersion === oldVersion) {
console.log('Alrready up to date');
} else {
download(m[0]);
fs.writeFileSync(verpath, newVersion);
}
} else {
console.error('Could not find download link in ' + url);
}
});

res.on('error', function(err) {
throw err;
});
}).on('error', function(err) {
throw err;
});
res.on('error', onerr);
}).on('error', onerr);
}

// Download youtube-dl.
Expand All @@ -56,13 +65,8 @@ function download(link) {
console.log('Finished!');
});

res.on('error', function(err) {
throw err;
});

}).on('error', function(err) {
throw err;
});
res.on('error', onerr);
}).on('error', onerr);
}

console.log('Downloading latest youtube-dl');
Expand Down

0 comments on commit 1c8211c

Please sign in to comment.