구글 제미니를 사용하여 유튜브 다운로드 프로그램을 5분만에 제작하기

in #kr-devlast month (edited)

최근에 AI를 활용하여 작은 프로그램을 개발해보는 실험을 하고 있습니다.
이번에는 유튜브 동영상을 다운로드할 수 있는 간단한 프로그램을 만들어보았습니다.

블로그 글: https://anpigon.tistory.com/464

아래는 구글 제미니가 작성한 프로그램 코드입니다.

import sys
from PyQt5.QtCore import Qt 
from PyQt5.QtWidgets import (
    QApplication,
    QWidget,
    QLabel,
    QLineEdit,
    QPushButton,
    QVBoxLayout,
    QProgressBar,
    QMessageBox,
    QGridLayout
)
from PyQt5.QtGui import QImage, QPixmap
from pytube import YouTube, StreamQuery
from io import BytesIO
import requests

class YouTubeDownloader(QWidget):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("YouTube Downloader")

        # 레이블, 입력 필드, 버튼, 진행률 표시줄, 다운로드 상태 레이블, 썸네일 레이블
        self.url_label = QLabel("YouTube URL 입력:")
        self.url_input = QLineEdit()
        self.download_button = QPushButton("다운로드")
        self.progress_bar = QProgressBar()
        self.status_label = QLabel("")
        self.thumbnail_label = QLabel()

        # 레이아웃 설정
        layout = QVBoxLayout()
        layout.addWidget(self.url_label)
        layout.addWidget(self.url_input)
        layout.addWidget(self.download_button)
        layout.addWidget(self.thumbnail_label)
        layout.addWidget(self.progress_bar)
        layout.addWidget(self.status_label)
        self.setLayout(layout)

        # 버튼 연결
        self.download_button.clicked.connect(self.download_video)
        self.url_input.textChanged.connect(self.update_thumbnail)

    def update_thumbnail(self):
        url = self.url_input.text()
        if url:
            try:
                yt = YouTube(url)
                response = requests.get(yt.thumbnail_url)
                image_data = response.content  # Get image data as bytes
                image = QImage.fromData(image_data)  # Create QImage from bytes

                # 썸네일 크기 조절
                scaled_image = image.scaled(200, 150, Qt.KeepAspectRatio)  # 예시 크기: 200x150
                pixmap = QPixmap.fromImage(scaled_image)  # Create QPixmap from QImage

                self.thumbnail_label.setPixmap(pixmap)
            except Exception as e:
                self.thumbnail_label.setText(f"썸네일 가져오기 오류: {e}")
        else:
            self.thumbnail_label.clear()

    def download_video(self):
        url = self.url_input.text()
        try:
            yt = YouTube(url)
            stream = yt.streams.filter(progressive=True, file_extension="mp4").order_by("resolution").desc().first()

            # 다운로드 진행률 표시 및 상태 업데이트
            total_size = stream.filesize
            bytes_downloaded = 0
            
            while bytes_downloaded < total_size:
                stream.download(filename="temp.mp4")  # Download in chunks
                bytes_downloaded = total_size - stream.bytes_remaining
                percentage = int((bytes_downloaded / total_size) * 100)
                self.progress_bar.setValue(percentage)
                self.status_label.setText(f"다운로드 중... ({percentage}%)")

            # 다운로드 완료 후 알림
            QMessageBox.information(self, "다운로드 완료", "다운로드가 완료되었습니다.")

            self.progress_bar.setValue(100)
            self.status_label.setText("다운로드 완료")

        except Exception as e:
            QMessageBox.warning(self, "오류 발생", f"다운로드 오류: {e}")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    downloader = YouTubeDownloader()
    downloader.show()
    sys.exit(app.exec_())



Posted through the ECblog app (https://blog.etain.club)

Sort:  

[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.

Congratulations, your post has been upvoted by @upex with a 0.21% upvote. We invite you to continue producing quality content and join our Discord community here. Keep up the good work! #upex

취미로 하시는건가요..유튜브 무료다운로드하는사이트들은 많은데.,,어쨌든 개발자들은 대단함요^

네 취미로 하고 있어요. 요즘 AI 개발 자동화 시스템을 구축해보고 있어요.

Coin Marketplace

STEEM 0.19
TRX 0.12
JST 0.027
BTC 64886.88
ETH 3516.64
USDT 1.00
SBD 2.37