diff options
| -rw-r--r-- | export-firefox-cookies | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/export-firefox-cookies b/export-firefox-cookies new file mode 100644 index 0000000..98367f3 --- /dev/null +++ b/export-firefox-cookies @@ -0,0 +1,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 + ' +``` |
