Skip to content

Commit

Permalink
Merge pull request #172 from estrohm/master
Browse files Browse the repository at this point in the history
Crosspost gallery support
  • Loading branch information
ubershmekel authored Jun 21, 2024
2 parents 5730099 + 6728b41 commit bb4c847
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions js/EmbedIt.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,17 +366,30 @@ embedit.transformRedditData = function (pic) {
pic.url = pic.url.replace(http_prefix, https_prefix);
} else if (pic.url.indexOf("reddit.com/gallery") >= 0) {
console.log("GOTCHA!");

var dataSource;
if (pic.data.gallery_data && pic.data.gallery_data.items) {
var firstItemId = pic.data.gallery_data.items[0].media_id;
var encodedUrl = pic.data.media_metadata[firstItemId]["s"]["u"];
pic.type = embedit.imageTypes.image;
if (encodedUrl === undefined) {
// some posts don't have the u key, but have gif and mp4 keys
encodedUrl = pic.data.media_metadata[firstItemId]["s"]["mp4"];
pic.type = embedit.imageTypes.gifv;
}
pic.url = decodeEntities(encodedUrl);
dataSource = pic.data;
} else if (
pic.data.crosspost_parent_list &&
pic.data.crosspost_parent_list[0] &&
pic.data.crosspost_parent_list[0].gallery_data &&
pic.data.crosspost_parent_list[0].gallery_data.items
) {
// Grab the first image from the crosspost parent
dataSource = pic.data.crosspost_parent_list[0];
}

var firstItemId = dataSource.gallery_data.items[0].media_id;
var encodedUrl = dataSource.media_metadata[firstItemId]["s"]["u"];

pic.type = embedit.imageTypes.image;
if (encodedUrl === undefined) {
// some posts don't have the u key, but have gif and mp4 keys
encodedUrl = dataSource.media_metadata[firstItemId]["s"]["mp4"];
pic.type = embedit.imageTypes.gifv;
}
pic.url = decodeEntities(encodedUrl);
console.log(pic.url);
} else if (isImageExtension(pic.url)) {
// simple image
Expand Down

0 comments on commit bb4c847

Please sign in to comment.