Skip to content

Commit

Permalink
correction du pull nightlyside
Browse files Browse the repository at this point in the history
et ajout de vidéos
  • Loading branch information
arblade committed Oct 9, 2020
1 parent 8356002 commit f7dc8d5
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/usr/bin/python"
}
13 changes: 9 additions & 4 deletions app/GUI.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'mainwindow.ui'
# Form implementation generated from reading ui file 'app/mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.12.3
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtWidgets
from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
Expand Down Expand Up @@ -51,6 +51,9 @@ def setupUi(self, MainWindow):
self.checkBox = QtWidgets.QCheckBox(self.centralWidget)
self.checkBox.setObjectName("checkBox")
self.verticalLayout.addWidget(self.checkBox)
self.checkBox_video = QtWidgets.QCheckBox(self.centralWidget)
self.checkBox_video.setObjectName("checkBox_video")
self.verticalLayout.addWidget(self.checkBox_video)
self.state = QtWidgets.QLabel(self.centralWidget)
self.state.setWordWrap(True)
self.state.setObjectName("state")
Expand Down Expand Up @@ -78,12 +81,14 @@ def setupUi(self, MainWindow):
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label_3.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\"><img src=\":/name/icon_little.png\"/></p></body></html>"))
self.label_3.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\"><img src=\":/name/assets/icon_little.png\"/></p></body></html>"))
self.label_2.setText(_translate("MainWindow", "<html><head/><body><p>Link</p></body></html>"))
self.label.setText(_translate("MainWindow", "Directory "))
self.lineEdit.setPlaceholderText(_translate("MainWindow", "Path of download, default if empty"))
self.pushButton_2.setText(_translate("MainWindow", "Browse"))
self.lineEdit_link.setPlaceholderText(_translate("MainWindow", "Link of the video or playlist"))
self.lineEdit_link.setPlaceholderText(_translate("MainWindow", "Link of the video, music or playlist"))
self.checkBox.setText(_translate("MainWindow", "playlist in separate folder"))
self.checkBox_video.setText(_translate("MainWindow", "video"))
self.state.setText(_translate("MainWindow", "<html><head/><body><p>State : None</p></body></html>"))
self.pushButton.setText(_translate("MainWindow", "Download"))
import app.test_rc
28 changes: 13 additions & 15 deletions app/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import os
class Model():
def __init__(self):
self.path=None
self.folder = os.path.dirname(os.path.abspath(__file__))
self.config=self.folder+'/../config.txt'
self.path_music=None
self.path_video=None
self.dir = None
self.config=None

def set_config(self):
if not self.fileIsValid(self.config):
Expand All @@ -22,12 +23,16 @@ def get_config(self):
elems=line.split("=")
param=elems[0]
param.replace(" ", "") # on enlève les espaces potentiels
if param=='default_path':
self.path=re.sub("\r|\n|\s","",elems[1]) # on enlève les espaces potentiels
if self.path[-1]=="/": # au cas où l'utilisateur mette un /
self.path=self.path[:-1]
if param=='default_path_music':
self.path_music=re.sub("\r|\n|\s","",elems[1]) # on enlève les espaces potentiels
if self.path_music[-1]=="/": # au cas où l'utilisateur mette un /
self.path_music=self.path_music[:-1]
elif param=='default_path_video':
self.path_video=re.sub("\r|\n|\s","",elems[1]) # on enlève les espaces potentiels
if self.path_video[-1]=="/": # au cas où l'utilisateur mette un /
self.path_video=self.path_video[:-1]

return self.path
return self.path_music,self.path_video


def fileIsValid(self,file):
Expand Down Expand Up @@ -55,10 +60,3 @@ def get_path(self):
return self.path



a=Model()
print(a.get_config())




11 changes: 9 additions & 2 deletions app/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;:/name/icon_little.png&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;:/name/assets/icon_little.png&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -76,7 +76,7 @@
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_link">
<property name="placeholderText">
<string>Link of the video or playlist</string>
<string>Link of the video, music or playlist</string>
</property>
</widget>
</item>
Expand All @@ -89,6 +89,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_video">
<property name="text">
<string>video</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="state">
<property name="text">
Expand Down
6 changes: 6 additions & 0 deletions app/test.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<RCC>
<qresource prefix="name">
<file>../assets/icon.png</file>
<file>../assets/icon_little.png</file>
</qresource>
</RCC>
23 changes: 15 additions & 8 deletions app/test_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,10 @@
\x00\x07\x48\x35\
\x00\x6e\
\x00\x61\x00\x6d\x00\x65\
\x00\x06\
\x06\x8a\x9c\xb3\
\x00\x61\
\x00\x73\x00\x73\x00\x65\x00\x74\x00\x73\
\x00\x0f\
\x07\xad\x88\xa7\
\x00\x69\
Expand All @@ -1486,20 +1490,23 @@

qt_resource_struct_v1 = b"\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\
\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x00\x32\x00\x00\x00\x00\x00\x01\x00\x00\x0b\xd6\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\
\x00\x00\x00\x0e\x00\x02\x00\x00\x00\x02\x00\x00\x00\x03\
\x00\x00\x00\x20\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x00\x44\x00\x00\x00\x00\x00\x01\x00\x00\x0b\xd6\
"

qt_resource_struct_v2 = b"\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x01\x74\xac\x2c\x44\x61\
\x00\x00\x00\x32\x00\x00\x00\x00\x00\x01\x00\x00\x0b\xd6\
\x00\x00\x01\x74\xa6\x80\xff\x77\
\x00\x00\x00\x0e\x00\x02\x00\x00\x00\x02\x00\x00\x00\x03\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x20\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x01\x75\x0e\xc2\x17\x67\
\x00\x00\x00\x44\x00\x00\x00\x00\x00\x01\x00\x00\x0b\xd6\
\x00\x00\x01\x75\x0e\xc2\x17\x67\
"

