-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
121 lines (82 loc) · 3.17 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from __future__ import unicode_literals
from downloader import Downloader
from cmd_interface import CmdInterface
from file_iterator import FileIterator
import sys
from qtpy import QtWidgets
from ui.mainwindow import Ui_MainWindow
from url_validator import url_is_valid
from shell_controller import duration_information, output_format_information, quick_mp3_download, quick_mp4_download, update_ydl
import logging
from PyQt5.QtGui import QIcon
# This file will run the program
# The pattern used is the Model View Controller
# This file will initialize the YdlController
logger = logging.getLogger(__name__) # now we use logger.debug, etc.
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(style="{", fmt="{asctime} [{levelname}] {message}", datefmt="%d.%m.%Y %H:%M:%S")
file_handler = logging.FileHandler('run.log')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
interface = CmdInterface
fIter = FileIterator
title = ""
link = ""
author = ""
duration = 0
linkList = fIter.link_generator(fIter, "_done.txt")
# begin with qt implementation
app = QtWidgets.QApplication(sys.argv)
class MainWindow(QtWidgets.QMainWindow):
def read_format(self):
return self.ui.comboBox.currentText()
def download(self):
link = self.ui.lineEdit.text()
f = self.read_format()
logger.debug("beginning download..." + f)
if (f == "mp3"):
quick_mp3_download(link)
elif (f == "mp4"):
quick_mp4_download(link)
# todo: will be led to a new class: a communicator with the console. (?)
def get_information(self):
information = self.sc.output_format_information(self.ui.lineEdit.text())
for item in information:
self.ui.comboBox_2.addItem(item)
#self.title =
def on_url_change(self):
# log print("url changed")
url = self.ui.lineEdit.text()
if(url_is_valid(url)):
self.ui.downloadButton.setEnabled(True)
else:
self.ui.downloadButton.setDisabled(True)
self.ui.lineEdit.setText("Your link was not a valid YouTube link...")
# this string will cause a graying of each element. yeah
def __init__(self, parent=None):
super().__init__(parent)
update_ydl()
logger.info("updater finished")
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.dl = Downloader
self.setWindowIcon(QIcon("icons/Ydl_V2.png"))
self.ui.downloadButton.clicked.connect(self.download)
self.ui.lineEdit.textChanged.connect(self.on_url_change)
self.setWindowTitle("YouTube-Downloader Version Alpha 0.4.3")
window = MainWindow()
window.show()
def set_label_updating(self):
window.ui.label.setText("Updating... Please wait")
def set_label_downloading(self):
window.ui.label.setText("Downloading...")
def set_label_success(self):
window.ui.label.setText("Download succeeded")
# for future cases
def set_label_failed(self):
window.ui.label.setText("Download failed")
# should be called from extern, like downloader
def write_saved(self, link):
with open("_done.txt", "w") as file:
file.writelines(link)
sys.exit(app.exec_())