Skip to content

Commit

Permalink
- Use rookiepy for getting line cookies
Browse files Browse the repository at this point in the history
- Also support supplying json string as line cookie
- Add documentation for getting line cookies manually as json string
  • Loading branch information
laggykiller committed Oct 7, 2023
1 parent 02bbb1d commit 89a118a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
18 changes: 17 additions & 1 deletion docs/guide_line.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,28 @@
1. Input your Message stickers url, start conversion
2. A message will pop up when downloading stickers, edit line-sticker-text.txt, then continue

# Downloading "Custom stickers" with custom text (Requires Line cookies)
# Downloading "Custom stickers" with custom text
This requires Line cookies.

## Method 1: Automatic
1. Login to store.line.me
2. Press on `Generate` button in sticker-convert GUI
3. Press on `Get cookies` button in the window (Format: `key_1=value_1;key_2=value_2`)
4. Input your Custom stickers url, start conversion
5. A message will pop up when downloading stickers, edit line-sticker-text.txt, then continue

NOTICE:
- Due to [recent updates](https://github.com/borisbabic/browser_cookie3/issues/180) to chrome browser, this might not work! You will have to use manual method in such cases.
- For best chance of success, use firefox.

## Method 2: Manual
1. Install `Get cookies.txt LOCALLY` extension on your browser
- Chrome: https://chrome.google.com/webstore/detail/get-cookiestxt-locally/cclelndahbckbenkjhflpdbgdldlbecc
- Firefox: https://addons.mozilla.org/en-US/firefox/addon/get-cookies-txt-locally/
- Github page: https://github.com/kairi003/Get-cookies.txt-LOCALLY
2. Login to store.line.me
3. Open `Get cookies.txt LOCALLY` extension, select `Export Format` to `JSON` and press `Copy`
4. Paste to `Line cookies` field in sticker-convert

# Uploading Line stickers
You need to manually submit sticker pack for approval before you can use in app.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apngasm_python~=1.2.1
pyav~=11.0.1
beautifulsoup4~=4.12.2
browser-cookie3~=0.19.1
rookiepy~=0.2.7
imageio~=2.31.5
memory-tempfile~=2.2.3
mergedeep~=1.3.4
Expand Down
11 changes: 6 additions & 5 deletions src/sticker_convert/auth/get_line_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
import json
from typing import Optional

import browser_cookie3 # type: ignore
import rookiepy # type: ignore
import requests

class GetLineAuth:
def get_cred(self) -> Optional[str]:
cookies_jar = browser_cookie3.load(domain_name='store.line.me')
cookies = [c for c in rookiepy.load() if c.domain == 'store.line.me']
cookies_dict = rookiepy.to_dict(cookies)
cookies_jar = rookiepy.to_cookiejar(cookies)

if not GetLineAuth.validate_cookies(cookies_jar):
return None

cookies_dict = requests.utils.dict_from_cookiejar(cookies_jar)
cookies_list = ['%s=%s' % (name, value) for (name, value) in cookies_dict.items()]

cookies_list = ['%s=%s' % (i['name'], i['value']) for i in cookies_dict]
cookies = ';'.join(cookies_list)

return cookies
Expand Down
22 changes: 15 additions & 7 deletions src/sticker_convert/downloaders/download_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,24 @@ def __init__(self, *args, **kwargs):
def load_cookies(self) -> dict[str, str]:
cookies = {}
if self.opt_cred and self.opt_cred.get('line', {}).get('cookies'):
line_cookies = self.opt_cred['line']['cookies']

try:
for i in self.opt_cred['line']['cookies'].split(';'):
c_key, c_value = i.split('=')
cookies[c_key] = c_value
if not GetLineAuth.validate_cookies(cookies):
line_cookies_dict = json.loads(line_cookies)
for c in line_cookies_dict:
cookies[c['name']] = c['value']
except json.decoder.JSONDecodeError:
try:
for i in line_cookies.split(';'):
c_key, c_value = i.split('=')
cookies[c_key] = c_value
except ValueError:
self.cb_msg('Warning: Line cookies invalid, you will not be able to add text to "Custom stickers"')
cookies = {}
except ValueError:
self.cb_msg('Warning: Line cookies invalid, you will not be able to add text to "Custom stickers"')

if not GetLineAuth.validate_cookies(cookies):
self.cb_msg('Warning: Line cookies invalid, you will not be able to add text to "Custom stickers"')
cookies = {}

return cookies

def get_pack_url(self) -> str:
Expand Down

0 comments on commit 89a118a

Please sign in to comment.