diff --git a/scraper/lib/torrentEntries.js b/scraper/lib/torrentEntries.js index 42f793a..66d69a6 100644 --- a/scraper/lib/torrentEntries.js +++ b/scraper/lib/torrentEntries.js @@ -15,6 +15,10 @@ async function createTorrentEntry(torrent) { torrent.imdbId = await getImdbId(titleInfo, torrent.type) .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')) { // sanitize imdbId from redundant zeros torrent.imdbId = torrent.imdbId.replace(/tt0+([0-9]{7,})$/, 'tt$1'); diff --git a/scraper/scrapers/1337x/1337x_api.js b/scraper/scrapers/1337x/1337x_api.js index 4ad2823..62db8ec 100644 --- a/scraper/scrapers/1337x/1337x_api.js +++ b/scraper/scrapers/1337x/1337x_api.js @@ -113,7 +113,7 @@ function parseTorrentPage(body) { const details = $('.torrent-detail-page'); 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 = { name: decode(magnetLink).name.replace(/\+/g, ' '), @@ -125,7 +125,7 @@ function parseTorrentPage(body) { language: details.find('strong:contains(\'Language\')').next().text(), size: parseSize(details.find('strong:contains(\'Total size\')').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') .map((i, elem) => $(elem).text()) .map((i, text) => ({ diff --git a/scraper/scrapers/kickass/kickass_api.js b/scraper/scrapers/kickass/kickass_api.js index d7307de..84ec165 100644 --- a/scraper/scrapers/kickass/kickass_api.js +++ b/scraper/scrapers/kickass/kickass_api.js @@ -121,7 +121,7 @@ function parseTorrentPage(body) { const info = content.find('div[class="torrent_stats"]').parent(); const description = content.find('div[id="main"]'); 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 = { 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() .match(/\(Size: (.+)\)/)[1]), 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"]') .map((i, elem) => $(elem)) .map((i, ele) => ({ diff --git a/scraper/scrapers/thepiratebay/thepiratebay_api.js b/scraper/scrapers/thepiratebay/thepiratebay_api.js index 2e483d6..6d9d6e5 100644 --- a/scraper/scrapers/thepiratebay/thepiratebay_api.js +++ b/scraper/scrapers/thepiratebay/thepiratebay_api.js @@ -197,7 +197,7 @@ function parseTorrentPage(body) { } const details = $('div[id=\'details\']'); 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 = { 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), size: parseSize(details.find('dt:contains(\'Size:\')').next().text().match(/(\d+)(?:.?Bytes)/)[1]), uploadDate: new Date(details.find('dt:contains(\'Uploaded:\')').next().text()), - imdbId: imdbIdMatch && `tt${imdbIdMatch[1].padStart(7, '0')}` + imdbId: imdbIdMatch && imdbIdMatch[1] }; resolve(torrent); });