Closed kbravh closed 2 years ago
After restarting Obsidian, I am unable to re-create this "bug". I do backup older versions before I upgrade and may have inadvertently merged some custom code. Please mark this as solved and I will comment again if needed. Apologies for the false alarm. While I'm here, let me share some mods I've made to your plugin to facilitate GIF
s & other small changes. No expectations, do with it as you see fit.
The animated GIF makes it easy to save demos, memes and such as MP4
s. The #round
is a CSS class from Minimal Theme to spice up the profile avatar. The vhn-api-3.netlify.app
call is for an Open Graph Image API deployed on Netlify (@gapmiss/api-opengraph-image). The "nested" level of tagging could be added as a new setting. I couldn't figure out how to discover the video URLs via Twitter API, so I opted to use the info provided to give a little context.
diff:
2425a2426,2431
> function millisToMinutesAndSeconds(millis) {
> var minutes = Math.floor(millis / 60000);
> var seconds = ((millis % 60000) / 1000).toFixed(0);
> return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
> }
>
3802c3808
< 'media.fields': 'url,alt_text',
---
> 'media.fields': 'duration_ms,height,media_key,preview_image_url,public_metrics,type,width,url,alt_text',
3986a3994,4003
> case 'animated_gif':
> // var fp = obsidian.normalizePath(`${assetLocation}/${medium.media_key}.jpg`);
> const tmp = medium.preview_image_url.replace('https://pbs','https://video').replace('_thumb','').replace('jpg','mp4');
> const new_title = tmp.replace('https://video.twimg.com/tweet_video/','');
> const fp = obsidian.normalizePath(`${assetLocation}/${new_title}`);
> // console.log(tmp);
> // console.log(new_title);
> return `\n![${(_a = null) !== null && _a !== void 0 ? _a : medium.media_key}](${fp})`;
> case 'video':
> return `\n![[${(_a = null) !== null && _a !== void 0 ? _a : ''}${filepath}|${medium.width/2}x${medium.height/2}]]\nVideo: ${medium.width}x${medium.height} - ${millisToMinutesAndSeconds(medium.duration_ms)} mins\n`;
4002c4019
< var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
---
> var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
4052c4070
< text = text.replace(new RegExp(`#${tag}`, 'g'), `[#${tag}](https://twitter.com/hashtag/${tag}) `);
---
> text = text.replace(new RegExp(`#${tag}`, 'g'), `[#TWTTR/${tag}](https://twitter.com/hashtag/${tag}) `);
4055a4074,4076
> if (!url.expanded_url.match("twitter.com")) {
> text += `\n\n![](https://vhn-api-3.netlify.app/${encodeURIComponent(url.expanded_url)}/small/)`;
> }
4109c4129
< markdown.push(`![[${filename}${plugin.settings.avatarSize ? `|${plugin.settings.avatarSize}` : ''}]]`);
---
> markdown.push(`![[${filename}${plugin.settings.avatarSize ? `|${plugin.settings.avatarSize}` : ''}#round]]`);
4112c4132
< markdown.push(`![${user.username}${plugin.settings.avatarSize ? `|${plugin.settings.avatarSize}` : ''}](${plugin.settings.downloadAssets ? filename : user.profile_image_url})` // profile image
---
> markdown.push(`![${user.username}${plugin.settings.avatarSize ? `|${plugin.settings.avatarSize}` : ''}](${plugin.settings.downloadAssets ? filename : user.profile_image_url}#round)` // profile image
4205a4227,4247
> case 'animated_gif':
> var tmp = medium.preview_image_url.replace('https://pbs','https://video').replace('_thumb','').replace('jpg','mp4');
> var new_title = tmp.replace('https://video.twimg.com/tweet_video/','');
> // console.log(tmp);
> // console.log(new_title);
> filesToDownload.push({
> // https://video.twimg.com/tweet_video/FNK2z3UWQAYJjdj.mp4
> // https://pbs.twimg.com/tweet_video_thumb/FNK2z3UWQAYJjdj.jpg
> url: tmp,
> // title: `${medium.media_key}.mp4`,
> title: new_title,
> });
> break;
> case 'video' :
> // console.log(medium);
>
> filesToDownload.push({
> url: medium.preview_image_url,
> title: `${medium.media_key}.jpg`,
> });
> break;
@gapmiss Thanks for reporting back! I was doing some testing, and the only way I could replicate the issue was by setting the image location to [[handle]]Twitter/media
, so I'm glad to hear you haven't seen it again.
And thanks so much for sharing your modifications! It all seems to be very clever. I'm going to read through and see what I can implement.
Referencing the comment on the tweet-to-markdown repository: https://github.com/kbravh/tweet-to-markdown/issues/9#issuecomment-1213612159
I've updated both ttm and the Obsidian plugin. In Obsidian, the downloaded/saved profile image path is incorrect.
Here are the results. The username is prepending the image path (Twitter/media/).
Tweet URL
Here are the plugin settings: