Movies2HDD
A simple set of python scripts and libraries to work with movies. I use it with my DreamBox.
 All Classes Namespaces Files Functions Variables Pages
gui.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 '''A GUI to Movies2HDD.'''
3 
4 # Copyright (C) 2013 Niklas Sombert
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 print ("Movies2HDD's graphical user interface Copyright (C) 2013 Niklas Sombert")
20 print ("This program comes with ABSOLUTELY NO WARRANTY.")
21 print ("This is free software, and you are welcome to redistribute it")
22 print ("under certain conditions.")
23 
24 print ("")
25 
26 import sys
27 sys.stdout.write("Loading...")
28 sys.stdout.flush()
29 sys.stdout.write(" PySide")
30 sys.stdout.flush()
31 from PySide.QtCore import *
32 from PySide.QtGui import *
33 app = QApplication(sys.argv)
34 msg = QMessageBox()
35 msg.setWindowTitle("Movies2HDD")
36 sys.stdout.write(" Movies2HDD")
37 sys.stdout.flush()
38 from movies2hdd import Movies2HDD
39 movies2hdd = Movies2HDD()
40 sys.stdout.write(" ...done.")
41 sys.stdout.flush()
42 sys.stdout.write("\n")
43 sys.stdout.flush()
44 print ("")
45 
46 
47 class Step1(QWizardPage):
48  def __init__(self, parent=None):
49  super(Step1, self).__init__(parent)
50  self.setTitle("Select the folder and the series")
51  self.layout = QVBoxLayout()
52  self.introduction = QLabel("First, you need to select the folder where the movies are or should be placed. The name of the series is needed, too.")
53  self.introduction.setWordWrap(True)
54  self.layout.addWidget(self.introduction)
55  self.form = QFormLayout()
56  self.folder_selection = QPushButton("Select")
57  self.registerField("folder_selection", self.folder_selection)
58  self.folder_selection.clicked.connect(self.func_folder_selection)
59  self.form.addRow(self.tr("Select &folder:"), self.folder_selection)
60  self.series_selection = QPushButton("Select")
61  self.registerField("seriesid", self.series_selection)
62  self.series_selection.clicked.connect(self.func_series_selection)
63  self.form.addRow(self.tr("Select &series:"), self.series_selection)
64  self.layout.addLayout(self.form)
65  self.setLayout(self.layout)
66 
67  self.lang = QLineEdit()
68  self.registerField("lang", self.lang)
69 
70 
72  folder = QFileDialog.getExistingDirectory()
73  self.folder_selection.setText(folder)
74  self.setField("folder_selection", folder)
75 
77  seriesselection = SeriesSelection(self)
78  seriesselection.setWindowModality(Qt.WindowModal)
79  seriesselection.show()
80 
81  def validatePage(self):
82  if self.folder_selection.text() != "Select" and self.series_selection != "Select" and self.folder_selection.text() != "":
83  return(True)
84  else:
85  msg.setText("You need to select a folder and a series first.")
86  msg.show()
87  return(False)
88 
89 class Step2(QWizardPage):
90  def __init__(self, parent=None):
91  super(Step2, self).__init__(parent)
92  self.setTitle("Connect to your Dreambox")
93  self.layout = QVBoxLayout()
94  #self.introduction = QLabel("")
95  #self.introduction.setWordWrap(True)
96  #self.layout.addWidget(self.introduction)
97  self.check = QCheckBox("Do the movies need to be &downloaded?")
98  self.check.stateChanged.connect(self.func_check)
99  self.layout.addWidget(self.check)
100 
101  self.group = QGroupBox("Connection information")
102  self.group.layout = QVBoxLayout()
103  self.group.form = QFormLayout()
104 
105  self.host = QLineEdit()
106  self.registerField("host", self.host)
107  self.group.form.addRow(self.tr("&Host:"), self.host)
108  self.user = QLineEdit()
109  self.registerField("user", self.user)
110  self.group.form.addRow(self.tr("&User:"), self.user)
111  self.warning = QLabel("<strong color='red'>Warning:</strong> Your password will be sent unencryptedly!\nPlease do this only if you trust the network that you are currently connected to.\nOtherwise please tunnel your connection for example via SSH or VPN.")
112  self.warning.setWordWrap(True)
113  self.group.form.addRow(self.warning)
114  self.password = QLineEdit()
115  self.registerField("password", self.password)
116  self.password.setEchoMode(QLineEdit.EchoMode.Password)
117  self.group.form.addRow(self.tr("&Password:"), self.password)
118 
119  self.group.layout.addLayout(self.group.form)
120  self.group.setLayout (self.group.layout)
121  self.layout.addWidget(self.group)
122  self.group.setEnabled(False)
123 
124  self.setLayout(self.layout)
125 
126  def func_check(self):
127  self.group.setEnabled(self.check.isChecked())
128 
129 
130  def validatePage(self):
131  if self.check.isChecked() == False:
132  return(True)
133  else:
134  try:
135  movies2hdd.connect(self.host.text(), self.user.text(), self.password.text())
136  return(True)
137  except Exception as e:
138  #sys.stderr.write("ERROR: " + str(e) + "\n")
139  msg.setText("Could not connect.\nPlease check your input and your connection.\n\nThe detailed error message is:\n"+str(e))
140  msg.show()
141  raise
142  return(False)
143 
144  def nextId(self):
145  if self.check.isChecked() == False:
146  return(3)
147  else:
148  return(2)
149 
150 class Step3(QWizardPage):
151  def __init__(self, parent=None):
152  super(Step3, self).__init__(parent)
153  self.setTitle("Search for and select movies")
154  self.layout = QVBoxLayout()
155  self.introduction = QLabel("Please enter a string to search for:")
156  self.introduction.setWordWrap(True)
157  self.layout.addWidget(self.introduction)
158  self.form = QFormLayout()
159  self.lineEdit = QLineEdit()
160  self.form.addRow(self.tr("&Search string:"), self.lineEdit)
161  self.layout.addLayout(self.form)
162  self.pushButton = QPushButton("S&earch")
163  self.pushButton.clicked.connect(self.func_search)
164  self.layout.addWidget(self.pushButton)
165  self.list = QListWidget()
166  self.layout.addWidget(self.list)
167  self.setLayout(self.layout)
168 
169  def func_search(self):
170  self.list.clear()
171  movies = []
172  try:
173  movies = movies2hdd.getAviableMovies(self.lineEdit.text())
174  except:
175  try:
176  movies2hdd.connect(self.field("host"), self.field("user"), self.field("password"))
177  movies = movies2hdd.getAviableMovies(str(""+self.lineEdit.text()))
178  except Exception as e:
179  #sys.stderr.write("ERROR: " + str(e)+ "\n")
180  msg.setText("Something went wrong.\n\nThe detailed error message is:\n"+str(e))
181  msg.show()
182  raise
183  finally:
184  for x in movies:
185  self.list.addItem(QListWidgetItem(x))
186 
187 
188  def validatePage(self):
189  return(False)
190 
191 class SeriesSelection(QDialog):
192  def __init__(self, parent):
193  super(SeriesSelection, self).__init__(parent)
194  self.setWindowTitle("Series Selection")
195  self.layout = QVBoxLayout()
196  self.introduction = QLabel("Please enter the name of the series to search for and the language code.")
197  self.introduction.setWordWrap(True)
198  self.layout.addWidget(self.introduction)
199  self.form = QFormLayout()
200  self.form.series = QLineEdit()
201  self.form.addRow(self.tr("&Series:"), self.form.series)
202  self.form.lang = QLineEdit()
203  self.form.addRow(self.tr("&Language code:"), self.form.lang)
204  self.layout.addLayout(self.form)
205  self.searchButton = QPushButton("Se&arch")
206  self.layout.addWidget(self.searchButton)
207  self.searchButton.clicked.connect(self.searchForSeries)
208 
209  self.table = QTableWidget()
210  self.table.setColumnCount(3)
211  self.table.setHorizontalHeaderLabels(["ID", "Series", "Overview"])
212  self.layout.addWidget(self.table)
213 
214  self.button = QPushButton("Se&lect")
215  self.layout.addWidget(self.button)
216  self.button.clicked.connect(self.select)
217 
218  self.setLayout(self.layout)
219 
220  def searchForSeries(self):
221  #progress = QProgressDialog("Searching for the series...", "Close", 0, 1, self)
222  #progress.setWindowModality(Qt.WindowModal)
223  #progress.setWindowTitle("Movies2HDD")
224  #progress.setAutoClose(False)
225  #progress.setCancelButton(None)
226  #progress.setMinimumDuration(0)
227  #progress.show()
228  #progress.setValue(0)
229  try:
230  series = movies2hdd.getSeries(self.form.series.text())
231  #progress.setMaximum(series.__len__())
232  self.table.clear()
233  self.table.setRowCount(0)
234  self.table.setHorizontalHeaderLabels(["ID", "Series", "Overview"])
235  for x in series:
236  #progress.setValue(progress.value() + 1)
237  flags = int(Qt.ItemIsEnabled) #+ int(Qt.ItemIsSelectable)
238  self.table.setRowCount(self.table.rowCount() + 1)
239  sidItem = QTableWidgetItem(x['seriesid'])
240  sidItem.setFlags(flags)
241  self.table.setItem(self.table.rowCount() - 1, 0, sidItem)
242  SeriesNameItem = QTableWidgetItem(x['SeriesName'])
243  SeriesNameItem.setFlags(flags)
244  self.table.setItem(self.table.rowCount() - 1, 1, SeriesNameItem)
245  OverviewItem = QTableWidgetItem(x['Overview'].replace("\n", " "))
246  OverviewItem.setFlags(flags)
247  self.table.setItem(self.table.rowCount() - 1, 2, OverviewItem)
248  except Exception as e:
249  #sys.stderr.write("ERROR: " + str(e)+ "\n")
250  msg.setText("An error occured.\n\nThe detailed error message is:\n"+str(e))
251  msg.show()
252  #progress.hide()
253  raise
254 
255 
256  def select(self):
257  if(self.form.lang.text()!= ""):
258  try:
259  item = self.table.item(self.table.currentRow(), 0)
260  #The conversion str->int->str is not really needed. And it is nothing that the user can change. But it could prevent future issues.
261  sid = str(int(item.text()))
262  self.parent().series_selection.setText(sid)
263  self.parent().setField("seriesid", sid)
264  self.parent().setField("lang", self.form.lang.text())
265  self.close()
266  except:
267  msg.setText("You need to select one series by clicking on it.")
268  msg.show()
269  else:
270  msg.setText("You need to enter your language code.")
271  msg.show()
272 
273 
274 mainwindow = QWizard()
275 mainwindow.setWindowTitle("Movies2HDD")
276 mainwindow.step1 = Step1()
277 mainwindow.step2 = Step2()
278 mainwindow.step3 = Step3()
279 mainwindow.addPage(mainwindow.step1)
280 mainwindow.addPage(mainwindow.step2)
281 mainwindow.addPage(mainwindow.step3)
282 mainwindow.show()
283 app.exec_()
284 try:
285  movies2hdd.disconnect()
286 except:
287  pass