-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search for YouTube videos and convert them to Spotify URIs
- Loading branch information
Showing
6 changed files
with
157 additions
and
25 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
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
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
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
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,29 @@ | ||
import fetch from 'node-fetch'; | ||
import * as queryString from 'query-string'; | ||
const getYouTubeID = require('get-youtube-id'); | ||
|
||
interface YouTubeVideo { | ||
id: string; | ||
title: string; | ||
} | ||
|
||
export default class YouTube { | ||
public static async getVideo(url: string): Promise<YouTubeVideo> { | ||
const id = getYouTubeID(url); | ||
if (!id) { | ||
return; | ||
} | ||
|
||
const response = await fetch( | ||
`http://youtube.com/get_video_info?html5=1&video_id=${id}`, | ||
).then(res => res.text()); | ||
|
||
const query = queryString.parse(response); | ||
const { videoDetails } = JSON.parse(query.player_response.toString()); | ||
|
||
return { | ||
id: videoDetails.videoId, | ||
title: videoDetails.title, | ||
}; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -720,6 +720,10 @@ fsevents@^1.2.7: | |
nan "^2.12.1" | ||
node-pre-gyp "^0.12.0" | ||
|
||
fuse.js@^3.4.5: | ||
version "3.4.5" | ||
resolved "https://registry.yarnpkg.com/fuse.js/-/fuse.js-3.4.5.tgz#8954fb43f9729bd5dbcb8c08f251db552595a7a6" | ||
|
||
gauge@~2.7.3: | ||
version "2.7.4" | ||
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7" | ||
|
@@ -741,6 +745,10 @@ get-value@^2.0.3, get-value@^2.0.6: | |
version "2.0.6" | ||
resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" | ||
|
||
get-youtube-id@^1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/get-youtube-id/-/get-youtube-id-1.0.1.tgz#adb6f475e292d98f98ed5bfb530887656193e157" | ||
|
||
glob-parent@^3.1.0: | ||
version "3.1.0" | ||
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-3.1.0.tgz#9e6af6299d8d3bd2bd40430832bd113df906c5ae" | ||
|
@@ -1232,6 +1240,10 @@ [email protected]: | |
version "0.6.2" | ||
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb" | ||
|
||
node-fetch@^2.6.0: | ||
version "2.6.0" | ||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" | ||
|
||
node-pre-gyp@^0.12.0: | ||
version "0.12.0" | ||
resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.12.0.tgz#39ba4bb1439da030295f899e3b520b7785766149" | ||
|
@@ -1446,6 +1458,14 @@ [email protected], qs@^6.5.1: | |
version "6.7.0" | ||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc" | ||
|
||
query-string@^6.8.3: | ||
version "6.8.3" | ||
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.8.3.tgz#fd9fb7ffb068b79062b43383685611ee47777d4b" | ||
dependencies: | ||
decode-uri-component "^0.2.0" | ||
split-on-first "^1.0.0" | ||
strict-uri-encode "^2.0.0" | ||
|
||
range-parser@~1.2.1: | ||
version "1.2.1" | ||
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031" | ||
|
@@ -1680,6 +1700,10 @@ source-map@^0.6.0: | |
version "0.6.1" | ||
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" | ||
|
||
split-on-first@^1.0.0: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f" | ||
|
||
split-string@^3.0.1, split-string@^3.0.2: | ||
version "3.1.0" | ||
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2" | ||
|
@@ -1703,6 +1727,10 @@ static-extend@^0.1.1: | |
version "1.5.0" | ||
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" | ||
|
||
strict-uri-encode@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546" | ||
|
||
string-width@^1.0.1: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3" | ||
|