Topic: Logging in so that blacklist is used in API calls

Posted under e621 Tools and Applications

Hello,

Could someone explain the general flow I should be using to login and make use of my blacklist when using the e621 API?

What I have tried:
1. get password_hash via e621.net/user/login.xml?name=myname&password=mypass
2. perform search via e621.net/post/index.json?tags=a_tag&name=myname&password_hash=my_hash

However I see results with blacklisted tags in the results. What am I doing wrong?

Thank you!

Updated

wwyaiykycnf1 said:
However I see results with blacklisted tags in the results. What am I doing wrong?

Expecting the server to do blacklisting. All blacklisting is done client-side via a bit of javascript that looks at your blacklist cookie and hides images accordingly.

This means that if you want blacklisting, you will have to implement it yourself (ie. make your program remove posts from the results after downloading them, just like the Javascript does.)

Updated by anonymous

What savageorange said is correct.

Depending on how you are doing all this, you could just adapt the site's JS in your project (if only to help figure out what it's doing).

Since the script is minimized (and kind of a pain to read like that), here's a snippet with just the blacklist bits. http://pastebin.com/YMgUrTNu (just note that you probably need jquery)

(I apologize if the syntax broke while I was trimming it, JS isn't my strong suit. Just let me know if it doesn't validate and I can double check it.)

Updated by anonymous

savageorange said:
Expecting the server to do blacklisting. All blacklisting is done client-side via a bit of javascript that looks at your blacklist cookie and hides images accordingly.

This means that if you want blacklisting, you will have to implement it yourself (ie. make your program remove posts from the results after downloading them, just like the Javascript does.)

Didn't know that but makes perfect sense, thanks. I see I need to parse the cookie to retrieve the blacklist. If anyone has other examples, especially in python, please share. It's always very illuminating to see a few ways to solve a problem.

Thanks again!

Updated by anonymous

Actually I've written some E6 related stuff in Python.

Offhand, I would convert the 'tags' field into a set -- tags = set(tags.split(' ')). I would also convert each blacklist line into a few sets: one of tags that must -not- be used for the item to be blacklisted (as in '-foo bar'), and one of tags that must be used for the item to be blacklisted (as in '-foo bar' or 'bar'). Then, if tags.intersection(thisline_blacklisted) and (not tags.intersection(thisline_antiblacklisted)) and ([any other more complicated conditions like metatags are satisfied]), then the post should be removed.

This covers basic blacklist usage, metatags like 'user:' obviously need more sophisticated parsing/checking.

Updated by anonymous

wwyaiykycnf1 said:
Hello,

Could someone explain the general flow I should be using to login and make use of my blacklist when using the e621 API?

What I have tried:
1. get password_hash via e621.net/user/login.xml?name=myname&password=mypass
2. perform search via e621.net/post/index.json?tags=a_tag&name=myname&password_hash=my_hash

However I see results with blacklisted tags in the results. What am I doing wrong?

Thank you!

I was able to solve this with some help from parasprite and savageorange and I just wanted to post the solution in case anyone finds it useful later.

It was news to me that blacklisting was done client side, so I realized I needed to log in and get my blacklist by way of the blacklisted_tags cookie. Using the requests python module and performing a POST to:

user/login.xml?login=USERNAME&password_hash=SHA1

did the trick perfectly:

#!/usr/bin/env python3
 
from requests import session
 
# note: obtain SHA1PASSWORDHASH @ https://e621.net/user/login.xml?name=USERNAME&password=MYPASSWORD
 
with session() as c:
    response = c.post('https://www.e621.net/user/login.xml?login=USERNAME&password_hash=SHA1PASSWORDHASH')
    blacklist = c.cookies['blacklisted_tags']
    print(blacklist)
 

Thanks again to parasprite and savageorange for the quick and helpful advice.

Updated by anonymous

  • 1