qt_version = [int(v) for v in QtCore.qVersion().split('.')]
Expand Down
39 changes: 17 additions & 22 deletions app/yt_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
from app import GUI
from app.Model import *
from gi.repository import Notify,GdkPixbuf
from pathlib import Path



class MyApp(QtWidgets.QMainWindow, GUI.Ui_MainWindow):
def __init__(self, parent=None):
def __init__(self, model,parent=None):
super(MyApp, self).__init__(parent)
self.setupUi(self)

# Connect a button to a function
app_icon = QtGui.QIcon('/home/theophane/Documents/youtube-downloader/yt-downloader/icon.png')
self.setWindowIcon(app_icon)
self.model=model
self.pushButton.clicked.connect(self.run)
self.process=None
self.progressBar.setValue(0)
Expand Down Expand Up @@ -65,7 +63,7 @@ def terminate(self):
self.progressBar.setValue(100)
Notify.init("App Name")
# Use GdkPixbuf to create the proper image type
image = GdkPixbuf.Pixbuf.new_from_file(model.folder+"/icon.png")
image = GdkPixbuf.Pixbuf.new_from_file(self.model.dir+"/assets/icon.png")

# Use the GdkPixbuf image
summary = "Download Complete !"
Expand All @@ -85,26 +83,30 @@ def run(self):
link = self.lineEdit_link.text()

if self.lineEdit.text() :
if not model.set_path(str(self.lineEdit.text())):
if not self.model.set_path(str(self.lineEdit.text())):
self.state.setText("State : Cannot find the path")
return
else :
path=model.get_path()
path=self.model.get_path()
else :
if not model.set_config():
if not self.model.set_config():
self.state.setText("State : Cannot find the configuration file")
return
else :
path=model.get_config()
path_music,path_video=self.model.get_config()
if link[0:4]=="http": #petite vérification
self.state.setText("State : Launching Download")
self.create_process() # on crée le process
if not self.checkBox.isChecked():
if not self.checkBox.isChecked() and not self.checkBox_video.isChecked():
#cmd = 'youtube-dl -x --embed-thumbnail --format bestaudio --output \"~/Musique/yt-download/%(title)s.%(ext)s\" {}'.format(link)
self.process.start('youtube-dl',['-x','--embed-thumbnail','--format', 'bestaudio', '--output', path+'/%(title)s.%(ext)s\"', link])
else :
self.process.start('youtube-dl',['-x','--embed-thumbnail','--format', 'bestaudio', '--output', path_music+'/%(title)s.%(ext)s', link])
elif self.checkBox.isChecked() and not self.checkBox_video.isChecked():
#cmd = 'youtube-dl -x --embed-thumbnail --format bestaudio --output \"~/Musique/yt-download/%(playlist)s/%(title)s.%(ext)s\" {}'.format(link)
self.process.start('youtube-dl',['-x','--embed-thumbnail','--format', 'bestaudio', '--output',path+'/%(playlist)s/%(title)s.%(ext)s\"', link])
self.process.start('youtube-dl',['-x','--embed-thumbnail','--format', 'bestaudio', '--output',path_music+'/%(playlist)s/%(title)s.%(ext)s', link])
elif self.checkBox_video.isChecked():
self.process.start('youtube-dl',['-f','mp4','--output',path_video+'/%(title)s.%(ext)s', link])
else :
self.process.start('youtube-dl',['--output',path_video+'/%(playlist)s/%(title)s.%(ext)s', link])
#os.system(cmd)
#subp.run(['youtube-dl','-x','--embed-thumbnail','--format', 'bestaudio', '--output', '\"~/Musique/yt-download/%(title)s.%(ext)s\"', link],capture_output=True, text=True)
#process=subp.Popen(['youtube-dl','-x','--embed-thumbnail','--format', 'bestaudio', '--output', '\"~/Musique/yt-download/%(title)s.%(ext)s\"', link],stdout=subp.PIPE)
Expand All @@ -115,12 +117,5 @@ def run(self):
self.state.setText("State : Stopped : wrong link")
return

if __name__ == '__main__':
model=Model()
app = QtWidgets.QApplication(sys.argv)
form = MyApp()
form.setWindowIcon(QtGui.QIcon(model.folder+'/icon.png'))
form.setWindowTitle("Youtube-Downloader")
form.show()
app.exec_()


3 changes: 2 additions & 1 deletion config.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Configuration file

# Path to folder like home/arblade/myfolder
default_path=/home/theophane/Musique/yt-download/
default_path_music=/home/theophane/Musique/yt-download/
default_path_video=/home/theophane/Vidéos/yt-download/
7 changes: 5 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import sys
from app.Model import *
from app.yt_downloader import MyApp
import app.test_rc

if __name__ == '__main__':
model=Model()
app = QtWidgets.QApplication(sys.argv)
form = MyApp()
form.setWindowIcon(QtGui.QIcon(model.folder+'/icon.png'))
form = MyApp(model)
model.dir=os.path.dirname(os.path.abspath(__file__))
model.config=model.dir+'/config.txt'
form.setWindowIcon(QtGui.QIcon(model.dir+'/assets/icon.png'))
form.setWindowTitle("Youtube-Downloader")
form.show()
app.exec_()
5 changes: 3 additions & 2 deletions prep
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pyrcc5 test.qrc -o test_rc.py
pyuic5 mainwindow.ui -o GUI.py
pyrcc5 app/test.qrc -o app/test_rc.py
pyuic5 app/mainwindow.ui -o app/GUI.py
echo '[To do] Pensez à changer manuellement dans GUI.py le import test_rc en app.test_rc'

0 comments on commit f7dc8d5

Please sign in to comment.