diff --git a/.github/stale.yml b/.github/stale.yml deleted file mode 100644 index 533c538..0000000 --- a/.github/stale.yml +++ /dev/null @@ -1,18 +0,0 @@ -# Number of days of inactivity before an issue becomes stale -daysUntilStale: 60 -# Number of days of inactivity before a stale issue is closed -daysUntilClose: 7 -# Issues with these labels will never be considered stale -exemptLabels: - - bug - - enhancement - - help wanted -# Label to use when marking an issue as stale -staleLabel: stale -# Comment to post when marking an issue as stale. Set to `false` to disable -markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. Thank you - for your contributions. -# Comment to post when closing a stale issue. Set to `false` to disable -closeComment: false diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 804e31b..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Lint - -on: [push, pull_request] - -jobs: - eslint: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - - uses: actions/setup-node@v1 - with: - node-version: 14.x - - - name: npm install, build, and lint - run: | - npm install - npm run build --if-present - npm run-script lint - npm run-script lint:typings diff --git a/.github/workflows/node_ci.yml b/.github/workflows/node_ci.yml deleted file mode 100644 index 7e2941d..0000000 --- a/.github/workflows/node_ci.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Node.js CI - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [10.x, 12.x, 14.x] - - steps: - - uses: actions/checkout@v2 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - run: npm install - - run: npm run build --if-present - - run: npm test - env: - CI: true - - codecov: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Use Node.js 14.x - uses: actions/setup-node@v1 - with: - node-version: 14.x - - - run: npm install - - run: npm run build --if-present - - run: npm run-script test:coverage - env: - CI: true diff --git a/.gitignore b/.gitignore index 805e581..e5e58d6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ node_modules coverage .nyc_output dumps -.vscode +.vscode \ No newline at end of file diff --git a/example/artistmix.js b/example/artistmix.js new file mode 100644 index 0000000..0fb51e9 --- /dev/null +++ b/example/artistmix.js @@ -0,0 +1,11 @@ +const YTSR = require('../'); + +const main = async() => { + return await YTSR('enrique iglesias') +}; + +main().then(results => { + console.log(results.artistDetails) +}).catch(err => { + console.log(err) +}); diff --git a/lib/main.js b/lib/main.js index be00436..82c3b9d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,6 +33,7 @@ const main = module.exports = async(searchString, options, rt = 3) => { refinements: [], items: [], continuation: null, + artistDetails: [] }; // Add refinements if (Array.isArray(parsed.json.refinements)) { @@ -49,6 +50,13 @@ const main = module.exports = async(searchString, options, rt = 3) => { parsed.json.contents.twoColumnSearchResultsRenderer.primaryContents, ); + // Parse Artist details + const artistWrapper = parsed.json.contents + .twoColumnSearchResultsRenderer.secondaryContents; + if (artistWrapper) { + resp.artistDetails = UTIL.parseArtist(artistWrapper) + } + // Parse items resp.items = rawItems.map(a => PARSE_ITEM(a, resp)).filter(a => a).filter((_, index) => index < opts.limit); diff --git a/lib/utils.js b/lib/utils.js index 94e4ace..603a043 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -302,6 +302,30 @@ const cutAfterJSON = exports.cutAfterJSON = mixedJson => { throw Error("Can't cut unsupported JSON (no matching closing bracket found)"); }; +exports.parseArtist = (wrapper) => { + const artistDetails = []; + const artistWrapper = wrapper + .secondarySearchContainerRenderer.contents[0] + .universalWatchCardRenderer; + + const artistHeader = artistWrapper.header.watchCardRichHeaderRenderer; + const artistImages = artistWrapper.callToAction.watchCardHeroVideoRenderer.heroImage.collageHeroImageRenderer; + const artistAlbums = artistWrapper.sections[1].watchCardSectionSequenceRenderer.lists[0].horizontalCardListRenderer.cards.map(card => { + return {thumbnail: card.searchRefinementCardRenderer.thumbnail.thumbnails, title: card.searchRefinementCardRenderer.query.runs[0].text} + }); + const artistTracks = artistWrapper.sections[0].watchCardSectionSequenceRenderer.lists[0].verticalWatchCardListRenderer.items.map(track => { + return {thumbnail: track.watchCardCompactVideoRenderer.thumbnail.thumbnails, title: track.watchCardCompactVideoRenderer.title.runs[0].text, + subtitle: track.watchCardCompactVideoRenderer.subtitle.simpleText, length: track.watchCardCompactVideoRenderer.lengthText.simpleText, + videoId:track.watchCardCompactVideoRenderer.navigationEndpoint.watchEndpoint.videoId, playlistId: track.watchCardCompactVideoRenderer.navigationEndpoint.watchEndpoint.playlistId} + }); + artistDetails.push({ + header: {title: artistHeader.title.simpleText, subtitle: artistHeader.subtitle.simpleText, avatar:artistHeader.avatar.thumbnails[0].url}, + images: {leftThumbnail:artistImages.leftThumbnail.thumbnails, topRightThumbnail: artistImages.topRightThumbnail.thumbnails, bottomRightThumbnail: artistImages.bottomRightThumbnail.thumbnails}, + tracks: artistTracks, + albums: artistAlbums + }); + return artistDetails +}; // Exports for testing exports._hidden = { jsonAfter, between, cutAfterJSON, diff --git a/package-lock.json b/package-lock.json index 7d7638d..3293e67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3764,6 +3764,12 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "yargs": { "version": "15.4.1", "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz",