kepler471 / dvembed Goto Github PK
View Code? Open in Web Editor NEWDiscord bot to properly embed media from v.redd.it
License: GNU General Public License v3.0
Discord bot to properly embed media from v.redd.it
License: GNU General Public License v3.0
Hey!
Updated the bot to the most recent build and tried first using go run dvembed and since that didnt work i tried with the .exe to see if that would solve it, in both instances I get the same error:
2021/07/15 13:51:25 dvembed bot is now running. Press CTRL-C to exit.
2021/07/15 13:51:38 ṁͫ i̇ͥ j͐ͥ ȧͣ `test`
2021/07/15 13:51:38 ṁͫ i̇ͥ j͐ͥ ȧͣ `https://old.reddit.com/r/aww/comments/okk00k/i_am_so_happy_i_found_this/`
2021/07/15 13:51:38 Message sent on channel: 211609129284796418
2021/07/15 13:51:38 Message unit: `https://old.reddit.com/r/aww/comments/okk00k/i_am_so_happy_i_found_this/`, is valid URl
2021/07/15 13:51:38 Checking JSON for media type...
2021/07/15 13:51:39 ...fallback_url found, v.redd.it media confirmed. Continue...
2021/07/15 13:51:39 Entering download process >
2021/07/15 13:51:39 ...run youtube-dl...
2021/07/15 13:51:42 Error finding downloaded file: CreateFile downloads/i_am_so_happy_i_found_this/i_am_so_happy_i_found_this.mp4: The system cannot find the file specified.
2021/07/15 13:51:42 did not download: CreateFile downloads/i_am_so_happy_i_found_this/i_am_so_happy_i_found_this.mp4: The system cannot find the file specified.
Any suggestions on how to solve this?
As mentioned in #7 , various URLs of different video sizes are held in this json. Create a type and Unmarshal, it is not a deeply nested json so the type structure should not be difficult to create.
For small and medium size files, the file size will be known from the URL. For large files, only the resolution is listed, so will need to come up with a different system.
Sometimes a link which just has an image, will be processed as if there is a video, and so the bot will send that image, converted to mp4, as a video which seems to just have one frame.
This will mean the video shows up with the correct name, useful for someone who wants to download from the bot's message.
This will require working back from a short link, getting hte long link, and finding the post title in the JSON or using the base of the url which is formatted nicely already for filenames, with underscores.
Test to see if media is redownloaded if both the long and short forms of the link have been seen by the bot.
My guess is yes, it will be, as this is checked by file path, which is determined by URL.
Lines 33 to 37 in 8651edf
When a user posts a link, the link is embedded with either a reddit icon, or a preview image of the v.redd.it media.
I attempted to replace the user's message embed with a blank embed but it fails.
I got this issue no matter what:
2021/01/21 16:37:02 dvembed bot is now running. Press CTRL-C to exit.
2021/01/21 16:37:17 name https://v.redd.it/8b7qosjl6oc61 [0xc00019c1e0] &[0xc00019c1e0]
2021/01/21 16:37:17 Message by name contains v.redd.it link: https://v.redd.it/8b7qosjl6oc61
2021/01/21 16:37:17 Message sent on channel: 793927661822935100
2021/01/21 16:37:17 Message segment: https://v.redd.it/8b7qosjl6oc61, is valid URl
2021/01/21 16:37:17 Entering download process >
2021/01/21 16:37:17 ...run youtube-dl...
2021/01/21 16:37:17 Failed youtube-dl process: [youtube-dl -v --output 8b7qosjl6oc61.mp4 --write-info-json --merge-output-format mp4 https://v.redd.it/8b7qosjl6oc61]
2021/01/21 16:37:17 Did not download: exec: "downloads\8b7qosjl6oc61\youtube-dl.exe": file does not exist
was unable to solve it until i changed download.go to this:
package main
import (
"log"
"os"
"os/exec"
"path"
"fmt"
)
type media struct {
os.FileInfo
Id string
Path string
}
// download handles retrieving the v.redd.it media. Initialises
// a media instance for each URL.
func download(URL string) (*media, error) {
f := media{
Id: path.Base(URL),
}
dir, _ := os.Getwd()
cmd := exec.Command(
fmt.Sprintf("%v/youtube-dl", dir),
"-v",
//"--id", // use id as name
"--output",
f.Id+originalExt,
"--write-info-json", // save file information
//"--restrict-filenames",
"--merge-output-format", // Downloading the best available audio and video
outputFormat,
URL,
)
cmd.Dir = path.Join(dir, f.Id)
err := os.MkdirAll(cmd.Dir, 0755)
if err != nil {
log.Printf("\tError creating sub-directory: %v", err)
cmd.Dir = dir
}
f.Path = path.Join(cmd.Dir, f.Id+originalExt)
if info, err := os.Stat(f.Path); !os.IsNotExist(err) {
log.Printf("\tFile at %v exists, will not be downlaoded. Err: %v", f.Path, err)
f.FileInfo = info
return &f, nil
} else {
log.Print("\t...run youtube-dl...")
err = cmd.Run()
if err != nil {
log.Printf("\tFailed youtube-dl process: %v", cmd.Args)
return &f, err
}
}
f.FileInfo, err = os.Stat(f.Path)
if err != nil {
log.Print("\tError finding downloaded file: ", err)
}
// TODO want to return output error from youtube-dl
return &f, err
}
this solved the issue.
Could use yt-dlp?
Since the last commits in 2021, Discord actually added their own way to embed v.redd.it media, and so dvembed
was redundant.
As of now, v.redd.it media no longer embeds again, so this app is useful again!
Be aware that there is also a HLSPLaylist.m3u8, which also hosts a set of video files. For some videos, the youtube-dl "best" option which is default, will select on of these, which leads to some of the test cases I have seen where the original video was not the same size as the largest video hosted on DASHPlaylist.mpd. HLS will be ignored for now, will aim to get this feature fully working with DASH first.
Originally posted by @kepler471 in #7 (comment)
It would be nice to not require that youtube-dl be installed.
The audio and video can be accessed separately and then combined.
This may also give access to different sized video files, so an appropriately sized video can be selected, potentially reducing the number of videos that need to be compressed, or the compression time of certain videos.
How to access media:
after the last backslash of the reddit post's url, add '.json'
find the fallback_url. this is a link to the video.
For audio, use fallback_url, except replace DASH_x_x_M with 'audio'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.