Selenium デフォルトダウンロードディレクトリを変更する(Chrome, Python)

Selenium 4.9.0 Chrome 112 ChromeDriver 112.0.5615.49 Python 3.11 from selenium.webdriver import ( Chrome, ChromeOptions, ) download_dir = "./downloads" os.makedirs(download_dir, exist_ok=True) options = ChromeOptions() options.add_experimental_option("prefs", { "profile.default_content_settings.popups": 0, "download.default_directory": os.path.realpath(download_dir), "download.prompt_for_download": False, "download.directory_upgrade": True, }) driver = Chrome( options=options, ) python - How to change download directory location path in Selenium using Chrome? - Stack Overflow

2023年4月24日 · aoirint

動画を繋げる(FFmpeg)

Git Bash (Git for Windows) 2.32.0 ffmpeg version N-109977-gaca7ef78cc-20230309 連番の動画ファイルを順番通りに繋げて、1つの動画ファイルにします。 lsコマンドの-vオプションは、自然な数字順にソートします。 ls -v *.ts | sed "s/.*/file '&'/" > list.txt ffmpeg -f concat -safe 0 -i list.txt -c copy -map 0 -map_metadata 0 output.mp4 Concatenate – FFmpeg 【 ls 】コマンド(並べ替え編)――表示結果を並べ替える:Linux基本コマンドTips(29) - @IT Add prefix to line that is the pattern of text after dot using sed or other command - Unix & Linux Stack Exchange

2023年4月24日 · aoirint

FFmpegで動画を逆再生化するPythonスクリプト

MATVToolに組み込むかもしれませんが、いまのところ詳細な動作検証をするほど需要がないので、簡易的にここに置いておきます。 動画ファイルによっては、フレームの欠け、重複が発生したり、変換に失敗するかもしれません。 Python 3.11.3 FFmpeg 4.2.7-0ubuntu0.1 Ubuntu 20.04 (WSL2) python3 main.py input.mp4 output.mp4 # License: CC0-1.0 import os import subprocess import tempfile import re import math def get_duration_seconds(input_file: str) -> float: proc = subprocess.run( [ 'ffmpeg', '-hide_banner', '-i', input_file, ], stderr=subprocess.PIPE, ) lines = proc.stderr.decode(encoding='utf-8').splitlines() # hh:mm:ss.ff duration_string = None for line in lines: m = re.match(r'^\s*Duration:\s(.+?),.*$', line) if m: duration_string = m.group(1) break assert duration_string is not None hours = int(duration_string[0:2]) minutes = int(duration_string[3:5]) seconds = int(duration_string[6:8]) milliseconds = float('0.' + duration_string[9:11]) return hours * 3600 + minutes * 60 + seconds + milliseconds def parse_time(string: str) -> float: """ string: HH:MM:SS.FF """ hours = int(string[0:2]) minutes = int(string[3:5]) seconds = int(string[6:8]) milliseconds = float('0.' + string[9:11]) return hours * 3600 + minutes * 60 + seconds + milliseconds def format_time(seconds: int) -> str: hours_minutes = seconds // 60 hours = hours_minutes // 60 minutes = hours_minutes - hours * 60 local_seconds = seconds - hours_minutes * 60 return f'{hours:02d}:{minutes:02d}:{local_seconds:02d}' def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument('input_file', type=str) parser.add_argument('output_file', type=str) parser.add_argument('--split_duration', type=int, default=10) args = parser.parse_args() input_file = args.input_file output_file = args.output_file split_duration = args.split_duration duration_seconds = math.ceil(get_duration_seconds(input_file=input_file)) count = math.ceil(duration_seconds / split_duration) work_dir_obj = tempfile.TemporaryDirectory() work_dir = work_dir_obj.name part_output_file_list = [] for index in range(count): start = index * split_duration end = start + split_duration start_string = format_time(start) end_string = format_time(end) print(index, start_string, end_string) part_output_file = os.path.join(work_dir, f'output{count-index}.mp4') subprocess.run([ 'ffmpeg', '-hide_banner', '-ss', start_string, '-to', end_string, '-i', 'input.mp4', '-vf', 'reverse', '-af', 'areverse', part_output_file, ]) part_output_file_list.append(part_output_file) list_file = os.path.join(work_dir, 'list.txt') with open(list_file, 'w', encoding='utf-8') as fp: for part_output_file in part_output_file_list: fp.write(f"file '{part_output_file}'\n") subprocess.run([ 'ffmpeg', '-hide_banner', '-f', 'concat', '-safe', '0', '-i', list_file, '-c', 'copy', output_file, ]) if __name__ == '__main__': main() 参考 How to Reverse a Video using FFmpeg - OTTVerse 映像と音声を逆再生にエンコードする | ニコラボ FFMPEGで動画を逆再生して保存する方法 | 技術的特異点 Concatenate – FFmpeg

2023年4月18日 · aoirint

markdownlint-cli2

Node.js 18.16.0 markdownlint-cli2 0.6.0 https://www.npmjs.com/package/markdownlint-cli2 npm install -g markdownlint-cli2 # lint markdownlint-cli2 # format markdownlint-cli2-fix Config .markdownlint-cli2.yaml Example: https://github.com/DavidAnson/markdownlint/blob/fcb8190781c80b292ac44f6df984326e0e6c69cd/schema/.markdownlint.yaml # https://github.com/DavidAnson/markdownlint # https://github.com/DavidAnson/markdownlint-cli2 globs: - "**/*.md" ignores: - ".git/**" - ".github/**" config: # h1 MD025: false # inline HTML MD033: false

2023年4月17日 · aoirint

GatsbyのsiteMetadataにカスタムデータを追加する

Node.js 18.16.0 Gatsby 5.8.1 gatsby-config.ts const config: GatsbyConfig = { siteMetadata: { siteUrl: "https://example.com", title: "Example Blog", myCustomData: myCustomData, }, graphqlTypegen: true, // ... } gatsby-node.ts export const createSchemaCustomization: GatsbyNode['createSchemaCustomization'] = ({ actions }) => { const { createTypes } = actions createTypes(` type MyCustomData { text: String flag: Boolean } type SiteSiteMetadata { myCustomData: MyCustomData } `) } mypage.tsx import * as React from "react" import { graphql, PageProps, } from 'gatsby' import { GetMyPageQuery } from '../gatsby-types' const MyPage: React.FC<PageProps<GetMyPageQuery>> = (props) => { const data = props.data const site = data?.site const myCustomData = site?.siteMetadata?.myCustomData // ... } export const pageQuery = graphql` query GetMyPage { site { siteMetadata { myCustomData { text flag } } } } ` export default MyPage 参考 https://github.com/gatsbyjs/gatsby/issues/1781 https://stackoverflow.com/questions/61530280/unable-to-filter-custom-data-in-sitemetadata-in-gatsby-using-graphql-in-graphiql https://tomiko0404.hatenablog.com/entry/2022/02/20/gatasby-graphql-datalayer https://stackoverflow.com/questions/62984585/gatsby-how-to-handle-undefined-fields-in-sitemetadata

2023年4月17日 · aoirint

Jenkinsのapt GPGキーを更新する

$ sudo apt update Err:9 https://pkg.jenkins.io/debian-stable binary/ Release.gpg The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 5BA31D57EF5975CA W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://pkg.jenkins.io/debian-stable binary/ Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 5BA31D57EF5975CA W: Failed to fetch https://pkg.jenkins.io/debian-stable/binary/Release.gpg The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 5BA31D57EF5975CA W: Some index files failed to download. They have been ignored, or old ones used instead. ...

2023年4月17日 · aoirint

Gitの改行コード自動置換機能(autocrlf)を無効化する

https://stackoverflow.com/questions/21822650/disable-git-eol-conversions git config --global core.autocrlf false git add --renormalize . すでにautocrlfが適用されたファイルを元に戻すために、既存のローカルリポジトリではadd --renormalizeが必要です。 GitのCRLF自動置換機能のためにDocker Buildに失敗する例 改行コードCRLFで以下のようなDockerfileを作成すると、 # syntax=docker/dockerfile:1.4 FROM ubuntu:22.04 RUN <<EOF set -eux echo "OK" EOF 以下のようなエラーとなり、ビルドに失敗します。 ------ > [2/2] RUN <<EOF (set -eux...): #8 0.294 /bin/sh: 1: set: Illegal option - ------ executor failed running [/bin/sh -c set -eux echo "OK" ]: exit code: 2 GitのCRLF自動置換機能によって、Dockerfileの改行コードがCRLFに書き換えられることでも同じことが起きます。 Linuxの仮想化ソフトウェアであるDockerの構成ファイルにCRLFが使われることが想定されないのは理解できます。 WindowsでDockerを扱っていることは理解してください。 .gitattributesでリポジトリごとに改行コードのポリシーを変更することができますが、令和の時代に改行コードの切り替えができないテキストエディタを使うこともないと思われるので、 不要なCRLF自動置換機能を無効化する方が、たくさんのリポジトリを扱う人には向いているでしょう。

2023年4月16日 · aoirint

pyenvでPyInstallerを使えるようにする

env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.11.3 https://pyinstaller.org/en/stable/development/venv.html

2023年4月16日 · aoirint

Waifu Diffusion 1.4 Epoch 2 + 東北ずん子PJ公式イラスト LoRA作成テスト

種類 LoRA ベースモデル Waifu Diffusion 1.4 Epoch 2 生成例 生成例1 <lora:tohoku_zunko-20230404.1-epoch-000010:1:OUTD>, (tohoku zunko girl:1), 1girl, solo, hairband, long hair, green hairband, japanese clothes, yellow eyes, smile, green hair, open mouth, upper body, white background, kimono, simple background, ahoge, very long hair, short kimono, looking at viewer, masterpiece, best quality, ultra-detailed Negative prompt: lowres, ((bad anatomy)), ((bad hands)), text, missing finger, extra digits, fewer digits, blurry, ((mutated hands and fingers)), (poorly drawn face), ((mutation)), ((deformed face)), (ugly), ((bad proportions)), ((extra limbs)), extra face, (double head), (extra head), ((extra feet)), monster, logo, cropped, worst quality, jpeg, humpbacked, long body, long neck, ((jpeg artifacts)), deleted, old, oldest, ((censored)), ((bad aesthetic)), (mosaic censoring, bar censor, blur censor) Steps: 20, Sampler: DPM++ 2M Karras, CFG scale: 7, Seed: 4052543271, Size: 512x512, Model hash: 1f108d4ceb, Model: wd-1-4-anime_e2 生成例2 ...

2023年4月15日 · aoirint

Stable Diffusion に関するメモ

Stable Diffusionは、ミュンヘン大学のCompVis研究グループ、スタートアップ企業のStability AI、Runwayの三者が共同で2022年8月にリリースした、オープンソースの画像生成AIモデル。 「プロンプト」という単語列に従って画像を生成する、Text to Imageモデルの一種。 CompVis/stable-diffusion: A latent text-to-image diffusion model Creative ML OpenRAIL-Mという独自のオープンソースライセンスのもと配布され、 望ましくない使い方を禁止するいくつかの制限のもと、再利用が認められている。 CreativeML OpenRAIL-Mライセンス原文 - CompVis/stable-diffusion - GitHub 同時期に公開された類似の画像生成AIには、DALL·E2やMidjourneyがある。 公式の有償サービスとして、DreamStudioが提供されている。 Stable Diffusionは、学習済みモデルを含めてオープンソースであるため、ユーザのローカル環境や、Googleが提供するGPU環境であるColaboratory上、オープンソースコミュニティHugging Face上での推論実行が可能なほか、Fine tuningなどにより変更を加えたモデルを公開することができる。 Stable Diffusion派生モデルには、アニメ風の絵・萌え絵に特化したWaifu Diffusionや、NovelAIの画像生成サービスなどがある。

2023年4月15日 · aoirint