~sircmpwn/pass-rotate

ref: 837d726c037a6d52bd5cbf159a75386a39e4dea0 pass-rotate/passrotate/providers/pixiv.py -rw-r--r-- 2.0 KiB
837d726cDrew DeVault Merge pull request #29 from gabm/AddPassName 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from passrotate.provider import Provider, ProviderOption, register_provider
from passrotate.forms import get_form
import requests
from urllib.parse import urlparse

class Pixiv(Provider):
    """
    [pixiv.net]
    username=Your pixiv username
    """
    name = "pixiv"
    domains = [
        "pixiv.net",
        "www.pixiv.net",
        "touch.pixiv.net"
    ]
    options = {
        "username": ProviderOption(str, "Your pixiv username")
    }

    def __init__(self, options):
        self.username = options["username"]

    def prepare(self, old_password):
        self._session = requests.Session()
        r = self._session.get("https://accounts.pixiv.net/login")
        self._form = get_form(r.text, action="/login")
        self._form.update({
            "pixiv_id": self.username,
            "password": old_password
        })
        r = self._session.post("https://accounts.pixiv.net/api/login",
                data=self._form)
        r = self._session.get("https://www.pixiv.net/setting_userdata.php",
                params={"type": "password"})
        url = urlparse(r.url)
        if url.path != "/setting_userdata.php":
            raise Exception("Current password for pixiv is incorrect")
        self._form = get_form(r.text, action="setting_userdata.php")
        self._form.update({
            "check_pass": old_password
        })
        r = self._session.post("https://www.pixiv.net/setting_userdata.php",
                data=self._form)

        self._form = get_form(r.text, action="setting_userdata.php")

    def execute(self, old_password, new_password):
        self._form.update({
            "new_password_1": new_password,
            "new_password_2": new_password
        })
        r = self._session.post("https://www.pixiv.net/setting_userdata.php",
                data=self._form)
        url = urlparse(r.url)
        if url.path == "/setting_userdata.php":
            raise Exception("Failed to update pixiv password")

register_provider(Pixiv)