Skip to content

Commit

Permalink
fix(base-provider): Fixes for updating existing item
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Oct 15, 2020
1 parent 1ac97e0 commit fd405d4
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions libs/scraper/base-provider/src/base.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,22 @@ export abstract class BaseProvider {
const updateExistingItem = existingItem && helper.shouldUpdateExistingItem(existingItem)

let newItem
if (updateExistingItem) {
newItem = await helper.updateTraktInfo(existingItem)
// Check if we have a existing item
if (existingItem) {
// Only update the item if we need to
if (updateExistingItem) {
newItem = await helper.updateTraktInfo(existingItem)

} else {
// Use existing cached / old data
newItem = existingItem
}

} else {
// Add trakt info to the item, will return null if trakt could not find it
newItem = await helper.addTraktInfo(item)
}

let used = process.memoryUsage()
for (let key in used) {
console.log(`${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`)
}

// If Trakt could not find the item then add it to the blacklist
if (!newItem) {
// Try again in 1 week
Expand All @@ -254,7 +258,7 @@ export abstract class BaseProvider {
await helper.addItemToDatabase(newItem)

} else {
await helper.updateItemInDatabase(newItem)
await helper.updateItemInDatabase(newItem, updateExistingItem)
}

return Promise.resolve()
Expand Down Expand Up @@ -338,15 +342,17 @@ export abstract class BaseProvider {
? res.data.movies // YTS
: []

} catch (e) {
} catch (err) {
// If we are allowed to retry then do else throw the error
if (retry) {
this.logger.warn(`On page ${page} "${e}", going to retry.`)

return this.getOnePage(page, false)

} else {
this.logger.error(`On page ${page} "${e}"`)
throw e

throw err
}
}
}
Expand Down Expand Up @@ -405,20 +411,4 @@ export abstract class BaseProvider {
return result.totalPages
}

// async scrapedConfigs(scraped) {
// try {
// if (this.contentType === BaseProvider.ContentTypes.Show) {
// // TODO:: Do post call to the GraphQL api to check and start downloading new my episodes
// logger.info(`Calling GraphQL to update my episodes`)
//
// } else if (this.contentType === BaseProvider.ContentTypes.Movie) {
// // TODO:: Do post call to the GraphQL api to check and start downloading better qualities
// logger.info(`Calling GraphQL to qualities of downloaded movies`)
// }
// } catch (e) {
//
// }
//
// return scraped
// }
}

0 comments on commit fd405d4

Please sign in to comment.