-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eztv-provider): Added eztv provider
- Loading branch information
Showing
9 changed files
with
160 additions
and
0 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "../../../.eslintrc", "rules": {}, "ignorePatterns": ["!**/*"] } |
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,14 @@ | ||
module.exports = { | ||
name: 'scraper-eztv-provider', | ||
preset: '../../../jest.config.js', | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../../coverage/libs/scraper/eztv-provider', | ||
}; |
23 changes: 23 additions & 0 deletions
23
libs/scraper/eztv-provider/src/eztv-provider.interfaces.ts
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,23 @@ | ||
export interface YtsTorrent { | ||
|
||
title: string | ||
|
||
imdb_code: string | ||
|
||
year: string | ||
|
||
language: string | ||
|
||
torrents: [{ | ||
hash: string | ||
|
||
peers: number | ||
|
||
quality: string | ||
|
||
seeds: number | ||
|
||
size_bytes: number | ||
}] | ||
|
||
} |
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,10 @@ | ||
import { Module } from '@nestjs/common' | ||
|
||
import { EztvProviderService } from './yts-provider.service' | ||
|
||
@Module({ | ||
providers: [EztvProviderService], | ||
exports: [EztvProviderService] | ||
}) | ||
export class EztvProviderModule { | ||
} |
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,70 @@ | ||
import { Injectable, Logger } from '@nestjs/common' | ||
import { BaseProvider, ScrapedItem, ScraperProviderConfig, ShowType } from '@pct-org/scraper/base-provider' | ||
import * as Eztv from '@pct-org/eztv-api' | ||
import * as pMap from 'p-map' | ||
|
||
@Injectable() | ||
export class EztvProviderService extends BaseProvider { | ||
|
||
name = 'EZTV' | ||
|
||
maxWebRequests = 2 | ||
|
||
logger = new Logger(this.name) | ||
|
||
configs: ScraperProviderConfig[] = [{ | ||
contentType: ShowType | ||
}] | ||
|
||
api | ||
|
||
constructor() { | ||
super() | ||
|
||
this.api = new Eztv() | ||
} | ||
|
||
protected async scrapeConfig(config: ScraperProviderConfig): Promise<void> { | ||
this.setConfig(config) | ||
|
||
const contents: ScrapedItem[] = await this.api.getAll() | ||
|
||
this.logger.log(`${this.name}: Found ${contents.length} ${this.contentType}s.`) | ||
|
||
await pMap( | ||
contents, | ||
async (content) => { | ||
const isInBlacklist = await this.isItemBlackListed(content) | ||
|
||
// Only get data for this item if it's not in the blacklist | ||
if (!isInBlacklist) { | ||
try { | ||
// Get full show data | ||
const show: ScrapedItem = this.api.getShowData(content) | ||
|
||
// Enhance and import the show | ||
await this.enhanceAndImport(show) | ||
|
||
} catch (err) { | ||
const errorMessage = err.message || err | ||
|
||
this.logger.error(`BaseProvider.scrapeConfig`, err) | ||
|
||
// Log the content so it can be better debugged from logs | ||
if (errorMessage.includes('Could not find any data with slug')) { | ||
this.logger.error(JSON.stringify(content)) | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
concurrency: this.maxWebRequests | ||
} | ||
) | ||
} | ||
|
||
extractContent({ torrent, regex, lang }: { torrent: any; regex: any; lang: any }): undefined { | ||
return undefined | ||
} | ||
|
||
} |
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,3 @@ | ||
export * from './eztv-provider.module' | ||
export * from './eztv-provider.service' | ||
|
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,13 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
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,11 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "../../../dist/out-tsc", | ||
"declaration": true, | ||
"types": ["node"] | ||
}, | ||
"exclude": ["**/*.spec.ts"], | ||
"include": ["**/*.ts"] | ||
} |
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,15 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"**/*.spec.ts", | ||
"**/*.spec.tsx", | ||
"**/*.spec.js", | ||
"**/*.spec.jsx", | ||
"**/*.d.ts" | ||
] | ||
} |