Changing up YTmusic implementation
This commit is contained in:
4
src/app.d.ts
vendored
4
src/app.d.ts
vendored
@@ -42,7 +42,7 @@ declare global {
|
|||||||
connectionId: string
|
connectionId: string
|
||||||
serviceType: serviceType
|
serviceType: serviceType
|
||||||
type: 'song'
|
type: 'song'
|
||||||
duration: number
|
duration?: number
|
||||||
artists?: {
|
artists?: {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
@@ -60,7 +60,7 @@ declare global {
|
|||||||
connectionId: string
|
connectionId: string
|
||||||
serviceType: serviceType
|
serviceType: serviceType
|
||||||
type: 'album'
|
type: 'album'
|
||||||
duration: number
|
duration?: number
|
||||||
albumArtists?: {
|
albumArtists?: {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
|
|||||||
Binary file not shown.
@@ -74,6 +74,7 @@ declare namespace InnerTube {
|
|||||||
}
|
}
|
||||||
contents: {
|
contents: {
|
||||||
musicTwoRowItemRenderer?: musicTwoRowItemRenderer
|
musicTwoRowItemRenderer?: musicTwoRowItemRenderer
|
||||||
|
musicResponsiveListItemRenderer?: musicResponsiveListItemRenderer
|
||||||
}[]
|
}[]
|
||||||
trackingParams: string
|
trackingParams: string
|
||||||
itemSize: string
|
itemSize: string
|
||||||
@@ -105,6 +106,22 @@ declare namespace InnerTube {
|
|||||||
thumbnailOverlay: unknown
|
thumbnailOverlay: unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type musicResponsiveListItemRenderer = {
|
||||||
|
thumbnail: {
|
||||||
|
musicThumbnailRenderer: musicThumbnailRenderer
|
||||||
|
}
|
||||||
|
overlay: unknown
|
||||||
|
flexColumns: {
|
||||||
|
musicResponsiveListItemFlexColumnRenderer: {
|
||||||
|
text: { runs: [runs<'watch' | 'browse'>] }
|
||||||
|
}
|
||||||
|
}[]
|
||||||
|
menu: unknown
|
||||||
|
playlistItemData: {
|
||||||
|
videoId: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type musicThumbnailRenderer = {
|
type musicThumbnailRenderer = {
|
||||||
thumbnail: {
|
thumbnail: {
|
||||||
thumbnails: {
|
thumbnails: {
|
||||||
@@ -129,19 +146,18 @@ declare namespace InnerTube {
|
|||||||
: { text: string }
|
: { text: string }
|
||||||
|
|
||||||
type endpointType = 'browse' | 'watch' | 'watchPlaylist'
|
type endpointType = 'browse' | 'watch' | 'watchPlaylist'
|
||||||
type navigationEndpoint<T extends endpointType> = T extends 'browse'
|
type navigationEndpoint<T extends endpointType> = {
|
||||||
? {
|
|
||||||
clickTrackingParams: string
|
clickTrackingParams: string
|
||||||
|
} & T extends 'browse'
|
||||||
|
? {
|
||||||
browseEndpoint: browseEndpoint
|
browseEndpoint: browseEndpoint
|
||||||
}
|
}
|
||||||
: T extends 'watch'
|
: T extends 'watch'
|
||||||
? {
|
? {
|
||||||
clickTrackingParams: string
|
|
||||||
watchEndpoint: watchEndpoint
|
watchEndpoint: watchEndpoint
|
||||||
}
|
}
|
||||||
: T extends 'watchPlaylist'
|
: T extends 'watchPlaylist'
|
||||||
? {
|
? {
|
||||||
clickTrackingParams: string
|
|
||||||
watchPlaylistEndpoint: watchPlaylistEndpoint
|
watchPlaylistEndpoint: watchPlaylistEndpoint
|
||||||
}
|
}
|
||||||
: never
|
: never
|
||||||
@@ -178,11 +194,6 @@ declare namespace InnerTube {
|
|||||||
label: string
|
label: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface YouTubeMusicClient {
|
|
||||||
userId: string
|
|
||||||
accessToken: string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class YouTubeMusic {
|
export class YouTubeMusic {
|
||||||
@@ -269,50 +280,30 @@ export class YouTubeMusic {
|
|||||||
|
|
||||||
console.log(response.status)
|
console.log(response.status)
|
||||||
const data: InnerTube.BrowseResponse = await response.json()
|
const data: InnerTube.BrowseResponse = await response.json()
|
||||||
const results = data.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents
|
const contents = data.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents.flatMap((section) => section.musicCarouselShelfRenderer.contents)
|
||||||
const home: { id: string; name: string }[] = []
|
console.log(JSON.stringify(contents[0]))
|
||||||
for (const result of results) {
|
|
||||||
const homeSection = result.musicCarouselShelfRenderer.contents
|
for (const item of contents) {
|
||||||
for (const item of homeSection) {
|
let artists: Song['artists'], album: Song['album']
|
||||||
if (item.musicTwoRowItemRenderer?.navigationEndpoint) {
|
|
||||||
let id: string
|
if (item.musicResponsiveListItemRenderer) {
|
||||||
const navigationEndpoint = item.musicTwoRowItemRenderer.navigationEndpoint
|
for (const column of item.musicResponsiveListItemRenderer.flexColumns) {
|
||||||
if ('browseEndpoint' in navigationEndpoint) {
|
const text = column.musicResponsiveListItemFlexColumnRenderer.text.runs[0].text
|
||||||
id = navigationEndpoint.browseEndpoint.browseId
|
const endpoint = column.musicResponsiveListItemFlexColumnRenderer.text.runs[0].navigationEndpoint!
|
||||||
} else if ('watchEndpoint' in navigationEndpoint) {
|
if ('watchEndpoint' in endpoint) {
|
||||||
id = navigationEndpoint.watchEndpoint.videoId
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
home.push({ id, name: item.musicTwoRowItemRenderer.title.runs[0].text })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const youtube = google.youtube('v3')
|
private getDatestamp = () => {
|
||||||
const videoInfo = await youtube.videos.list({
|
const currentDate = new Date()
|
||||||
id: home.map((video) => video.id),
|
const epochDate = new Date(0)
|
||||||
part: ['contentDetails', 'snippet', 'statistics'],
|
const daysDifference = Math.floor((currentDate.getTime() - epochDate.getTime()) / (24 * 60 * 60 * 1000))
|
||||||
access_token: this.accessToken,
|
return daysDifference
|
||||||
})
|
|
||||||
console.log(JSON.stringify(videoInfo))
|
|
||||||
|
|
||||||
// console.log(JSON.stringify(results[0].musicCarouselShelfRenderer.contents[0]))
|
|
||||||
|
|
||||||
// const sectionList = data.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer
|
|
||||||
// if ('continuations' in sectionList) {
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const song: Song = {
|
|
||||||
// connectionId: this.connectionId,
|
|
||||||
// serviceType: 'youtube-music',
|
|
||||||
// type: 'song',
|
|
||||||
// id: home[0].id,
|
|
||||||
// name: home[0].name,
|
|
||||||
// duration:
|
|
||||||
// }
|
|
||||||
// return home
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getSong = async (videoId: string) => {
|
public getSong = async (videoId: string) => {
|
||||||
@@ -323,8 +314,9 @@ export class YouTubeMusic {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
playbackContext: {
|
playbackContext: {
|
||||||
contentPlaybackContext: { signatureTimestamp: }
|
contentPlaybackContext: { signatureTimestamp: this.getDatestamp() - 1 },
|
||||||
},
|
},
|
||||||
|
videoId,
|
||||||
context: {
|
context: {
|
||||||
client: {
|
client: {
|
||||||
clientName: 'WEB_REMIX',
|
clientName: 'WEB_REMIX',
|
||||||
@@ -334,6 +326,10 @@ export class YouTubeMusic {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log(response.status)
|
||||||
|
const data = await response.json()
|
||||||
|
console.log(JSON.stringify(data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user