def isRemoveMovieDialog(self, message): reply = QMessageBox.question(self, "提示框", message, QMessageBox.Yes | QMessageBox.No) if reply == QMessageBox.Yes: SqlUtils.delete_video(self.video_hash) if os.path.exists(self.cover_path): os.remove(self.cover_path) print("Yes")
def _confirm_pushButton_on_click(self): tag_list = "" for item in self.flowLayout.itemList: if item.widget().isChecked(): tag_list = tag_list + "," + item.widget().text() sql = "UPDATE video SET custom_tag = ? WHERE hash = ?" SqlUtils.update_video(sql, (tag_list, self.video_hash)) # self.parentWidget.tag_out_layout.removeItem(self.parentWidget.tag_layout) # sip.delete(self.parentWidget.tag_layout) # 删除控件的一个坑 https://my.oschina.net/yehun/blog/1813698 # self.parentWidget.tag_layout = QHBoxLayout() # 删除所有子控件 try: for i in range(self.parentWidget.tag_layout.count()): if self.parentWidget.tag_layout.itemAt(i).widget() != None: self.parentWidget.tag_layout.itemAt( i).widget().deleteLater() else: self.parentWidget.tag_layout.removeItem( self.parentWidget.tag_layout.itemAt(i)) print() except Exception as e: print(e) if (tag_list is not None) and (tag_list.strip() != ""): tag_array = tag_list.split(",") tag_text = QLabel("标签:") self.parentWidget.tag_layout.addWidget(tag_text) for tag in tag_array: if (tag is None) or (tag.strip() == ""): continue tag_lab = QLabel(tag) tag_lab.setTextInteractionFlags(Qt.TextSelectableByMouse | Qt.TextSelectableByKeyboard) tag_lab.setWordWrap(True) tag_lab.setFont(QFont("Microsoft YaHei")) tag_lab.setStyleSheet("color:red") # 文本颜色 # tag_lab.setStyleSheet("background-color:red"); # 背景色 self.parentWidget.tag_layout.addWidget(tag_lab) spacerItem = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum) self.parentWidget.tag_layout.addItem(spacerItem) self.parentWidget.tag_out_layout.addLayout( self.parentWidget.tag_layout) # if (tag_list is None) or (tag_list.strip() == ""): # intro = '' # self.parentWidget.intro_lab.setMaximumHeight(0) # else: # intro = "简介:" + intro # self.parentWidget.intro_lab.setMaximumHeight(1000) # self.parentWidget.intro_lab.setText(intro) self.close()
def _process_video_list(self, video_list): config = CommonUtils.read_config() image_type = config.get('DEFAULT', 'default_img_type') qb_identifier_str = config.get('DEFAULT', 'qb_identifier') qb_identifier_arr = qb_identifier_str.split(",") for _video_path in video_list: _video_path = _video_path.replace("\\", "/") _video_name = _video_path[_video_path.rfind('/') + 1:_video_path.rfind('.')] _hash = _video_name # _hash = file_md5(_video_path) is_exists, video_path_in_datebase = SqlUtils.hash_exists(_hash) if is_exists: if video_path_in_datebase != _video_path: # reply = QMessageBox.question(None, _video_name, "数据库中已存在名称相同的视频,是否更新视频路径?", # QMessageBox.Yes | QMessageBox.No) # if reply == QMessageBox.Yes: sql = "UPDATE video SET video_path = ?,video_name_local=? WHERE hash = ?" SqlUtils.update_video(sql, (_video_path, _video_name, _hash)) self.status_text_label.setText("更新路径完成") # self.statusbar.showMessage("更新路径完成", 5000) else: _identifier = "" _serious = "" _video_type = 0 try: _video_type = self.get_video_type(_video_name, qb_identifier_arr) if _video_type == 1: _identifier, _serious = self._get_qb_identifier( qb_identifier_arr, _video_name) print(_video_name + " : " + _identifier) else: pass except Exception as e: print(e) pass video = VideoFileClip(_video_path) # 打开视频 video.close() # 关闭视频 video_width = str(video.size[0]) video_height = str(video.size[1]) resolution = video_width + ',' + video_height # todo 获取视频时长 # video.duration sql = "INSERT INTO video (resolution,series,identifier,type,video_name_local,video_path,img_type,hash) VALUES (?,?,?,?,?,?,?,?)" SqlUtils.update_video( sql, (resolution, _serious, _identifier, _video_type, _video_name, _video_path, image_type, _hash)) self.status_text_label.setText(_video_name + " : " + _identifier + " 已导入") # self.statusbar.showMessage(_video_name + " : " + _identifier + " 已导入", 5000) print(_hash) self.status_text_label.setText("导入完成")
def download_pic(self): try: video = SqlUtils._select_("SELECT identifier,img_url from video where hash = " + '\''+ self.video_hash+'\'') is_success_download_img = CommonUtils.download_img(video[0][0], video[0][1]) if is_success_download_img: sql = "UPDATE video SET is_download = ? WHERE hash = ?" SqlUtils.update_video(sql, (2, self.video_hash)) # self.statusbar.showMessage("图片下载成功", 5000) print("2222") except Exception as e: print(e)
def update_video_info(self): video_list = SqlUtils._select_("SELECT video_path,hash from video") for video_entity in video_list: video_path = video_entity[0] hash = video_entity[1] if os.path.exists(video_path): video = VideoFileClip(video_path) # 打开视频 video.close() # 关闭视频 video_width = str(video.size[0]) video_height = str(video.size[1]) resolution = video_width + ',' + video_height video_duration = video.duration sql = "UPDATE video SET video_length_now = ? ,resolution = ? WHERE hash = ?" SqlUtils.update_video(sql, (video_duration, resolution, hash))
def initText(self, video_hash): video_list = SqlUtils.select_videos( "SELECT * from video where hash = " + '\'' + video_hash + '\'') video = video_list[0] self.identifier_lineEdit.setText(self.formate_str(video.identifier)) self.series_lineEdit.setText(self.formate_str(video.series)) self.type_lineEdit.setText(self.formate_str(video.type)) self.country_lineEdit.setText(self.formate_str(video.country)) self.img_type_lineEdit.setText(self.formate_str(video.img_type)) self.video_director_lineEdit.setText( self.formate_str(video.video_director)) self.publish_time_lineEdit.setText(self.formate_str( video.publish_time)) self.video_length_lineEdit.setText(self.formate_str( video.video_length)) self.video_zhizuoshang_lineEdit.setText( self.formate_str(video.video_zhizuoshang)) self.video_faxingshang_lineEdit.setText( self.formate_str(video.video_faxingshang)) self.video_score_lineEdit.setText(self.formate_str(video.video_score)) self.like_stars_lineEdit.setText(self.formate_str(video.like_stars)) self.video_path_lineEdit.setText(self.formate_str(video.video_path)) self.title_lineEdit.setText(self.formate_str(video.title)) self.video_name_local_lineEdit.setText( self.formate_str(video.video_name_local)) self.custom_tag_textEdit.setText(self.formate_str(video.custom_tag)) self.actor_name_textEdit.setText(self.formate_str(video.actor_name)) self.video_tag_textEdit.setText(self.formate_str(video.video_tag)) self.intro_textEdit.setText(self.formate_str(video.intro)) print(video_hash)
def __init__(self, cover_path, cover_title, video_path, video_hash, *args, **kwargs): super(CoverLabel, self).__init__(*args, **kwargs) self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.rightMenuShow) # 开放右键策略 self.setCursor(Qt.PointingHandCursor) self.cover_path = cover_path # self.setScaledContents(True) # self.setMinimumSize(Const.GL_image_weight, Const.GL_image_height) # self.setMaximumSize(Const.GL_image_weight, Const.GL_image_height) self.video_hash = video_hash self.cover_title = cover_title self.video_path = video_path if not (os.path.exists(cover_path)): print("the img is not exist : "+cover_path) cover_path = "cache/coverimg/default.jpg" img = Image.open("cache/coverimg/default.jpg") try: img = Image.open(cover_path) except Exception as e: print("图片已损坏 : "+str(e)) os.remove(cover_path) # 将下载状态置为1 sql = "UPDATE video SET is_download = ? WHERE hash = ?" SqlUtils.update_video(sql, (1,video_hash)) cover_path = "cache/coverimg/default.jpg" img_height = Const.GL_image_weight / img.size[0] * img.size[1] if cover_path.endswith('.gif'): movie = QMovie(cover_path) # movie.setScaledSize(self.size()) movie.setScaledSize(QSize(Const.GL_image_weight, img_height)) self.setMinimumSize(Const.GL_image_weight, img_height) self.setMaximumSize(Const.GL_image_weight, img_height) # self.parent().setMaximumSize(GL_widget_weight, img_height+100) # self.parent().setMaximumSize(GL_widget_weight, img_height+100) self.parent().setFixedWidth(Const.GL_widget_weight) self.setMovie(movie) movie.start() else: cover_img = QPixmap(cover_path) self.setPixmap(cover_img.scaled(Const.GL_image_weight, img_height)) self.setMinimumSize(Const.GL_image_weight, img_height) self.setMaximumSize(Const.GL_image_weight, img_height) # self.parent().setMaximumSize(GL_widget_weight, img_height+100) # self.parent().setMaximumSize(GL_widget_weight, img_height+100) self.parent().setFixedWidth(Const.GL_widget_weight)
def _save_button_on_click(self): paramters = (self.identifier_lineEdit.text(), self.series_lineEdit.text(), self.type_lineEdit.text(), self.country_lineEdit.text(), self.img_type_lineEdit.text(), self.video_director_lineEdit.text(), self.publish_time_lineEdit.text(), self.video_length_lineEdit.text(), self.video_zhizuoshang_lineEdit.text(), self.video_faxingshang_lineEdit.text(), self.video_score_lineEdit.text(), self.like_stars_lineEdit.text(), self.video_path_lineEdit.text(), self.title_lineEdit.text(), self.video_name_local_lineEdit.text(), self.custom_tag_textEdit.toPlainText(), self.actor_name_textEdit.toPlainText(), self.video_tag_textEdit.toPlainText(), self.intro_textEdit.toPlainText(), self.video_hash) sql = "UPDATE video SET identifier = ?,series = ?,type = ?,country = ?,img_type = ?" \ ",video_director = ?,publish_time = ?,video_length = ? ,video_zhizuoshang = ?,video_faxingshang = ?,video_score = ?" \ ",like_stars = ? ,video_path = ?,title = ?,video_name_local = ?,custom_tag = ?,actor_name = ?,video_tag = ?" \ ",intro = ? WHERE hash = ?" SqlUtils.update_video(sql, paramters) intro = self.intro_textEdit.toPlainText() if (intro is None) or (intro.strip() == ""): intro = '' self.parentWidget.intro_lab.setMaximumHeight(0) else: intro = "简介:" + intro self.parentWidget.intro_lab.setMaximumHeight(1000) self.parentWidget.intro_lab.setText(intro) # layout = self.parentWidget.parentWidget()._layout # layout.takeAt(0) # self.parentWidget.parentWidget()._layout.removeWidget(self.parentWidget) # sip.delete(self.parentWidget) # 删除控件的一个坑 https://my.oschina.net/yehun/blog/1813698 # from ItemWidget import ItemWidget # item = ItemWidget("","waopfjw","jawojgowg","wjoga","jwag","3","wioafj","gawg","gwag","awgwag",self) # layout.addWidget(item,0,0) self.close()
def _downlowd_img(self): try: video_list = SqlUtils._select_( "SELECT identifier,img_url,hash from video where is_download = 1 and type = 1" ) for video in video_list: if not (os.path.exists('cache/coverimg/' + video[0] + '.jpg')): is_success_download_img = CommonUtils.download_img( video[0], video[1]) if is_success_download_img: sql = "UPDATE video SET is_download = ? WHERE hash = ?" SqlUtils.update_video(sql, (2, video[2])) self.status_text_label.setText(video[0] + " : 图片下载成功") # self.statusbar.showMessage("图片下载成功", 5000) print("2222") sql = "UPDATE video SET is_download = ? WHERE hash = ?" SqlUtils.update_video(sql, (2, video[2])) self.status_text_label.setText("所有图片下载完成") except Exception as e: print("下载异常,请重试: " + str(e)) pass
def _downlowd_info(self): try: video_list = SqlUtils._select_( "SELECT identifier,hash from video where is_download = 0 and type = 1" ) for video in video_list: # self.statusbar.showMessage("下载影片信息中, 影片本地名称:" + video[1] + " 识别码:" + video[0]) self.status_text_label.setText("下载影片信息中, 影片本地名称:" + video[1] + " 识别码:" + video[0]) CommonUtils.get_video_info(video[0], video[1], 1) # self.statusbar.showMessage("影片-" + video[1] + "-信息下载完成") self.status_text_label.setText("影片-" + video[1] + "-信息下载完成") # self.statusbar.showMessage("所有影片信息下载完成") self.status_text_label.setText("所有影片信息下载完成") except Exception as e: print("下载异常,请重试: " + str(e)) pass
def init_sql(self): video_count = SqlUtils._select_("SELECT count(id) FROM 'video'" + Const.Where)[0][0] config = CommonUtils.read_config() count_per_page = int(config.get('DEFAULT', 'count_per_page')) current_page_num = int(self.page_num_lineEdit.text()) self.page_num_all_label.setText( str(math.ceil(video_count / count_per_page))) start = str((current_page_num - 1) * count_per_page) Const.Limit = " Limit " + start + "," + str(count_per_page) if self.like_order_radioButton.isChecked(): Const.Order = " ORDER BY like_stars " if self.time_order_radioButton.isChecked(): Const.Order = " ORDER BY id " if self.asc_order_radioButton.isChecked(): Const.Order = Const.Order + "ASC" if self.desc_order_radioButton.isChecked(): Const.Order = Const.Order + "DESC" Const.Gl_Refresh_Sql = Const.Sql + Const.Where + Const.Order + Const.Limit print()
def __init__(self, video_hash, parentWidget): super(edit_video_custom_tab, self).__init__() self.video_hash = video_hash self.setupUi(self) self.parentWidget = parentWidget self.confirm_pushButton.clicked.connect( self._confirm_pushButton_on_click) custom_tag_str = str( CommonUtils.get_setting_ini_('DEFAULT', 'custom_tag', "")) video_tag_str = SqlUtils._select_( "SELECT custom_tag from video where hash = " + '\'' + video_hash + '\'')[0][0] if video_tag_str == None: video_tag_str = '' video_tag_list = video_tag_str.split(",") for tag in custom_tag_str.split(","): if tag.strip() == '': continue self.checkBox = QCheckBox(tag) self.checkBox.setChecked(False) if tag in video_tag_list: self.checkBox.setChecked(True) self.flowLayout.addWidget(self.checkBox)
def search_pushButton_clicked(self): self.edit_search_condition_window = edit_search_condition() actor_array = list() series_array = list() custom_tag_array = list() series_set = set() actor_set = set() custom_tag_set = set() country_set = set() video_tag_set = set() entity_list = SqlUtils._select_( "SELECT series,actor_name,custom_tag,country,video_tag from video;" ) for entity in entity_list: self.addArrayToSet(series_set, entity[0]) self.addArrayToSetWithCount(actor_set, entity[1], 3) self.addArrayToSet(custom_tag_set, entity[2]) self.addArrayToSet(country_set, entity[3]) self.addArrayToSet(video_tag_set, entity[4]) self.stringToArray(actor_array, entity[1]) self.stringToArray(series_array, entity[0]) self.stringToArray(custom_tag_array, entity[2]) actor_show_list = self.sortedSetByValue(actor_set, actor_array) series_show_list = self.sortedSetByValue(series_set, series_array) custom_tag_show_list = self.sortedSetByValue(custom_tag_set, custom_tag_array) dict = { '系列': series_show_list, '演员': actor_show_list, '自定义标签': custom_tag_show_list } self.edit_search_condition_window.initDate(dict) self.edit_search_condition_window.Signal_OneParameter.connect( self.deal_emit_slot) self.edit_search_condition_window.show()
def like_star_combobox_changed(self, currentStars): sql = "UPDATE video SET like_stars = ? WHERE hash = ?" SqlUtils.update_video(sql, (currentStars, self.video_hash)) print(currentStars) # 响应测试语句
def get_video_info(identifier: str, hash, downlowd_type: int): config = read_config() url = config.get('DEFAULT', 'web_site') + "/" + identifier session = requests.Session() session.mount('http://', HTTPAdapter(max_retries=3)) session.mount('https://', HTTPAdapter(max_retries=3)) # response = requests.get(url) # 发get请求 response = None try: response = session.get(url, timeout=5) except requests.exceptions.RequestException as e: print(e) if "404 Page Not Found!" in response.text: print(identifier + ":该影片网站未收录或者识别码错误") return if "识别码搜寻结果" in response.text: html = etree.HTML(response.text, etree.HTMLParser()) url = config.get( 'DEFAULT', 'web_site') + html.xpath('//div[@class="video"]//a/@href')[0][1:] response = requests.get(url) html = etree.HTML(response.text, etree.HTMLParser()) title = getArrayFirst(html, '//div[@class="container"]/h3/text()') # span_list = html.xpath('//div[@class="col-md-3 info"]/p/span') # a_list = html.xpath('//div[@class="col-md-3 info"]/p/a') identifier_web = '' publish_time = '' video_length = '' video_director = '' video_zhizuoshang = '' video_faxingshang = '' video_score = 0 soup = BeautifulSoup(response.text, 'lxml') for item in soup.select('.col-md-3 p'): if '識別碼: ' in item.text: identifier_web = item.text.replace('識別碼: ', '').replace('\n', '') if '發行日期: ' in item.text: publish_time = item.text.replace('發行日期: ', '').replace('\n', '') if '長度: ' in item.text: video_length = item.text.replace('長度: ', '').replace('分鐘', '') if '導演: ' in item.text: video_director = item.text.replace('導演: ', '').replace('\n', '') if '製作商: ' in item.text: video_zhizuoshang = item.text.replace('製作商: ', '').replace('\n', '') if '發行商: ' in item.text: video_faxingshang = item.text.replace('發行商: ', '').replace('\n', '') tag_num = 0 for item in soup.select('.col-md-3 p'): tag_num = tag_num + 1 if item.text == '類別:': break video_tag = '' try: video_tag = soup.select('.col-md-3 p')[tag_num].text.replace('\n', ',') except: pass actor_num = 0 for item in soup.select('.col-md-3 p'): actor_num = actor_num + 1 if item.text == '演員:': break actor_name = '' try: actor_name = soup.select('.col-md-3 p')[actor_num].text.replace( '\n\n', '').replace('\n', ',') except: pass actor_name = actor_name + ',' img_url = soup.select(".bigImage img")[0].attrs.get('src') response.close() sql = "UPDATE video SET is_download = ?,title = ?,video_director=?,publish_time=?," \ "video_length=?,video_zhizuoshang=?,video_faxingshang=?,video_score=?," \ "video_tag=?,actor_name=? ,img_url = ? ,identifier_web=? WHERE hash = ?" SqlUtils.update_video( sql, (1, title, video_director, publish_time, video_length, video_zhizuoshang, video_faxingshang, video_score, video_tag, actor_name, img_url, identifier_web, hash))