İyi günler. Ben PyQt5 ile kendime bir Youtube Dönüştürücü yaptım. Her şey tamamdı. İndirme aşamasında ekran donuyor. Sebebi ise pytube kütüphanesine ait download() fonksiyonunu kullanmam. Tam olarak sorun yükleme aşamasında program yanıt vermiyor aşamasına geçiyor fakat o ara yaptığım progress bar yinede değeri göstermeye devam ediyor. Thread kullanmıyorum. Stack owerflow sitesinde Thread kullanılması istenmiş. Bir çok kaynağa bakmama rağmen anlayamadım. İyi akşamlar. Eğer ister iseniz ui ve tam kodu atabilirim.
Kodunu gönderebilirsen deneme imkanı bulmuş oluruz. Bu sayede daha iyi yardımcı olabiliriz.
Merhaba. Öncelikle şehir dışında olduğum için yazamadım. Kodu atıyorum fakat çok karışık çünkü içinde bir çok dosta bağlanıyor.
import os
import random
import shutil
import sys
import time
import urllib.request
from tkinter import *
from tkinter import filedialog
import PySide2
import pyautogui
from PyQt5.QtCore import QPoint, QThread, pyqtSignal
from PyQt5.QtGui import QColor, QFont, QMovie
from PyQt5.QtWidgets import *
from PySide2.QtCore import Qt
from pytube import YouTube
from caynak import *
from caynakerror import *
print("Program loading...")
print("Developer Mode On")
TIME_LIMIT = 100
class MainWindow(QMainWindow):
def __init__(self):
super (MainWindow, self).__init__ ( )
self.ui = Ui_SplashScreen()
self.ui.setupUi (self)
fihrist = open (os.getcwd() + r"\titleset.txt", "r")
rl = fihrist.readline ( )
_translate = QtCore.QCoreApplication.translate
name, version = rl.split ("|")
self.setWindowTitle(_translate("SplashScreen", f"{name} {version}"))
self.ui.label_2.setText(self.windowTitle())
self.ui.searchbar.setText ("https://www.youtube.com/watch?v=04ThD3KOPxw")
self.ui.stackedWidget.setCurrentIndex (0)
self.ui.ScanQ.hide ( )
self.ui.label_3.hide()
movie = QMovie ("load.gif")
self.ui.Loading.setMovie (movie)
movie.start ( )
self.ui.thumbnail.hide ( )
self.ui.ytime.hide ( )
self.ui.ytitle.hide ( )
self.ui.ytauthor.hide ( )
self.ui.clear.hide ( )
self.ui.cnti.hide ( )
self.ui.label_3.hide ( )
self.ui.Custom.hide ( )
self.ui.Loading.hide ( )
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
self.shadow = QGraphicsDropShadowEffect (self)
self.shadow.setBlurRadius (20)
self.shadow.setXOffset (0)
self.shadow.setYOffset (0)
self.shadow.setColor (QColor (0, 0, 0, 60))
self.ui.frame.setGraphicsEffect (self.shadow)
self.ui.close.clicked.connect(lambda: self.close())
self.ui.icona.clicked.connect(lambda: self.showMinimized())
self.dragPos = self.pos()
def mouseMoveEvent(event):
delta = QPoint (self.pos ( ) + event.globalPos ( ) - self.dragPos)
#print (self.pos ( ) + event.globalPos ( ) - self.dragPos)
self.move (self.pos ( ) + event.globalPos ( ) - self.dragPos)
self.dragPos = event.globalPos ( )
event.accept ( )
self.ui.titlebar.mouseMoveEvent = mouseMoveEvent
self.ui.navibar.mouseMoveEvent = mouseMoveEvent
self.timer = QtCore.QTimer (self)
self.timer.timeout.connect (self.showTime)
self.timer.start (1000)
#########
##########ALL DEF##########
#########
#PAGE1
def YtFinder():
# ----> MAIN FINDER
link = self.ui.searchbar.text ( )
yt = YouTube (link, on_progress_callback=progress)
fillse = yt.streams.get_highest_resolution ( )
try:
self.ui.Loading.hide ( )
self.ui.thumbnail.hide ( )
self.ui.ytime.hide ( )
self.ui.ytime.setText ("<Time>")
self.ui.ytitle.hide ( )
self.ui.ytitle.setText ("<Title>")
self.ui.ytauthor.hide ( )
self.ui.ytauthor.setText ("<Author>")
self.ui.clear.hide ( )
self.ui.cnti.hide ()
self.ui.label_3.hide ( )
global highsize
global lowsize
global highres
global lowres
highsize = yt.streams.get_highest_resolution().filesize
lowsize = yt.streams.get_lowest_resolution().filesize
highres = yt.streams.get_highest_resolution().resolution
lowres = yt.streams.get_lowest_resolution().resolution
print (r"\\\\\____Video algılandı____/////")
global findstatus
findstatus = "Yes"
print ("")
print (r"\\\\____Başlık____////")
print (yt.title)
print (r"\\\____Kanal____///")
print (yt.author)
print (r"\\____Süre____//")
print (round (yt.length / 60), ":", yt.length % 60) # Video Süresi Süre/60(Dakika) : Süre%60 (Saniye)
print (r"\____Kapak Fotoğrafı____/")
print (yt.thumbnail_url) # Kapak Fotoğrafının Verisini Çekip Site Aracılığına dönüştürüyor.
url = yt.thumbnail_url # Site URL
urllib.request.urlretrieve (url,
os.getcwd ( ) + r'\thunbail.jpg') # Kapak Fotoğrafını Belirtilen Yola kaydediyor. ( os.getcwd() projenin konumunu buluyor)
print (os.getcwd ( ) + r'\thunbail.jpg', 'konumuna', 'thubail.jpg olarak kaydedildi.')
self.ui.thumbnail.setPixmap (QtGui.QPixmap ("thunbail.jpg"))
self.ui.thumbnail.show ( )
d = yt.length / 60
s = yt.length % 60
self.ui.ytime.setText (str (round (d)) + " : " + str (round (s)))
self.ui.ytime.show ( )
self.ui.ytitle.setText (yt.title)
#self.ui.ytitle.setText("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
###########################TITLE####AUTO SCALE
fontsize = f"{len(self.ui.ytitle.text())}"
fontsize = fontsize[0]
fontsize2 = len(self.ui.ytitle.text())
bln = int (fontsize) - 1
bln2 = float (f"{bln}.5")
size = int(fontsize2 / bln2)
self.ui.ytitle.setFont(QFont("Arial", size))
#print(bln2)
###########################TITLE####AUTO SCALE
self.ui.ytitle.show ( )
self.ui.ytauthor.setText (yt.author)
###########################AUTHOR####AUTO SCALE
fontsize = f"{len(self.ui.ytauthor.text())}"
fontsize = fontsize[0]
fontsize2 = len(self.ui.ytauthor.text())
if fontsize2 < 10:
print("if worked")
bln = 0
bln2 = float (f"{bln}.3")
else:
bln = int (fontsize) - 1
bln2 = float (f"{bln}.5")
size = int(fontsize2 / bln2)
self.ui.ytauthor.setFont(QFont("Arial", size))
print(fontsize2)
print(bln2)
###########################AUTHOR####AUTO SCALE
self.ui.ytauthor.show ( )
self.ui.clear.show ( )
self.ui.cnti.show ( )
self.ui.label_3.show()
self.ui.finder.setText ("Find")
except:
print ("Geçersiz Link")
pyautogui.alert ('Error 404', "SynMax")
self.ui.finder.setText ("Find")
def FIND():
# ----> FINDER
movif = QMovie ("load.gif")
self.ui.Loading.setMovie (movif)
movif.start ( )
print("Clicked: Find Button")
self.ui.finder.setEnabled (False)
self.ui.searchbar.setEnabled (False)
self.ui.finder.setText ("...")
try:
YtFinder()
except:
print ("Geçersiz Link")
rl = open("error.txt", "w")
rl.truncate(0)
rl.write("Invaild Link!|14", )
rl.close()
rl = open ("error.txt", "r")
rlrd = rl.readline()
print(len(rlrd))
if len(rlrd) > 1:
MainError ( ).show ( )
self.ui.Loading.hide()
self.ui.finder.setText ("Find")
#YtFinder()
def CLEAR():
# ----> CLEAR FIND
print("Clicked: Clear Button")
self.ui.thumbnail.hide ( )
self.ui.ytime.hide ( )
self.ui.ytime.setText ("<Time>")
self.ui.ytitle.hide ( )
self.ui.ytitle.setText ("<Title>")
self.ui.ytauthor.hide ( )
self.ui.ytauthor.setText ("<Author>")
self.ui.clear.hide ( )
self.ui.cnti.hide ( )
self.ui.label_3.hide()
self.ui.searchbar.setText ("")
def CONITE():
print("Clicked: Continue Button(1)")
self.ui.thumbnail.hide ( )
self.ui.ytitle.hide ( )
self.ui.ytauthor.hide ( )
self.ui.ytime.hide ( )
self.ui.clear.hide ( )
self.ui.cnti.hide ( )
self.ui.label_3.hide ( )
self.ui.Loading.show ( )
self.ui.stackedWidget.setCurrentWidget (self.ui.page_3)
self.ui.vidname_2.setText (self.ui.ytitle.text ( ))
SCAN ( )
if self.ui.ytitle.text ( ) > r'64':
self.ui.vidname_2.setFont (QFont ('MS UI Gothic', 13))
self.ui.channel_2.setText (self.ui.ytauthor.text ( ))
self.ui.channel_2.setFont (QFont ('MS UI Gothic', 14))
self.ui.thumbnail_2.setPixmap (QtGui.QPixmap ('thunbail.jpg'))
self.ui.YTime.setText (self.ui.ytime.text ( ))
self.ui.CustomQ.hide ( )
self.ui.Custom.hide ( )
self.ui.LabelQ.hide ( )
self.ui.Low.hide ( )
self.ui.High.hide ( )
#PAGE3(2)
def RANDOMS():
# ----> RANDOM FILE NAME GENERATOR
print("Clicked: Random Button")
sayi1 = random.randint (1000000000, 9999999999)
sayi2 = random.randint (1000000000, 9999999999)
self.ui.Filebar.setText (str (sayi1) + "_" + str (sayi2))
def DEFLT():
# ----> Default File Name Setter
print("Clicked: Defeult Name Button")
self.ui.Filebar.setText (self.ui.ytitle.text ( ))
def openFile():
# ----> Folder dialog
print("Clicked: Folder Button")
root = Tk ( )
root.withdraw ( )
filepath = filedialog.askdirectory ( )
print (filepath)
root.destroy ( )
self.ui.FileLocName.setText (filepath)
def DEFAULT():
# ----> Default Folder Path
print("Clicked: Default Path Button")
from pathlib import Path
home = str (Path.home ( ))
self.ui.FileLocName.setText (home + "\Downloads")
def check():
# ----> Format Checker
print("Clicked: Any Format Button")
if self.ui.MP4.isChecked ( ):
# ui.Custom.show()
self.ui.LabelQ.show ( )
self.ui.Low.show ( )
self.ui.High.show ( )
self.ui.qts.setText (".mp4")
if self.ui.Custom.isChecked ( ):
self.ui.CustomQ.show ( )
if self.ui.Low.text ( ) == "<Low>":
self.ui.ScanQ.show ( )
elif self.ui.High.text ( ) == "<High>":
self.ui.ScanQ.show ( )
elif self.ui.AVI.isChecked ( ):
# ui.Custom.show()
self.ui.LabelQ.show ( )
self.ui.Low.show ( )
self.ui.High.show ( )
self.ui.qts.setText (".avi")
if self.ui.Custom.isChecked ( ):
self.ui.CustomQ.show ( )
if self.ui.Low.text ( ) == "<Low>":
self.ui.ScanQ.show ( )
elif self.ui.High.text ( ) == "<High>":
self.ui.ScanQ.show ( )
elif self.ui.MP3.isChecked ( ):
self.ui.CustomQ.hide ( )
self.ui.Custom.hide ( )
self.ui.LabelQ.hide ( )
self.ui.Low.hide ( )
self.ui.ScanQ.hide ( )
self.ui.High.hide ( )
self.ui.qts.setText (".mp3")
else:
self.ui.CustomQ.hide ( )
self.ui.Custom.hide ( )
self.ui.LabelQ.hide ( )
self.ui.Low.hide ( )
self.ui.High.hide ( )
def chenck():
#link = self.ui.searchbar.text ( )
#yt = YouTube (link, on_progress_callback=progress)
# ----> Quality Checker
print("Clicked: Any Quality Button")
if self.ui.Custom.isChecked ( ):
self.ui.CustomQ.show ( )
elif self.ui.High.isChecked ( ):
self.ui.CustomQ.hide ( )
self.ui.qts_2.setText (highres)
self.ui.VideoSize.setText ( str (round (highsize / (1024 * 1024))) + 'MB')
elif self.ui.Low.isChecked ( ):
self.ui.CustomQ.hide ( )
self.ui.qts_2.setText (lowres)
self.ui.VideoSize.setText (str (round (lowsize / (1024 * 1024))) + 'MB')
else:
self.ui.CustomQ.hide ( )
def SCAN():
# ----> Quality Scanner
link = self.ui.searchbar.text ( )
yt = YouTube (link, on_progress_callback=progress)
fillse = yt.streams.get_highest_resolution ( )
self.ui.High.setText (yt.streams.get_highest_resolution ( ).resolution)
self.ui.Low.setText (yt.streams.get_lowest_resolution ( ).resolution)
# ui.VideoSize.setText (str (round (yt.streams.get_highest_resolution ( ).filesize / (1024 * 1024))) + 'MB')
vs = yt.streams.get_highest_resolution ( ).filesize / (1024 * 1024)
def CANCEL():
# ----> CANCEL TO PAGE1
self.ui.stackedWidget.setCurrentWidget (self.ui.page)
def NEXTY():
link = self.ui.searchbar.text ( )
yt = YouTube (link, on_progress_callback=progress)
fillse = yt.streams.get_highest_resolution ( )
if self.ui.High.isChecked ( ):
self.ui.VideoSize.setText (
str (round (yt.streams.get_highest_resolution ( ).filesize / (1024 * 1024))) + 'MB')
global vs
vs = yt.streams.get_highest_resolution ( ).filesize / (1024 * 1024)
global vsd
vsd = yt.streams.get_highest_resolution ( ).filesize
elif self.ui.Low.isChecked ( ):
self.ui.VideoSize.setText (
str (round (yt.streams.get_lowest_resolution ( ).filesize / (1024 * 1024))) + 'MB')
vs = yt.streams.get_highest_resolution ( ).filesize / (1024 * 1024)
elif self.ui.Custom.isChecked ( ):
...
# \___________HATALAR___________/
total, used, free = shutil.disk_usage ("/")
nfree = free // (1024 * 1024)
if self.ui.qts.text ( ) == "Format":
rl = open("error.txt", "w")
rl.truncate(0)
rl.write("Select Format!|14", )
rl.close()
rl = open ("error.txt", "r")
rlrd = rl.readline()
print(len(rlrd))
if len(rlrd) > 1:
MainError ( ).show ( )
elif self.ui.qts_2.text ( ) == "Quality":
rl = open ("error.txt", "w")
rl.truncate (0)
rl.write ("Select Quality!|14", )
rl.close ( )
rl = open ("error.txt", "r")
rlrd = rl.readline ( )
print (len (rlrd))
if len (rlrd) > 1:
MainError ( ).show ( )
elif nfree < vs:
rl = open("error.txt", "w")
rl.truncate(0)
rl.write("Not Enough Space Available On The Disk|10", )
rl.close()
rl = open ("error.txt", "r")
rlrd = rl.readline()
print(len(rlrd))
if len(rlrd) > 1:
MainError ( ).show ( )
else:
DOWNLOAD()
self.ui.Location.setText ("File Location : " + self.ui.FileLocName.text ( ))
self.ui.Format.setText ("Format : " + self.ui.qts.text ( ))
def DOWNLOAD():
link = self.ui.searchbar.text ( )
self.ui.stackedWidget.setCurrentWidget (self.ui.page_5)
global yt
yt = YouTube (link, on_progress_callback=progress)
fillse = yt.streams.get_highest_resolution ( )
self.ui.progressBar.setValue (10)
fillse.download(self.ui.FileLocName.text())
# if ui.High.isChecked():
# fills = yt.streams.get_highest_resolution().filesize
# vs = fills / (1024 * 1024)
# yt.streams.get_highest_resolution().download()
# elif ui.Low.isChecked():
# fills = yt.streams.get_lowest_resolution().filesize
# vs = fills / (1024 * 1024)
# yt.streams.get_lowest_resolution().download()
def progress(streams, chunk: bytes, bytes_remaining: int): # Yükleme Barı
contentsize = vsd
size = contentsize - bytes_remaining
timer = 1
print (float (size / contentsize * 100))
global steer
steer = int(size / contentsize * 100)
print(int(size / contentsize * 100))
self.ui.progressBar.setValue(steer)
def progress_bar(self, chunk, file_handle, bytes_remaining,):
contentsize = MainWindow().ui.VideoSize.text() #yt.streams.get_highest_resolution().filesize
size = contentsize - bytes_remaining
timer = 1
print (float (size / contentsize * 100))
self.ui.progressBar.setValue(10)
# MainWindow().ui.progressBar.setValue(float (size / contentsize * 100))
#PAGE4
#########
##########ALL BUTTONS##########
#########
#PAGE1
self.ui.finder.clicked.connect(FIND)
self.ui.clear.clicked.connect (CLEAR)
self.ui.cnti.clicked.connect (CONITE)
# PAGE3(2)
self.ui.pushButton_7.clicked.connect (RANDOMS)
self.ui.defay.clicked.connect (DEFLT)
self.ui.findfoldr.clicked.connect (openFile)
self.ui.pushButton_8.clicked.connect (DEFAULT)
self.ui.MP4.clicked.connect (check)
self.ui.MP3.clicked.connect (check)
self.ui.AVI.clicked.connect (check)
self.ui.Low.clicked.connect (chenck)
self.ui.High.clicked.connect (chenck)
self.ui.Custom.clicked.connect (chenck)
self.ui.ScanQ.clicked.connect (SCAN)
self.ui.pushButton_5.clicked.connect (CANCEL)
self.ui.pushButton_6.clicked.connect (NEXTY)
self.ui.pushButton_9.clicked.connect (CANCEL)
def mousePressEvent(self, event):
self.dragPos = event.globalPos ( )
def showTime(self):
global link
global yt
link = self.ui.searchbar.text ( )
class MainError(QMainWindow):
def __init__(self):
super (MainError, self).__init__ ( )
self.ui = Ui_Dialog()
self.ui.setupUi (self)
rlf = open("error.txt", "r")
rl = rlf.readline()
name, fsize = rl.split ("|")
self.ui.error.setText(name)
self.ui.error.setFont(QFont("MS Shell Dlg 2", int(fsize)))
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
self.ui.close.clicked.connect(lambda: self.close())
self.ui.Ok.clicked.connect(lambda: self.close())
self.ui.icona.clicked.connect(lambda: self.showMinimized())
self.dragPos = self.pos()
def mouseMoveEvent(event):
delta = QPoint (self.pos ( ) + event.globalPos ( ) - self.dragPos)
#print (self.pos ( ) + event.globalPos ( ) - self.dragPos)
self.move (self.pos ( ) + event.globalPos ( ) - self.dragPos)
self.dragPos = event.globalPos ( )
event.accept ( )
# WIDGET HAREKETİ
self.ui.titlebar.mouseMoveEvent = mouseMoveEvent
################
def mousePressEvent(self, event):
self.dragPos = event.globalPos()
if __name__=='__main__':
app=QApplication(sys.argv)
ex=MainWindow()
ex.show()
app.setWindowIcon(QtGui.QIcon("icon.ico"))
ex.setWindowIcon(QtGui.QIcon("icon.ico"))
sys.exit(app.exec_())
download fonsiyonu uzun süre çalışıyor galiba, onu thread kullanarak çalıştırmanı tavsiye ederim.
düzenleme yaptım, ama tüm dosyalar bende olmadığından çalıştıramıyorum.kendin bu kodu test etmen lazım.
import os
import random
import shutil
import sys
import time
import urllib.request
from tkinter import *
from tkinter import filedialog
import PySide2
import pyautogui
from PyQt5.QtCore import QPoint, QThread, pyqtSignal
from PyQt5.QtGui import QColor, QFont, QMovie
from PyQt5.QtWidgets import *
from PySide2.QtCore import Qt
from pytube import YouTube
from threading import Thread
from caynak import *
from caynakerror import *
print("Program loading...")
print("Developer Mode On")
TIME_LIMIT = 100
class MainWindow(QMainWindow):
def __init__(self):
super (MainWindow, self).__init__ ( )
self.ui = Ui_SplashScreen()
self.ui.setupUi (self)
fihrist = open (os.getcwd() + r"\titleset.txt", "r")
rl = fihrist.readline ( )
_translate = QtCore.QCoreApplication.translate
name, version = rl.split ("|")
self.setWindowTitle(_translate("SplashScreen", f"{name} {version}"))
self.ui.label_2.setText(self.windowTitle())
self.ui.searchbar.setText ("https://www.youtube.com/watch?v=04ThD3KOPxw")
self.ui.stackedWidget.setCurrentIndex (0)
self.ui.ScanQ.hide ( )
self.ui.label_3.hide()
movie = QMovie ("load.gif")
self.ui.Loading.setMovie (movie)
movie.start ( )
self.ui.thumbnail.hide ( )
self.ui.ytime.hide ( )
self.ui.ytitle.hide ( )
self.ui.ytauthor.hide ( )
self.ui.clear.hide ( )
self.ui.cnti.hide ( )
self.ui.label_3.hide ( )
self.ui.Custom.hide ( )
self.ui.Loading.hide ( )
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
self.shadow = QGraphicsDropShadowEffect (self)
self.shadow.setBlurRadius (20)
self.shadow.setXOffset (0)
self.shadow.setYOffset (0)
self.shadow.setColor (QColor (0, 0, 0, 60))
self.ui.frame.setGraphicsEffect (self.shadow)
self.ui.close.clicked.connect(lambda: self.close())
self.ui.icona.clicked.connect(lambda: self.showMinimized())
self.dragPos = self.pos()
def mouseMoveEvent(event):
delta = QPoint (self.pos ( ) + event.globalPos ( ) - self.dragPos)
#print (self.pos ( ) + event.globalPos ( ) - self.dragPos)
self.move (self.pos ( ) + event.globalPos ( ) - self.dragPos)
self.dragPos = event.globalPos ( )
event.accept ( )
self.ui.titlebar.mouseMoveEvent = mouseMoveEvent
self.ui.navibar.mouseMoveEvent = mouseMoveEvent
self.timer = QtCore.QTimer (self)
self.timer.timeout.connect (self.showTime)
self.timer.start (1000)
#########
##########ALL DEF##########
#########
#PAGE1
def YtFinder():
# ----> MAIN FINDER
link = self.ui.searchbar.text ( )
yt = YouTube (link, on_progress_callback=progress)
fillse = yt.streams.get_highest_resolution ( )
try:
self.ui.Loading.hide ( )
self.ui.thumbnail.hide ( )
self.ui.ytime.hide ( )
self.ui.ytime.setText ("<Time>")
self.ui.ytitle.hide ( )
self.ui.ytitle.setText ("<Title>")
self.ui.ytauthor.hide ( )
self.ui.ytauthor.setText ("<Author>")
self.ui.clear.hide ( )
self.ui.cnti.hide ()
self.ui.label_3.hide ( )
global highsize
global lowsize
global highres
global lowres
highsize = yt.streams.get_highest_resolution().filesize
lowsize = yt.streams.get_lowest_resolution().filesize
highres = yt.streams.get_highest_resolution().resolution
lowres = yt.streams.get_lowest_resolution().resolution
print (r"\\\\\____Video algılandı____/////")
global findstatus
findstatus = "Yes"
print ("")
print (r"\\\\____Başlık____////")
print (yt.title)
print (r"\\\____Kanal____///")
print (yt.author)
print (r"\\____Süre____//")
print (round (yt.length / 60), ":", yt.length % 60) # Video Süresi Süre/60(Dakika) : Süre%60 (Saniye)
print (r"\____Kapak Fotoğrafı____/")
print (yt.thumbnail_url) # Kapak Fotoğrafının Verisini Çekip Site Aracılığına dönüştürüyor.
url = yt.thumbnail_url # Site URL
urllib.request.urlretrieve (url,
os.getcwd ( ) + r'\thunbail.jpg') # Kapak Fotoğrafını Belirtilen Yola kaydediyor. ( os.getcwd() projenin konumunu buluyor)
print (os.getcwd ( ) + r'\thunbail.jpg', 'konumuna', 'thubail.jpg olarak kaydedildi.')
self.ui.thumbnail.setPixmap (QtGui.QPixmap ("thunbail.jpg"))
self.ui.thumbnail.show ( )
d = yt.length / 60
s = yt.length % 60
self.ui.ytime.setText (str (round (d)) + " : " + str (round (s)))
self.ui.ytime.show ( )
self.ui.ytitle.setText (yt.title)
#self.ui.ytitle.setText("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
###########################TITLE####AUTO SCALE
fontsize = f"{len(self.ui.ytitle.text())}"
fontsize = fontsize[0]
fontsize2 = len(self.ui.ytitle.text())
bln = int (fontsize) - 1
bln2 = float (f"{bln}.5")
size = int(fontsize2 / bln2)
self.ui.ytitle.setFont(QFont("Arial", size))
#print(bln2)
###########################TITLE####AUTO SCALE
self.ui.ytitle.show ( )
self.ui.ytauthor.setText (yt.author)
###########################AUTHOR####AUTO SCALE
fontsize = f"{len(self.ui.ytauthor.text())}"
fontsize = fontsize[0]
fontsize2 = len(self.ui.ytauthor.text())
if fontsize2 < 10:
print("if worked")
bln = 0
bln2 = float (f"{bln}.3")
else:
bln = int (fontsize) - 1
bln2 = float (f"{bln}.5")
size = int(fontsize2 / bln2)
self.ui.ytauthor.setFont(QFont("Arial", size))
print(fontsize2)
print(bln2)
###########################AUTHOR####AUTO SCALE
self.ui.ytauthor.show ( )
self.ui.clear.show ( )
self.ui.cnti.show ( )
self.ui.label_3.show()
self.ui.finder.setText ("Find")
except:
print ("Geçersiz Link")
pyautogui.alert ('Error 404', "SynMax")
self.ui.finder.setText ("Find")
def FIND():
# ----> FINDER
movif = QMovie ("load.gif")
self.ui.Loading.setMovie (movif)
movif.start ( )
print("Clicked: Find Button")
self.ui.finder.setEnabled (False)
self.ui.searchbar.setEnabled (False)
self.ui.finder.setText ("...")
try:
YtFinder()
except:
print ("Geçersiz Link")
rl = open("error.txt", "w")
rl.truncate(0)
rl.write("Invaild Link!|14", )
rl.close()
rl = open ("error.txt", "r")
rlrd = rl.readline()
print(len(rlrd))
if len(rlrd) > 1:
MainError ( ).show ( )
self.ui.Loading.hide()
self.ui.finder.setText ("Find")
#YtFinder()
def CLEAR():
# ----> CLEAR FIND
print("Clicked: Clear Button")
self.ui.thumbnail.hide ( )
self.ui.ytime.hide ( )
self.ui.ytime.setText ("<Time>")
self.ui.ytitle.hide ( )
self.ui.ytitle.setText ("<Title>")
self.ui.ytauthor.hide ( )
self.ui.ytauthor.setText ("<Author>")
self.ui.clear.hide ( )
self.ui.cnti.hide ( )
self.ui.label_3.hide()
self.ui.searchbar.setText ("")
def CONITE():
print("Clicked: Continue Button(1)")
self.ui.thumbnail.hide ( )
self.ui.ytitle.hide ( )
self.ui.ytauthor.hide ( )
self.ui.ytime.hide ( )
self.ui.clear.hide ( )
self.ui.cnti.hide ( )
self.ui.label_3.hide ( )
self.ui.Loading.show ( )
self.ui.stackedWidget.setCurrentWidget (self.ui.page_3)
self.ui.vidname_2.setText (self.ui.ytitle.text ( ))
SCAN ( )
if self.ui.ytitle.text ( ) > r'64':
self.ui.vidname_2.setFont (QFont ('MS UI Gothic', 13))
self.ui.channel_2.setText (self.ui.ytauthor.text ( ))
self.ui.channel_2.setFont (QFont ('MS UI Gothic', 14))
self.ui.thumbnail_2.setPixmap (QtGui.QPixmap ('thunbail.jpg'))
self.ui.YTime.setText (self.ui.ytime.text ( ))
self.ui.CustomQ.hide ( )
self.ui.Custom.hide ( )
self.ui.LabelQ.hide ( )
self.ui.Low.hide ( )
self.ui.High.hide ( )
#PAGE3(2)
def RANDOMS():
# ----> RANDOM FILE NAME GENERATOR
print("Clicked: Random Button")
sayi1 = random.randint (1000000000, 9999999999)
sayi2 = random.randint (1000000000, 9999999999)
self.ui.Filebar.setText (str (sayi1) + "_" + str (sayi2))
def DEFLT():
# ----> Default File Name Setter
print("Clicked: Defeult Name Button")
self.ui.Filebar.setText (self.ui.ytitle.text ( ))
def openFile():
# ----> Folder dialog
print("Clicked: Folder Button")
root = Tk ( )
root.withdraw ( )
filepath = filedialog.askdirectory ( )
print (filepath)
root.destroy ( )
self.ui.FileLocName.setText (filepath)
def DEFAULT():
# ----> Default Folder Path
print("Clicked: Default Path Button")
from pathlib import Path
home = str (Path.home ( ))
self.ui.FileLocName.setText (home + "\Downloads")
def check():
# ----> Format Checker
print("Clicked: Any Format Button")
if self.ui.MP4.isChecked ( ):
# ui.Custom.show()
self.ui.LabelQ.show ( )
self.ui.Low.show ( )
self.ui.High.show ( )
self.ui.qts.setText (".mp4")
if self.ui.Custom.isChecked ( ):
self.ui.CustomQ.show ( )
if self.ui.Low.text ( ) == "<Low>":
self.ui.ScanQ.show ( )
elif self.ui.High.text ( ) == "<High>":
self.ui.ScanQ.show ( )
elif self.ui.AVI.isChecked ( ):
# ui.Custom.show()
self.ui.LabelQ.show ( )
self.ui.Low.show ( )
self.ui.High.show ( )
self.ui.qts.setText (".avi")
if self.ui.Custom.isChecked ( ):
self.ui.CustomQ.show ( )
if self.ui.Low.text ( ) == "<Low>":
self.ui.ScanQ.show ( )
elif self.ui.High.text ( ) == "<High>":
self.ui.ScanQ.show ( )
elif self.ui.MP3.isChecked ( ):
self.ui.CustomQ.hide ( )
self.ui.Custom.hide ( )
self.ui.LabelQ.hide ( )
self.ui.Low.hide ( )
self.ui.ScanQ.hide ( )
self.ui.High.hide ( )
self.ui.qts.setText (".mp3")
else:
self.ui.CustomQ.hide ( )
self.ui.Custom.hide ( )
self.ui.LabelQ.hide ( )
self.ui.Low.hide ( )
self.ui.High.hide ( )
def chenck():
#link = self.ui.searchbar.text ( )
#yt = YouTube (link, on_progress_callback=progress)
# ----> Quality Checker
print("Clicked: Any Quality Button")
if self.ui.Custom.isChecked ( ):
self.ui.CustomQ.show ( )
elif self.ui.High.isChecked ( ):
self.ui.CustomQ.hide ( )
self.ui.qts_2.setText (highres)
self.ui.VideoSize.setText ( str (round (highsize / (1024 * 1024))) + 'MB')
elif self.ui.Low.isChecked ( ):
self.ui.CustomQ.hide ( )
self.ui.qts_2.setText (lowres)
self.ui.VideoSize.setText (str (round (lowsize / (1024 * 1024))) + 'MB')
else:
self.ui.CustomQ.hide ( )
def SCAN():
# ----> Quality Scanner
link = self.ui.searchbar.text ( )
yt = YouTube (link, on_progress_callback=progress)
fillse = yt.streams.get_highest_resolution ( )
self.ui.High.setText (yt.streams.get_highest_resolution ( ).resolution)
self.ui.Low.setText (yt.streams.get_lowest_resolution ( ).resolution)
# ui.VideoSize.setText (str (round (yt.streams.get_highest_resolution ( ).filesize / (1024 * 1024))) + 'MB')
vs = yt.streams.get_highest_resolution ( ).filesize / (1024 * 1024)
def CANCEL():
# ----> CANCEL TO PAGE1
self.ui.stackedWidget.setCurrentWidget (self.ui.page)
def NEXTY():
link = self.ui.searchbar.text ( )
yt = YouTube (link, on_progress_callback=progress)
fillse = yt.streams.get_highest_resolution ( )
if self.ui.High.isChecked ( ):
self.ui.VideoSize.setText (
str (round (yt.streams.get_highest_resolution ( ).filesize / (1024 * 1024))) + 'MB')
global vs
vs = yt.streams.get_highest_resolution ( ).filesize / (1024 * 1024)
global vsd
vsd = yt.streams.get_highest_resolution ( ).filesize
elif self.ui.Low.isChecked ( ):
self.ui.VideoSize.setText (
str (round (yt.streams.get_lowest_resolution ( ).filesize / (1024 * 1024))) + 'MB')
vs = yt.streams.get_highest_resolution ( ).filesize / (1024 * 1024)
elif self.ui.Custom.isChecked ( ):
...
# \___________HATALAR___________/
total, used, free = shutil.disk_usage ("/")
nfree = free // (1024 * 1024)
if self.ui.qts.text ( ) == "Format":
rl = open("error.txt", "w")
rl.truncate(0)
rl.write("Select Format!|14", )
rl.close()
rl = open ("error.txt", "r")
rlrd = rl.readline()
print(len(rlrd))
if len(rlrd) > 1:
MainError ( ).show ( )
elif self.ui.qts_2.text ( ) == "Quality":
rl = open ("error.txt", "w")
rl.truncate (0)
rl.write ("Select Quality!|14", )
rl.close ( )
rl = open ("error.txt", "r")
rlrd = rl.readline ( )
print (len (rlrd))
if len (rlrd) > 1:
MainError ( ).show ( )
elif nfree < vs:
rl = open("error.txt", "w")
rl.truncate(0)
rl.write("Not Enough Space Available On The Disk|10", )
rl.close()
rl = open ("error.txt", "r")
rlrd = rl.readline()
print(len(rlrd))
if len(rlrd) > 1:
MainError ( ).show ( )
else:
link = self.ui.searchbar.text()
self.ui.stackedWidget.setCurrentWidget(self.ui.page_5)
global yt
yt = YouTube(link, on_progress_callback=progress)
fillse = yt.streams.get_highest_resolution()
self.ui.progressBar.setValue(10)
Thread( target=DOWNLOAD, args=(fillse,), daemon=True ).start()
# DOWNLOAD()
self.ui.Location.setText ("File Location : " + self.ui.FileLocName.text ( ))
self.ui.Format.setText ("Format : " + self.ui.qts.text ( ))
def DOWNLOAD(fillse):
fillse.download(self.ui.FileLocName.text())
# if ui.High.isChecked():
# fills = yt.streams.get_highest_resolution().filesize
# vs = fills / (1024 * 1024)
# yt.streams.get_highest_resolution().download()
# elif ui.Low.isChecked():
# fills = yt.streams.get_lowest_resolution().filesize
# vs = fills / (1024 * 1024)
# yt.streams.get_lowest_resolution().download()
def progress(streams, chunk: bytes, bytes_remaining: int): # Yükleme Barı
contentsize = vsd
size = contentsize - bytes_remaining
timer = 1
print (float (size / contentsize * 100))
global steer
steer = int(size / contentsize * 100)
print(int(size / contentsize * 100))
self.ui.progressBar.setValue(steer)
def progress_bar(self, chunk, file_handle, bytes_remaining,):
contentsize = MainWindow().ui.VideoSize.text() #yt.streams.get_highest_resolution().filesize
size = contentsize - bytes_remaining
timer = 1
print (float (size / contentsize * 100))
self.ui.progressBar.setValue(10)
# MainWindow().ui.progressBar.setValue(float (size / contentsize * 100))
#PAGE4
#########
##########ALL BUTTONS##########
#########
#PAGE1
self.ui.finder.clicked.connect(FIND)
self.ui.clear.clicked.connect (CLEAR)
self.ui.cnti.clicked.connect (CONITE)
# PAGE3(2)
self.ui.pushButton_7.clicked.connect (RANDOMS)
self.ui.defay.clicked.connect (DEFLT)
self.ui.findfoldr.clicked.connect (openFile)
self.ui.pushButton_8.clicked.connect (DEFAULT)
self.ui.MP4.clicked.connect (check)
self.ui.MP3.clicked.connect (check)
self.ui.AVI.clicked.connect (check)
self.ui.Low.clicked.connect (chenck)
self.ui.High.clicked.connect (chenck)
self.ui.Custom.clicked.connect (chenck)
self.ui.ScanQ.clicked.connect (SCAN)
self.ui.pushButton_5.clicked.connect (CANCEL)
self.ui.pushButton_6.clicked.connect (NEXTY)
self.ui.pushButton_9.clicked.connect (CANCEL)
def mousePressEvent(self, event):
self.dragPos = event.globalPos ( )
def showTime(self):
global link
global yt
link = self.ui.searchbar.text ( )
class MainError(QMainWindow):
def __init__(self):
super (MainError, self).__init__ ( )
self.ui = Ui_Dialog()
self.ui.setupUi (self)
rlf = open("error.txt", "r")
rl = rlf.readline()
name, fsize = rl.split ("|")
self.ui.error.setText(name)
self.ui.error.setFont(QFont("MS Shell Dlg 2", int(fsize)))
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
self.ui.close.clicked.connect(lambda: self.close())
self.ui.Ok.clicked.connect(lambda: self.close())
self.ui.icona.clicked.connect(lambda: self.showMinimized())
self.dragPos = self.pos()
def mouseMoveEvent(event):
delta = QPoint (self.pos ( ) + event.globalPos ( ) - self.dragPos)
#print (self.pos ( ) + event.globalPos ( ) - self.dragPos)
self.move (self.pos ( ) + event.globalPos ( ) - self.dragPos)
self.dragPos = event.globalPos ( )
event.accept ( )
# WIDGET HAREKETİ
self.ui.titlebar.mouseMoveEvent = mouseMoveEvent
################
def mousePressEvent(self, event):
self.dragPos = event.globalPos()
if __name__=='__main__':
app=QApplication(sys.argv)
ex=MainWindow()
ex.show()
app.setWindowIcon(QtGui.QIcon("icon.ico"))
ex.setWindowIcon(QtGui.QIcon("icon.ico"))
sys.exit(app.exec_())
Çalıştı hocam. Çok teşekkür ederim şuan donma vs. yok progress bar sorunsuz hareket ediyor ve program donmuyor. Aynı şey aslında video aramada da oluyor. Tam olarak ne yaptınız?
hocam bende bu tür bir proje yapmak istiyorum.
sormak istediğim şunlar;
bu kodların hepsini tek başına mı yazdınız?
Birde önerebileceğiniz kaynaklar nelerdir?
- Kodları tek başıma yazdım. Zorlandığım yerleri ingilizce şekilde internette aratarak stackedoverwolf sitesinden araştırdım. O forumda çok insan var.
2.Hocam ben karışık yerden aldım. pytube öğrendim ve ilk başta normal bir şekilde python ile yaptım. Sonra pyqt öğrenip pytube projemin kodlarını pyqtye geçirdim. Fakat pyqt kütüphanesini şunlardan öğrendim:
https://www.youtube.com/c/YapayZekaLabs/videos
Gibi gibi. Tkinter biliyorsanız bunları da bi hayli öğrenirsiniz. İyice ilerledikten sonra class kullanmanızı tavsiye ederim. Bildiğim kaynaklar bunlar. İsterseniz @Asif hocam size önersin.
pytubeyi nerden öğrendiniz?
Download fonksiyonuna bakarsan diğerini ona uygun ayarlaya bilirsin. Download fonksiyonunu Thread kullanarak çağırdım.
Find() fonsiyonu içerisinde YtFinder() fonksiyonunu Thread kullanarak çağırmayı dene,
Thread( targets = YtFinder, daemon = True).start()
Fakat YtFinder çok fazla arayüz elemanına erişiyor, sorun yaratırmı bilemiyorum. Denemen lazım.
Saçma gelecek ama instagramdaki bir gönderiden. Pytubenin varlığından haberim yoktu. Bir instagram postunda gördüğüm gönderi ile temelini attım. Sonra araştırdım;
Pytube kalite ayarlama
Video dönüştürme
Gibi araştırmalar ile pytubede buraya kadar ilerleyebildim.
https://www.instagram.com/p/CYV7S-LgguE/
Ayrıca yazmayı unutmuştum bu arkadaşta iyi postlar atıyor. İnceleyebilirsiniz.
Uygulamayı kapatıyor fakat ben onu farklı defler oluşturarak halledebilirim. Teşekkürler yardımlarınız için.
ekranı görebilir miyiz ?
Tam olarak neyi ve nasıl?
youtube indirmede pyqt5 ekranı yaptınız galiba?
mantığı anlamak için ekranı görme şansımız var mı?
üstad güzel bir proje
bunu yapmayı düşünmüştüm sonra sizin postunuza denk geldim o yüzden ilgiliyim
mesela videonun nereye kaydedileceğini yaptınız mı?
os modülünü kullandınız mı?
farklı modül yazıp onu içe aktarmışssınız mesela
Hocam öncelikle Qt Designer ile tasarımını yaptım.
Ekran şu şekilde;
Çalıştırınca şu şekilde (Eski tasarımda kaldığı için öyle)
Find tuşuna bağlanıldığında barın yazısını link değişkenine kaydediyor.
Sonra pytube ile try yaparak videoyu arıyor. Sonuç çıkarsa bana elemanları gösteriyor.
PyTube verileri çekerek yansıtıyorum. Basit olayı. Bir çok yapım videosu var bakabilirsiniz. Ama kendiniz öğrenirseniz daha iyi olur.
Evet. Os modülü, nereye kaydedileceğini yaptım. download() fonksiyonunun içine nereye kaydedebileceğimizi yazabiliyoruz.
download(self.ui.outpoutfolder.text()) şeklinde mesela.
hocam playlist olayını yaptınız mı?
hocam dosyaya kaydetme fonksıyonu nerede?