'프로그램개발/python'에 해당되는 글 2건

  1. 2025.03.23 파이썬으로 youtube 다운받기
  2. 2025.02.26 텍스트파일 인코딩 utf8로 전환

import yt_dlp

def download_video(url, output_path="downloads/%(title)s.%(ext)s"):
    ydl_opts = {
        "outtmpl": output_path,  # 파일 저장 경로 및 이름 설정
        "format": "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]",  # 최고 화질 비디오+오디오 조합
        "noplaylist": True,  # 개별 비디오만 다운로드
        "merge_output_format": "mp4",  # 병합 시 MP4로 저장
    }

    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        ydl.download([url])

# 예제 실행
video_url = "https://www.youtube.com/watch?v="
download_video(video_url)

Posted by 아기곰푸우
,
import os  
import chardet  

def convert\_to\_utf8(folder\_path):  
    for root, \_, files in os.walk(folder\_path):  
        for file in files:  
            if file.endswith(".cs"):  # .cs 파일만 선택  
                file\_path = os.path.join(root, file)  
                with open(file\_path, 'rb') as f:  
                    raw\_data = f.read()  
                    detected = chardet.detect(raw\_data)  # 인코딩 감지  
                    encoding = detected\['encoding'\] if detected\['encoding'\] else 'utf-8'  

                if encoding.lower() != 'utf-8':  
                    try:  
                        text = raw\_data.decode(encoding)  
                        with open(file\_path, 'w', encoding='utf-8') as f:  
                            f.write(text)  
                        print(f"Converted: {file\_path} from {encoding} to UTF-8")  
                    except Exception as e:  
                        print(f"Failed to convert {file\_path}: {e}")  
                else:  
                    print(f"Skipped (already UTF-8): {file\_path}")  

# 사용 예시  
folder\_path = "C:/your/folder/path"  # 변경 필요  
convert\_to\_utf8(folder\_path)
Posted by 아기곰푸우
,