Alt-text scraping and crossposting
This commit is contained in:
parent
818bd55237
commit
4fdd9f0634
2 changed files with 16 additions and 3 deletions
|
@ -59,6 +59,7 @@ class Tweets {
|
|||
this.hasMultiImage = false;
|
||||
this.hasImages = false;
|
||||
this.imgArray = [];
|
||||
this.imgAltArray = [];
|
||||
this.imgCount = 0;
|
||||
this.imgUrl = "";
|
||||
this.iterateExists = false;
|
||||
|
@ -212,6 +213,9 @@ class Tweets {
|
|||
if (this.hasSingleImage) {
|
||||
debuglog(`${this.orig} Tweet #${this.no} contains a single image.`, 2)
|
||||
this.imgCount = 1;
|
||||
var imgAltText = await elements.getAttribute(driver,this.x.singleImage,"alt")
|
||||
this.imgAltArray.push(imgAltText);
|
||||
debuglog(this.imgAltArray,2);
|
||||
var origImageURL = await elements.getAttribute(driver,this.x.singleImage,"src")
|
||||
const reg = /&name=\w+/
|
||||
this.imgUrl = origImageURL.replace(reg, "&name=large");
|
||||
|
@ -229,6 +233,9 @@ class Tweets {
|
|||
this.iterateExists = await elements.doesExist(driver,this.x.multiImages(x,y));
|
||||
if (this.iterateExists) {
|
||||
debuglog(`${x},${y} Exists!`);
|
||||
var imgAltText = await elements.getAttribute(driver,this.x.multiImages(x,y),"alt")
|
||||
this.imgAltArray.push(imgAltText);
|
||||
debuglog(this.imgAltArray,2);
|
||||
var origImageURL = await elements.getAttribute(driver,this.x.multiImages(x,y),'src')
|
||||
const reg = /&name=\w+/
|
||||
this.imgUrl = origImageURL.replace(reg, "&name=large");
|
||||
|
@ -253,7 +260,8 @@ class Tweets {
|
|||
for (var f = 1; f < (this.imgCount+1); f++) {
|
||||
var jpgPath = `${imgSavePath}${this.orig == 'home' ? '' : 'r'}${this.no}.${f}.jpg`
|
||||
debuglog(`uploading image to mastodon: ${jpgPath}`);
|
||||
var imgid = await mastodon.postMedia(jpgPath)
|
||||
debuglog(this.imgAltArray);
|
||||
var imgid = await mastodon.postMedia(jpgPath,this.imgAltArray[f-1]);
|
||||
debuglog(`mastodon image id: ${imgid}`);
|
||||
this.imgArray.push(imgid);
|
||||
}
|
||||
|
|
|
@ -19,11 +19,16 @@ function setupMastodon(){
|
|||
return M;
|
||||
}
|
||||
|
||||
async function postMedia(path){
|
||||
async function postMedia(path,alt){
|
||||
id = 0;
|
||||
if (alt == null) {
|
||||
alt = "Image";
|
||||
}
|
||||
if (args.enablePosts){
|
||||
var M = setupMastodon();
|
||||
await M.post('media', { file: fs.createReadStream(path) }).then(resp => {
|
||||
params = { file: fs.createReadStream(path) }
|
||||
Object.assign(params, { description: alt });
|
||||
await M.post('media', params).then(resp => {
|
||||
id = resp.data.id;
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
|
|
Reference in a new issue