forked from same31/addic7ed-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search subtitles by show, season, episode and optional language list
- Loading branch information
Showing
3 changed files
with
101 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |