Skip to content

Commit

Permalink
Fix unable to get channel id and video id issues.
Browse files Browse the repository at this point in the history
GoneTone committed Nov 18, 2023

Verified

This commit was signed with the committer’s verified signature.
mcs Marcus
1 parent b138e53 commit bcb5ab1
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gonetone/get-youtube-id-by-url",
"version": "1.0.0",
"version": "1.0.1",
"description": "Get YouTube channel or video id by url!",
"main": "index.js",
"scripts": {
12 changes: 4 additions & 8 deletions src/GetYouTubeIdByUrl.js
Original file line number Diff line number Diff line change
@@ -63,10 +63,8 @@ const channelId = async (url) => {
const ytChannelPageResponse = await axiosInstance.get(url)
const $ = cheerio.load(ytChannelPageResponse.data)

const id = $('meta[itemprop="channelId"]').attr('content')
if (id) {
return id
}
const id = $('meta[itemprop="identifier"]').attr('content')
if (id) return id
} else {
throw Error(`"${url}" is not a YouTube url.`)
}
@@ -85,10 +83,8 @@ const videoId = async (url) => {
const ytChannelPageResponse = await axiosInstance.get(url)
const $ = cheerio.load(ytChannelPageResponse.data)

const id = $('meta[itemprop="videoId"]').attr('content')
if (id) {
return id
}
const id = $('meta[itemprop="identifier"]').attr('content')
if (id) return id
} else {
throw Error(`"${url}" is not a YouTube url.`)
}

0 comments on commit bcb5ab1

Please sign in to comment.