mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
pads zeros to imdbId if missing
This commit is contained in:
@@ -15,6 +15,10 @@ async function createTorrentEntry(torrent) {
|
|||||||
torrent.imdbId = await getImdbId(titleInfo, torrent.type)
|
torrent.imdbId = await getImdbId(titleInfo, torrent.type)
|
||||||
.catch(() => undefined);
|
.catch(() => undefined);
|
||||||
}
|
}
|
||||||
|
if (torrent.imdbId && torrent.imdbId.length < 9) {
|
||||||
|
// pad zeros to imdbId if missing
|
||||||
|
torrent.imdbId = 'tt' + torrent.imdbId.replace('tt', '').padStart(7, '0');
|
||||||
|
}
|
||||||
if (torrent.imdbId && torrent.imdbId.length > 9 && torrent.imdbId.startsWith('tt0')) {
|
if (torrent.imdbId && torrent.imdbId.length > 9 && torrent.imdbId.startsWith('tt0')) {
|
||||||
// sanitize imdbId from redundant zeros
|
// sanitize imdbId from redundant zeros
|
||||||
torrent.imdbId = torrent.imdbId.replace(/tt0+([0-9]{7,})$/, 'tt$1');
|
torrent.imdbId = torrent.imdbId.replace(/tt0+([0-9]{7,})$/, 'tt$1');
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ function parseTorrentPage(body) {
|
|||||||
|
|
||||||
const details = $('.torrent-detail-page');
|
const details = $('.torrent-detail-page');
|
||||||
const magnetLink = details.find('a:contains(\'Magnet Download\')').attr('href');
|
const magnetLink = details.find('a:contains(\'Magnet Download\')').attr('href');
|
||||||
const imdbIdMatch = details.find('div[id=\'description\']').html().match(/imdb\.com\/title\/tt(\d+)/i);
|
const imdbIdMatch = details.find('div[id=\'description\']').html().match(/imdb\.com\/title\/(tt\d+)/i);
|
||||||
|
|
||||||
const torrent = {
|
const torrent = {
|
||||||
name: decode(magnetLink).name.replace(/\+/g, ' '),
|
name: decode(magnetLink).name.replace(/\+/g, ' '),
|
||||||
@@ -125,7 +125,7 @@ function parseTorrentPage(body) {
|
|||||||
language: details.find('strong:contains(\'Language\')').next().text(),
|
language: details.find('strong:contains(\'Language\')').next().text(),
|
||||||
size: parseSize(details.find('strong:contains(\'Total size\')').next().text()),
|
size: parseSize(details.find('strong:contains(\'Total size\')').next().text()),
|
||||||
uploadDate: Sugar.Date.create(details.find('strong:contains(\'Date uploaded\')').next().text()),
|
uploadDate: Sugar.Date.create(details.find('strong:contains(\'Date uploaded\')').next().text()),
|
||||||
imdbId: imdbIdMatch && `tt${imdbIdMatch[1].padStart(7, '0')}`,
|
imdbId: imdbIdMatch && imdbIdMatch[1],
|
||||||
files: details.find('div[id=\'files\']').first().find('li')
|
files: details.find('div[id=\'files\']').first().find('li')
|
||||||
.map((i, elem) => $(elem).text())
|
.map((i, elem) => $(elem).text())
|
||||||
.map((i, text) => ({
|
.map((i, text) => ({
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ function parseTorrentPage(body) {
|
|||||||
const info = content.find('div[class="torrent_stats"]').parent();
|
const info = content.find('div[class="torrent_stats"]').parent();
|
||||||
const description = content.find('div[id="main"]');
|
const description = content.find('div[id="main"]');
|
||||||
const magnetLink = info.find('a[title="Download verified Magnet"]').attr('href');
|
const magnetLink = info.find('a[title="Download verified Magnet"]').attr('href');
|
||||||
const imdbIdMatch = description.html().match(/imdb\.com\/title\/tt(\d+)/i);
|
const imdbIdMatch = description.html().match(/imdb\.com\/title\/(tt\d+)/i);
|
||||||
|
|
||||||
const torrent = {
|
const torrent = {
|
||||||
name: info.find('h1').first().text(),
|
name: info.find('h1').first().text(),
|
||||||
@@ -134,7 +134,7 @@ function parseTorrentPage(body) {
|
|||||||
size: parseSize(description.find('ul[class="file_list"]').first().find('li').first().contents().eq(2).text()
|
size: parseSize(description.find('ul[class="file_list"]').first().find('li').first().contents().eq(2).text()
|
||||||
.match(/\(Size: (.+)\)/)[1]),
|
.match(/\(Size: (.+)\)/)[1]),
|
||||||
uploadDate: moment(info.find('time').first().text()).toDate(),
|
uploadDate: moment(info.find('time').first().text()).toDate(),
|
||||||
imdbId: imdbIdMatch && `tt${imdbIdMatch[1].padStart(7, '0')}`,
|
imdbId: imdbIdMatch && imdbIdMatch[1],
|
||||||
files: content.find('ul[class="file_list"]').first().find('li > ul > li[class="file_list__file"]')
|
files: content.find('ul[class="file_list"]').first().find('li > ul > li[class="file_list__file"]')
|
||||||
.map((i, elem) => $(elem))
|
.map((i, elem) => $(elem))
|
||||||
.map((i, ele) => ({
|
.map((i, ele) => ({
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ function parseTorrentPage(body) {
|
|||||||
}
|
}
|
||||||
const details = $('div[id=\'details\']');
|
const details = $('div[id=\'details\']');
|
||||||
const col1 = details.find('dl[class=\'col1\']');
|
const col1 = details.find('dl[class=\'col1\']');
|
||||||
const imdbIdMatch = col1.html().match(/imdb\.com\/title\/tt(\d+)/i);
|
const imdbIdMatch = col1.html().match(/imdb\.com\/title\/(tt\d+)/i);
|
||||||
|
|
||||||
const torrent = {
|
const torrent = {
|
||||||
name: $('div[id=\'title\']').text().trim(),
|
name: $('div[id=\'title\']').text().trim(),
|
||||||
@@ -209,7 +209,7 @@ function parseTorrentPage(body) {
|
|||||||
subcategory: parseInt(col1.find('a[title=\'More from this category\']').eq(0).attr('href').match(/\d+$/)[0], 10),
|
subcategory: parseInt(col1.find('a[title=\'More from this category\']').eq(0).attr('href').match(/\d+$/)[0], 10),
|
||||||
size: parseSize(details.find('dt:contains(\'Size:\')').next().text().match(/(\d+)(?:.?Bytes)/)[1]),
|
size: parseSize(details.find('dt:contains(\'Size:\')').next().text().match(/(\d+)(?:.?Bytes)/)[1]),
|
||||||
uploadDate: new Date(details.find('dt:contains(\'Uploaded:\')').next().text()),
|
uploadDate: new Date(details.find('dt:contains(\'Uploaded:\')').next().text()),
|
||||||
imdbId: imdbIdMatch && `tt${imdbIdMatch[1].padStart(7, '0')}`
|
imdbId: imdbIdMatch && imdbIdMatch[1]
|
||||||
};
|
};
|
||||||
resolve(torrent);
|
resolve(torrent);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user