summaryrefslogtreecommitdiff
path: root/export-firefox-cookies
blob: 98367f3678cfb0e0ae45db6354fdfece1a92aa10 (plain)
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
# Firefox のクッキーを cookies.txt (Netscape HTTP Cookie File) として出す方法

yt-dlp のためにクッキーをエクスポートしたかった。
なんか、アドオンとか入れるのはなんか嫌だ。と思ったので。

$FIREFOX_PROFILE/cookies.sqlite にかかれているみたいなので、
sqlite3 コマンドで引っ張り出して jq と sed で整形する。
正しさは知らないが、なんとなく動いた。

```
echo '# Netscape HTTP Cookie File'
echo
sqlite3 cookies.sqlite \
        '.mode json --limits 0,0,0' \
        'select * from moz_cookies' \
    | jq -r '.[]
        | if .isHttpOnly then "#HttpOnly_\n" else "" end
        + .host +"\t"
        + (if .host|test("^\\.") then "TRUE" else "FALSE" end) +"\t"
        + .path +"\t"
        + (if .isSecure then "TRUE" else "FALSE" end) +"\t"
        + (.expiry/1000|floor|tostring) +"\t"
        + .name +"\t"
        +.value
    '
```

select を使ってエクスポート対象を絞り込める
(もちろん、 jq でやったっていい)

```
echo '# Netscape HTTP Cookie File'
echo
sqlite3 cookies.sqlite \
        ".mode json --limits 0,0,0" \
        "select * from moz_cookies where
            host like '%.google.com'
            or host like '%.youtube.com'
        " \
    | jq -r '.[]
        | if .isHttpOnly then "#HttpOnly_\n" else "" end
        + .host +"\t"
        + (if .host|test("^\\.") then "TRUE" else "FALSE" end) +"\t"
        + .path +"\t"
        + (if .isSecure then "TRUE" else "FALSE" end) +"\t"
        + (.expiry/1000|floor|tostring) +"\t"
        + .name +"\t"
        +.value
    '
```