Version 0.3.0-alpha1 - Youtube and Spotify support
This commit is contained in:
@@ -1,39 +1,44 @@
|
||||
const {LogType} = require('loguix')
|
||||
const { createAudioResource, StreamType } = require('@discordjs/voice');
|
||||
|
||||
|
||||
const clog = new LogType("Song")
|
||||
const MediaInformation = require('../media/MediaInformation')
|
||||
const YoutubeDuration = require('../utils/YoutubeDuration');
|
||||
const { getReadableDuration } = require('../utils/TimeConverter');
|
||||
|
||||
class Song {
|
||||
title = "Aucun titre";
|
||||
filename = "Aucun fichier";
|
||||
id = "Aucun fichier";
|
||||
author = "Auteur inconnu"
|
||||
authorId;
|
||||
url;
|
||||
thumbnail = "https://radomisol.fr/wp-content/uploads/2016/08/cropped-note-radomisol-musique.png" ;
|
||||
duration;
|
||||
readduration;
|
||||
type;
|
||||
resource;
|
||||
|
||||
constructor(properties) {
|
||||
if(properties) {
|
||||
this.type = properties.type ?? this.type
|
||||
this.title = properties.title ?? this.title
|
||||
this.filename = properties.filename ?? this.filename
|
||||
this.id = properties.id ?? this.id
|
||||
this.author = properties.author ?? this.author
|
||||
this.url = properties.url ?? this.url
|
||||
this.thumbnail = properties.thumbnail ?? this.thumbnail
|
||||
this.duration = properties.duration ?? this.duration
|
||||
this.readduration = properties.readduration ?? this.readduration
|
||||
this.type = properties.type ?? this.type
|
||||
this.authorId = properties.authorId ?? this.authorId
|
||||
}
|
||||
}
|
||||
|
||||
async processMedia(media, provider) {
|
||||
if(provider) this.author = provider
|
||||
if(provider) this.author = provider;
|
||||
if(provider) this.authorId = provider;
|
||||
// Check if media is a file or a link
|
||||
if(media.attachment) {
|
||||
this.url = media.attachment.url
|
||||
this.filename = media.attachment.name
|
||||
this.id = media.attachment.name
|
||||
this.type = "attachment"
|
||||
|
||||
// In face, duration is null, get the metadata of the file to get the duration
|
||||
@@ -45,18 +50,20 @@ class Song {
|
||||
|
||||
}
|
||||
|
||||
async getResource() {
|
||||
|
||||
const resource = createAudioResource(this.url, {
|
||||
inputType: StreamType.Arbitrary
|
||||
})
|
||||
return resource
|
||||
async processYoutubeVideo(video) {
|
||||
this.title = video.snippet.title
|
||||
this.author = video.snippet.channelTitle
|
||||
this.authorId = video.snippet.channelId
|
||||
this.thumbnail = video.snippet.thumbnails.standard.url
|
||||
this.url = `https://www.youtube.com/watch?v=${video.id}`
|
||||
this.type = "youtube"
|
||||
this.id = video.id
|
||||
|
||||
|
||||
this.duration = await YoutubeDuration.getDurationVideo(video.id)
|
||||
this.readduration = getReadableDuration(this.duration)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user