def updateWidgets(self, data): """ update the list with the data parameter :param data: :type: list of movies model :return: """ hasFilm = False self.lstWidgets.clear() for film in data: hasFilm = True try: item = QListWidgetItem(self.lstWidgets) itemW = ResultRow(self, film) item.setSizeHint(itemW.sizeHint()) self.lstWidgets.setItemWidget(item, itemW) #itemW.show.connect(lambda x: self.clickedSee(film)) itemW.btnSee.clicked.connect( lambda ignore, f=film: self.clickedSee(f)) except Exception as e: log.info("ERROR WHILE UPDATING MOVIE LIST") log.info(e) if hasFilm is True: self.lblNoFilm.setVisible(False) else: self.lblNoFilm.setVisible(True) self.lblNoFilm.setText("There is no result for this research") if Movie.query().count() == 0: self.lblNoFilm.setVisible(True) self.lblNoFilm.setText( "No film in database, please add a folder (File - add folder)") log.info("List of widgets %s", len(self.lstWidgets))
def _searchMovie(self, title): query = Movie.query().filter(Movie.name == title) log.info( "searching db first to see if we dont already have the movie %s", title) if query.count(): log.info("already have it") if hasattr(self, "emit"): self.emit(GoogleItResult(query.first())) else: return query.first() else: self._links[title] = [] log.info("searching .... ") try: time.sleep( .3 ) # add some sleep before anything else can be done, so that we don't get ip banned self._findOnDuck( title) #links found are stored in self._links[title] except: #if something went wrong with duck duck go try bing scraping time.sleep(.2) self._findOnBing( title) #links found are stored in self._links[title] finally: #now try the links if len( self._links[title] ): #maybe we had an error and couldn't connect to the internet for link in self._links[title].copy(): self.emit(TryLink(link, title)) else: #couldn't find any link ??? self.emit(NoLinkFound(title))
def deleteDirClicked(self, dirPath=None, item=None): """ delete the file and the movie form a given directory :param dirPath: the path of we didn't want to search movies anymore :param item: the item in the lstDir (QListWidget) :type dirPath: str :type item: QMovieWidgetItem :return: """ response = QMessageBox.question( self, "Delete folder ?", "Are you sure you want to delete this folder ? This will delete all metadata" " of movies that were contained in the folder", QMessageBox.Yes | QMessageBox.Cancel) if response == QMessageBox.Yes: listFileInDir = File.query().filter(File.base == dirPath) row = self.lstDir.row(item) for file in listFileInDir: movieId = file.movie_id movie = Movie.get(movieId) file.delete() if movie is not None: if len(movie.files) == 0: movie.delete() self.lstDir.takeItem(row)
def __init__(self, parent=None): """ This widget displays a list of film :param parent: parent of the widget :type parent: QWidget """ super(MovieListWidget, self).__init__(parent) self.createWidgets() self.updateWidgets(Movie.query())
def initWidget(self): self.addWidget(AdvancedSearch(self)) self.addWidget(MovieWidget(self)) self.addWidget(SettingsWidget(self)) s = MovieListWidget(self) self.addWidget(s) self.addWidget(AdvancedSearch(self)) self.addWidget(ExplorerWidget(self)) self.setCurrentWidget(s) # if there are movies we display the MovieListWidget otherwise we display the Explorer if Movie.query().count() > 0: self.setCurrentWidget(s) else: self.setCurrentWidget(self.widgetStore[ExplorerWidget.__name__]) log.info("initialized : %s widgets", self.widgetStore)
def run(self): """ Runs both process methods in an aysnc loop :return: """ log.info( "starting updator run [current time = %s] [timeout = %s] [previous run = %s]", time.time(), self._timeout, self.previousRun) if not hasattr(self, "emit"): self.runBlocking() return self._running = True # populate the queues for m in Movie.query(include_deleted=True): self._movies.put(m, True, 0.1) for f in File.query(include_deleted=True): self._files.put(f, True, 0.1) log.info( "updator queues will start processing [movies = %s] [files = %s]", self._movies.qsize(), self._files.qsize()) self.process() # start the processing
def runBlocking(self): """ This will do the same as run, but in a blocking way. It will process everything before returning handle of the thread. If you want to use this, you should use it in a separate thread. This method will be used in run() if the updator doesn't have any emit function :return: """ log.info( "starting updator run [current time = %s] [timeout = %s] [previous run = %s]", time.time(), self._timeout, self.previousRun) self._running = True for m in Movie.query(include_deleted=True): self._movies.put(m, True, 0.1) for f in File.query(include_deleted=True): # just search all files self._files.put(f, True, 0.1) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop.run_until_complete(self.procesFiles()) loop.run_until_complete(self.processMovies()) loop.close() self.previousRun = time.time() self._running = False
def _getMovieByImdbId(self, imdbId): q = Movie.query().filter(Movie.imdb_id == imdbId) if not q.count(): return False else: return q.first()
def _createMovieFromData(self, data): files = data["files"] root = data["root"] foundMovie = data["data"] if Movie.query().filter(Movie.imdb_id == foundMovie.imdb_id).count(): log.info("film %s [imdb_id = %s] already exists", foundMovie.title, foundMovie.imdb_id) return mov = Movie() mov.name = foundMovie.title #["title"] mov.imdb_id = foundMovie.imdb_id mov.genre = ", ".join( foundMovie.genres) if foundMovie.genres is not None else None mov.desc = "\n".join(foundMovie.plots) if getattr( foundMovie, "plots") is not None else None mov.release = datetime.strptime(str( foundMovie.year), "%Y") if foundMovie.year is not None else None mov.runtime = foundMovie.runtime if getattr( foundMovie, "runtime") is not None else None #TODO add models for this or fake ones like phurni mov.actors = ", ".join(map( lambda x: x.name, foundMovie.cast_summary)) if getattr( foundMovie, "cast_summary") is not None else None mov.directors = ", ".join( map(lambda x: x.name, foundMovie.directors_summary)) if getattr( foundMovie, "directors_summary") is not None else None mov.writer = ", ".join( map(lambda x: x.name, foundMovie.writers_summary)) if getattr( foundMovie, "writers_summary") is not None else None mov.poster = foundMovie.poster_url if getattr( foundMovie, "poster_url") is not None else None mov.rate = foundMovie.rating if getattr(foundMovie, "rating") is not None else None # and save it ! mov = mov.save() log.info("adding %s to the database", mov) for f in files: fi = File() fi.path = f fi.base = root mov.files.append(fi) #add the file mov.save() fi.save()
def btnDeleteFileClicked(self, file=None,item=None): """ Play the movie in the MoviePlayer or in the default player of the client system :param file: the file we want to play :type film: file model """ fileDel = None if file is None: fileDel = self.film.files[0] else: fileDel = file if item is not None: response = QMessageBox.question(self, "Delete file", "Delete the file from database ? it will not delete the file from your computer", QMessageBox.Yes | QMessageBox.Cancel) if response == QMessageBox.Yes: row = self.lstFile.row(item) self.lstFile.takeItem(row) if self.lstFile.count() is 1: self.lstFile.hide() self.btnLaunchFilm.show() self.btnDeleteFile.show() self.btnShowInDir.show() fileDel.delete() else: response = QMessageBox.question(self, "Delete the last file of the movie", "Delete the file and the <b>movie</b> from database ? it will not delete the movie from your computer", QMessageBox.Yes | QMessageBox.Cancel) if response == QMessageBox.Yes: fileDel.delete() self.film.delete() self.gui.emit(ShowFrame(mawie.gui.components.QMovieListWidget.MovieListWidget.__name__, data=Movie.query()))
operator = attr[1] value = attr[2] model = self.model if '.' in field: field_items = field.split('.') field_name = getattr(model, field_items[0], None) class_name = field_name.property.mapper.class_ new_model = getattr(class_name, field_items[1]) return field_name.has(OPERATORS[operator](new_model, value)) return OPERATORS[operator](getattr(model, field, None), value) def sort(self, sort_list): """ Sort """ order = [] for sort in sort_list: if sort_list[sort] == "asc": order.append(asc(getattr(self.model, sort, None))) elif sort_list[sort] == "desc": order.append(desc(getattr(self.model, sort, None))) return order if __name__ == '__main__': from mawie.models.Movie import Movie #res = elastic_query(Movie,{"filter":{"release":{'lte': '2014-09-19'},"name":{"like":"H-man"},"and":{"release":{'gte': '1980-01-01'}}}}) res = elastic_query(Movie,{"filter":{"name":{"like":"%h-man%"}}}) print("#############query################") print(res) print("#####################################") print(Movie.query().count()) print(len(res.all()))