Commit 5b829faa authored by Melroy van den Berg's avatar Melroy van den Berg

check for undefined

parent 7b73f18f
Pipeline #1629 passed with stage
in 1 minute and 18 seconds
......@@ -203,32 +203,38 @@ Oldest address in keypool: ${oldestKeyTime}
const chatId = msg.chat.id
this.lbry.getMetaFileData(uri)
.then(result => {
if ('error' in result) {
if (typeof result === 'undefined') {
this.bot.sendMessage(chatId, 'Error: meta data result is undefined. Something went wrong.', { parse_mode: 'markdown' })
} else if ('error' in result) {
this.bot.sendMessage(chatId, 'Error: ' + result.error, { parse_mode: 'markdown' })
} else {
// Retrieve the channel name as well
this.lbry.getChannelNameString(result.channel_claim_id)
.then(channelResult => {
const title = result.metadata.title
const channelName = channelResult[0].name
let duration = ''
if (result.metadata.video) {
const durationMin = Math.floor(parseFloat(result.metadata.video.duration) / 60)
const durationSec = (((parseFloat(result.metadata.video.duration) / 60) % 2) * 60).toFixed(0)
duration = `\n*Duration:* ${durationMin}m ${durationSec}s`
}
const fileSize = parseFloat(result.metadata.source.size / Math.pow(1024, 2)).toFixed(2) // To Megabyte
const uriWithoutProtocol = uri.replace(/(^\w+:|^)\/\//, '')
const publicURL = LBRY_TV_URL + '/' + uriWithoutProtocol
const textMsg = `
if (typeof channelResult === 'undefined') {
this.bot.sendMessage(chatId, 'Error: channel result is undefined. Something went wrong.', { parse_mode: 'markdown' })
} else {
const title = result.metadata.title
const channelName = channelResult[0].name
let duration = ''
if (result.metadata.video) {
const durationMin = Math.floor(parseFloat(result.metadata.video.duration) / 60)
const durationSec = (((parseFloat(result.metadata.video.duration) / 60) % 2) * 60).toFixed(0)
duration = `\n*Duration:* ${durationMin}m ${durationSec}s`
}
const fileSize = parseFloat(result.metadata.source.size / Math.pow(1024, 2)).toFixed(2) // To Megabyte
const uriWithoutProtocol = uri.replace(/(^\w+:|^)\/\//, '')
const publicURL = LBRY_TV_URL + '/' + uriWithoutProtocol
const textMsg = `
*Title:* ${title}
*Channel name:* [${channelName}](${OPEN_URL}/${channelName})
*Media Type:* ${result.metadata.source.media_type}${duration}
*Size:* ${fileSize} MB
[Watch Online!](${publicURL})
[Watch via LBRY App](${OPEN_URL}/${uriWithoutProtocol})`
this.bot.sendMessage(chatId, textMsg, { parse_mode: 'markdown' })
// Disable thumbnail: if (thumbnail) { this.bot.sendPhoto(chatId, result.metadata.thumbnail.url, { caption: 'Thumbnail: ' + title }) }
this.bot.sendMessage(chatId, textMsg, { parse_mode: 'markdown' })
// Disable thumbnail: if (thumbnail) { this.bot.sendPhoto(chatId, result.metadata.thumbnail.url, { caption: 'Thumbnail: ' + title }) }
}
})
.catch(error => {
console.error(error.message)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment