Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sharedfiles scraping error when Steam returns non-English page, fix rejected request detection and improve type detection #316

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions classes/CSteamSharedFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SteamCommunity.prototype.getSteamSharedFile = function(sharedFileId, callback) {
};

// Get DOM of sharedfile
this.httpRequestGet(`https://steamcommunity.com/sharedfiles/filedetails/?id=${sharedFileId}`, (err, res, body) => {
this.httpRequestGet(`https://steamcommunity.com/sharedfiles/filedetails/?id=${sharedFileId}&l=english`, (err, res, body) => { // Request page in english so that the Posted scraping below works
try {

/* --------------------- Preprocess output --------------------- */
Expand Down Expand Up @@ -77,9 +77,11 @@ SteamCommunity.prototype.getSteamSharedFile = function(sharedFileId, callback) {


// Find postDate and convert to timestamp
let posted = detailsStatsObj["Posted"].trim();
let posted = detailsStatsObj["Posted"] || null; // Set to null if "posted" could not be found as Steam translates dates and parsing it below will return a wrong result

sharedfile.postDate = Helpers.decodeSteamTime(posted);
if (posted) {
sharedfile.postDate = Helpers.decodeSteamTime(posted.trim()); // Only parse if posted is defined to avoid errors
}


// Find resolution if artwork or screenshot
Expand Down Expand Up @@ -118,18 +120,20 @@ SteamCommunity.prototype.getSteamSharedFile = function(sharedFileId, callback) {


// Determine type by looking at the second breadcrumb. Find the first separator as it has a unique name and go to the next element which holds our value of interest
let breadcrumb = $(".breadcrumbs > .breadcrumb_separator").next().get(0).children[0].data || "";
let breadcrumb = $(".breadcrumbs > .breadcrumb_separator").next().get(0) || $(".breadcrumbs").get(0).children[1]; // Some artworks only have one breadcrumb like "username's Artwork" so let's check that as a backup

if (breadcrumb.includes("Screenshot")) {
sharedfile.type = ESharedFileType.Screenshot;
}
if (breadcrumb) { // If neither could be found then leave type at null
if (breadcrumb.children[0].data.includes("Screenshot")) {
sharedfile.type = ESharedFileType.Screenshot;
}

if (breadcrumb.includes("Artwork")) {
sharedfile.type = ESharedFileType.Artwork;
}
if (breadcrumb.children[0].data.includes("Artwork")) {
sharedfile.type = ESharedFileType.Artwork;
}

if (breadcrumb.includes("Guide")) {
sharedfile.type = ESharedFileType.Guide;
if (breadcrumb.children[0].data.includes("Guide")) {
sharedfile.type = ESharedFileType.Guide;
}
}


Expand Down
70 changes: 59 additions & 11 deletions components/sharedfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var SteamID = require('steamid');

var SteamCommunity = require('../index.js');

const Helpers = require('./helpers.js');


/**
* Deletes a comment from a sharedfile's comment section
Expand All @@ -20,14 +22,25 @@ SteamCommunity.prototype.deleteSharedFileComment = function(userID, sharedFileId
"form": {
"gidcomment": cid,
"count": 10,
"json": 1,
"sessionid": this.getSessionID()
}
},
"json": true
}, function(err, response, body) {
if (!callback) {
return;
}

callback(err);
if (err) {
callback(err);
return;
}

if (body.success) {
callback(null);
} else {
callback(new Error(body.error));
}
Comment on lines +39 to +43
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this tested and confirmed working? Typically, when Steam returns a success key, it's an eresult and not a bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, Steam returns the following here: { success: false, error: 'There was a problem deleting this comment. Please try again.' }

}, "steamcommunity");
};

Expand All @@ -45,7 +58,7 @@ SteamCommunity.prototype.favoriteSharedFile = function(sharedFileId, appid, call
"appid": appid,
"sessionid": this.getSessionID()
}
}, function(err, response, body) {
}, function(err, response, body) { // Steam does not seem to return any errors for this request
if (!callback) {
return;
}
Expand All @@ -71,14 +84,25 @@ SteamCommunity.prototype.postSharedFileComment = function(userID, sharedFileId,
"form": {
"comment": message,
"count": 10,
"json": 1,
"sessionid": this.getSessionID()
}
},
"json": true
}, function(err, response, body) {
if (!callback) {
return;
}

callback(err);
if (err) {
callback(err);
return;
}

if (body.success) {
callback(null);
} else {
callback(new Error(body.error));
}
Comment on lines +101 to +105
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also tested; Steam returns the following: { success: false, error: 'There was a problem posting your comment. Please try again.' }

}, "steamcommunity");
};

Expand All @@ -97,14 +121,26 @@ SteamCommunity.prototype.subscribeSharedFileComments = function(userID, sharedFi
"uri": `https://steamcommunity.com/comment/PublishedFile_Public/subscribe/${userID.toString()}/${sharedFileId}/`,
"form": {
"count": 10,
"json": 1,
"sessionid": this.getSessionID()
}
},
"json": true
}, function(err, response, body) { // eslint-disable-line
if (!callback) {
return;
}

callback(err);
if (err) {
callback(err);
return;
}

if (body.success && body.success != SteamCommunity.EResult.OK) {
callback(Helpers.eresultError(body.success));
return;
}

callback(null);
}, "steamcommunity");
};

Expand All @@ -122,7 +158,7 @@ SteamCommunity.prototype.unfavoriteSharedFile = function(sharedFileId, appid, ca
"appid": appid,
"sessionid": this.getSessionID()
}
}, function(err, response, body) {
}, function(err, response, body) { // Steam does not seem to return any errors for this request
if (!callback) {
return;
}
Expand All @@ -146,13 +182,25 @@ SteamCommunity.prototype.unsubscribeSharedFileComments = function(userID, shared
"uri": `https://steamcommunity.com/comment/PublishedFile_Public/unsubscribe/${userID.toString()}/${sharedFileId}/`,
"form": {
"count": 10,
"json": 1,
"sessionid": this.getSessionID()
}
},
"json": true
}, function(err, response, body) { // eslint-disable-line
if (!callback) {
return;
}

callback(err);
if (err) {
callback(err);
return;
}

if (body.success && body.success != SteamCommunity.EResult.OK) {
callback(Helpers.eresultError(body.success));
return;
}

callback(null);
}, "steamcommunity");
};
};