# 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 ' ```