Skip to content

Commit

Permalink
Search subtitles by show, season, episode and optional language list
Browse files Browse the repository at this point in the history
  • Loading branch information
same31 committed Nov 28, 2015
1 parent 3a2f9a4 commit b467aac
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 26 deletions.
27 changes: 1 addition & 26 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,27 +1,2 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
.idea
node_modules
72 changes: 72 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
var request = require('request');

function formatShowNumber(number) {
return parseInt(number) < 10 ? '0' + number : number;
}

function searchSubtitles(show, season, episode, languages, callback) {
request({
uri: 'http://www.addic7ed.com/search.php',
qs: {
search: show.trim() + ' ' + formatShowNumber(season) + 'x' + formatShowNumber(episode)
}
}, function (error, response, body) {
if (error || !body.trim()) {
return console.log('Error', error, body);
}

var subs = {},
versionRegExp = /Version (.+?),([^]+?)<\/table/g,
versionMatch,
version,
subInfoRegExp = /class="language">([^]+?)<a[^]+?(% )?Completed[^]+?href="([^"]+?)"><strong>(?:most updated|Download)/g,
subInfoMatch,
lang,
notCompleted,
link,
distributionMatch,
distribution,
team;

// Find subtitles HTML block parts
// ===============================
while ((versionMatch = versionRegExp.exec(body)) !== null) {
version = versionMatch[1].toUpperCase();

while ((subInfoMatch = subInfoRegExp.exec(versionMatch[2])) !== null) {
notCompleted = subInfoMatch[2];
if (notCompleted) {
continue;
}
lang = subInfoMatch[1].substr(0, 3).toLowerCase();
link = subInfoMatch[3];

if (languages && !~languages.indexOf(lang)) {
continue;
}

subs[lang] || (subs[lang] = {});

distributionMatch = version.match(/WEB.DL|WEB.?RIP|BRRIP|BDRIP|BLURAY/i);

distribution = distributionMatch
? distributionMatch[0].toUpperCase()
.replace(/WEB.DL|WEB.?RIP/, 'WEB-DL')
.replace(/BRRIP|BDRIP|BLURAY/, 'BLURAY')
: 'HDTV';

subs[lang][distribution] || (subs[lang][distribution] = []);

team = distribution === 'HDTV' ? version.replace(/.?(REPACK|PROPER|X264|HDTV|480P|720P|1080P|2160P)+.?/g, '').trim().toUpperCase() : '';

subs[lang][distribution].push({
link: 'http://www.addic7ed.com' + link,
team: team,
version: version
});
}
}

typeof callback === 'function' && callback(subs);
});
}
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "addic7ed-api",
"version": "0.0.1",
"description": "API to search and download subtitles files from addic7ed.com",
"main": "lib/main.js",
"dependencies": {
"request": "^2.67.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/same31/addic7ed-api.git"
},
"keywords": [
"addic7ed.com",
"subtitles",
"api"
],
"author": "Matthieu Mitrani",
"license": "MIT",
"bugs": {
"url": "https://github.com/same31/addic7ed-api/issues"
},
"homepage": "https://github.com/same31/addic7ed-api"
}

0 comments on commit b467aac

Please sign in to comment.