def get_data(self): data = { 'url' : self.url, 'filename' : self.filename, 'max_pf_count' : self.max_pf_count, 'call_plugin' : self.call_plugin, 'temp_path' : self.temp_path, 'save_path' : self.save_path, 'temp_fullpath' : self.temp_fullpath, 'save_fullpath' : self.save_fullpath, 'status' : int(self.status), 'status_str' : self.status.name, 'status_kor' : str(self.status), 'duration' : self.duration, 'duration_str' : self.duration_str, 'current_duration' : self.current_duration, 'percent' : self.percent, 'current_pf_count' : self.current_pf_count, 'idx' : self.idx, #'log' : self.log, 'current_bitrate' : self.current_bitrate, 'current_speed' : self.current_speed, 'start_time' : '' if self.start_time is None else str(self.start_time).split('.')[0][5:], 'end_time' : '' if self.end_time is None else str(self.end_time).split('.')[0][5:], 'download_time' : '' if self.download_time is None else '%02d:%02d' % (self.download_time.seconds/60, self.download_time.seconds%60), 'exist' : os.path.exists(self.save_fullpath), } if self.status == Status.COMPLETED: data['filesize'] = self.filesize data['filesize_str'] = Util.sizeof_fmt(self.filesize) data['download_speed'] = Util.sizeof_fmt(self.filesize/self.download_time.seconds, suffix='Bytes/Second') return data
def change_filename_censored_by_save_original(include_original_filename, original_filename, new_filename, option='0', original_filepath=None): ''' 원본파일명 보존 옵션에 의해 파일명을 변경한다. ''' try: if include_original_filename: new_name, new_ext = os.path.splitext(new_filename) part = None match = re.search(r'(?P<part>cd\d+)$', new_name) if match: # cd1 앞에가 같아야함. return new_filename part = match.group('part') new_name = new_name.replace(part, '') ori_name, ori_ext = os.path.splitext(original_filename) # 2019-07-30 ori_name = ori_name.replace('[', '(').replace(']', ')').strip() if part is None: if option == '0': return '%s [%s]%s' % (new_name, ori_name, new_ext) elif option == '1': return '%s [%s(%s)]%s' % (new_name, ori_name, os.stat(original_filepath).st_size, new_ext) elif option == '2': from framework.util import Util return '%s [%s(%s)]%s' % (new_name, ori_name, Util.sizeof_fmt(os.stat(original_filepath).st_size, suffix='B'), new_ext) return '%s [%s]%s' % (new_name, ori_name, new_ext) else: #안씀 return '%s [%s] %s%s' % (new_name, ori_name, part, new_ext) else: return new_filename except Exception as exception: logger.debug('Exception:%s', exception) logger.debug(traceback.format_exc())
def check_option_size(item): try: flag_download = True option_min_size = ModelSetting.get_int('option_min_size') option_max_size = ModelSetting.get_int('option_max_size') if option_min_size != 0 and item.total_size < option_min_size: flag_download = False item.log += u'17.최소크기 - %s : %s\n' % (Util.sizeof_fmt(item.total_size, suffix='B'), flag_download) if option_max_size != 0 and item.total_size > option_max_size: flag_download = False item.log += u'17.최대크기 - %s : %s\n' % (Util.sizeof_fmt(item.total_size, suffix='B'), flag_download) if flag_download: item.log += u'17.크기 - %s : %s\n' % (Util.sizeof_fmt(item.total_size, suffix='B'), flag_download) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return flag_download
def as_dict(self): ret = {x.name: getattr(self, x.name) for x in self.__table__.columns} ret['created_time'] = self.created_time.strftime('%m-%d %H:%M:%S') ret['remote_time'] = self.remote_time.strftime('%m-%d %H:%M:%S') if self.remote_time is not None else '' ret['completed_time'] = self.completed_time.strftime('%m-%d %H:%M:%S') if self.completed_time is not None else '' ret['job'] = self.job.as_dict() try: ret['oc_fileSize'] = Util.sizeof_fmt(int(ret['oc_fileSize'])) if ret['oc_fileSize'] is not None else ret['oc_fileSize'] except: pass return ret
def get_info(): info = {} import platform info['platform'] = platform.platform() info['processor'] = platform.processor() import sys info['python_version'] = sys.version info['version'] = version info['recent_version'] = SystemLogic.recent_version info['path_app_root'] = path_app_root info['running_type'] = u'%s. 비동기 작업 : %s' % ( app.config['config']['running_type'], u"사용" if app.config['config']['use_celery'] else "미사용") import system info['auth'] = app.config['config']['auth_desc'] info['cpu_percent'] = 'not supported' info['memory'] = 'not supported' info['disk'] = 'not supported' if app.config['config']['running_type'] != 'termux': try: import psutil from framework.util import Util info['cpu_percent'] = '%s %%' % psutil.cpu_percent() tmp = psutil.virtual_memory() #info['memory'] = [Util.sizeof_fmt(tmp[0], suffix='B'), Util.sizeof_fmt(tmp[3]), Util.sizeof_fmt(tmp[1]), tmp[2]] info['memory'] = u'전체 : %s 사용량 : %s 남은량 : %s (%s%%)' % ( Util.sizeof_fmt(tmp[0], suffix='B'), Util.sizeof_fmt(tmp[3], suffix='B'), Util.sizeof_fmt(tmp[1], suffix='B'), tmp[2]) except: pass try: import platform if platform.system() == 'Windows': s = os.path.splitdrive(path_app_root) root = s[0] else: root = '/' tmp = psutil.disk_usage(root) info[ 'disk'] = u'전체 : %s 사용량 : %s 남은량 : %s (%s%%) - 드라이브 (%s)' % ( Util.sizeof_fmt(tmp[0], suffix='B'), Util.sizeof_fmt(tmp[1], suffix='B'), Util.sizeof_fmt(tmp[2], suffix='B'), tmp[3], root) except Exception as exception: pass try: tmp = SystemLogic.get_setting_value('system_start_time') #logger.debug('SYSTEM_START_TIME:%s', tmp) tmp_datetime = datetime.strptime(tmp, '%Y-%m-%d %H:%M:%S') timedelta = datetime.now() - tmp_datetime info['time'] = u'시작 : %s 경과 : %s 재시작 : %s' % ( tmp, str(timedelta).split('.')[0], app.config['config']['repeat']) except Exception as exception: info['time'] = str(exception) return info
def process_telegram_data(data): try: ret = ModelItem.process_telegram_data(data) logger.debug(data) #ret = None if ret is not None: if ModelSetting.get_bool('receive_send_notify'): msg = '😉 AV 정보 수신\n' msg += '제목 : [%s] %s (%s)\n' % (ret.code, ret.title, ret.date) msg += '파일 : %s\n' % ret.filename msg += '폴더 : %s\n' % ret.dirname msg += '크기 : %s\n' % Util.sizeof_fmt(ret.total_size) url = '%s/%s/api/add_download?id=%s' % ( SystemModelSetting.get('ddns'), package_name, ret.id) if SystemModelSetting.get_bool('auth_use_apikey'): url += '&apikey=%s' % SystemModelSetting.get( 'auth_apikey') if app.config['config']['is_sjva_server']: msg += '\n' + ret.magnet + '\n' else: msg += '\n➕ 다운로드 추가\n<%s>\n' % url #msg += '\n➕ 다운로드 추가\n<%s>\n' % url poster = ret.poster if ModelSetting.get_bool( 'show_poster_notify') else None import framework.common.notify as Notify Notify.send_message(msg, image_url=poster, message_id='bot_downloader_av_receive') LogicNormal.invoke() TorrentProcess.receive_new_data(ret, package_name) except Exception, e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def make_xml(self, remote, title, image, desc, genre): try: logger.debug('%s %s %s %s %s', remote, title, image, desc, genre) tmp = builder.ElementMaker( nsmap={'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}) root = tmp.rss(version="2.0") EE = builder.ElementMaker( namespace="http://www.itunes.com/dtds/podcast-1.0.dtd", nsmap={'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}) channel_tag = (E.channel( E.title(title), E.link(), E.description(desc), E.language('ko-kr'), E.copyright(''), EE.subtitle(), EE.author(), EE.summary(desc), EE.category(text=genre), EE.image(href=image), EE.explicit('no'), )) root.append(channel_tag) import rclone lsjson = RcloneTool2.lsjson(rclone.Logic.path_rclone, rclone.Logic.path_config, remote, option=['-R', '--files-only']) startdate = datetime.now() + timedelta(days=len(lsjson) * -1) for item in list(reversed(lsjson)): #logger.debug(item) if not item['MimeType'].startswith('audio'): continue channel_tag.append( E.item( E.title(item['Name']), #EE.subtitle(item['Name']), EE.summary(u'Path : {}/{}<br>Size : {}'.format( remote, item['Path'], Util.sizeof_fmt(item['Size'], suffix='B'))), E.guid(item['Name']), E.pubDate( startdate.strftime('%a, %d %b %Y %H:%M:%S') + ' +0900'), EE.duration(), #E.enclosure(url='https://drive.google.com/uc?export=download&id={}'.format(item['ID']), length=str(item['Size']), type=item['MimeType']), E.enclosure( url= 'https://drive.google.com/uc?export=download&id={}' .format(item['ID']), length=str(item['Size']), type='audio/mp3'), #E.description(item['Name']) )) startdate = startdate + timedelta(days=1) return app.response_class(ET.tostring(root, pretty_print=True, xml_declaration=True, encoding="utf-8"), mimetype='application/xml') except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def scheduler_function(): try: last_id = ModelSetting.get_int('last_id') flag_first = False if last_id == -1: flag_first = True # 최초 실행은 -1로 판단하고, 봇을 설정안했다면 0으로 query = db.session.query(ModelItem) \ .filter(ModelItem.created_time > datetime.datetime.now() + datetime.timedelta(days=-7)) items = query.all() else: query = db.session.query(ModelItem) \ .filter(ModelItem.id > last_id ) items = query.all() # 하나씩 판단.... logger.debug('New Feed.. last_id:%s count :%s', last_id, len(items)) for item in items: try: flag_download = False item.download_status = '' item.downloader_item_id = None item.log = '' option_auto_download = ModelSetting.get( '%s_auto_download' % item.av_type) if option_auto_download == '0': item.download_status = 'no' else: # censored - 메타 조건만.. flag_download = True if flag_download and item.av_type == 'censored': if ModelSetting.get( 'censored_option_meta' ) == '1' and item.meta_type == 'javdb': flag_download = False item.log += u'0. censored mode : False\n' if ModelSetting.get( 'censored_option_meta' ) == '2' and item.meta_type == 'dmm': flag_download = False item.log += u'0. censored mode : False\n' if flag_download: mode = 'blacklist' if ModelSetting.get( '%s_option_mode' % item.av_type) == '0' else 'whitelist' item.log += u'1. 모드 - %s. 다운여부 : ' % (mode) if mode == 'blacklist': flag_download = True item.log += u'%s\n' % flag_download # 2020-07-20 웨스턴 폴더명 조건 if flag_download and item.av_type == 'western': ret = LogicNormal.check_option( '%s_option_foldername_filter' % item.av_type, item.dirname) if ret is not None: flag_download = not ret item.log += u'0. 폴더명 - %s : %s\n' % ( item.dirname, flag_download) if flag_download: ret = LogicNormal.check_option( '%s_option_filter' % item.av_type, item.filename) if ret is not None: flag_download = not ret item.log += u'1. 파일명 - %s : %s\n' % ( item.filename, flag_download) if flag_download: ret = LogicNormal.check_option( '%s_option_label' % item.av_type, item.code) if ret is not None: flag_download = not ret item.log += u'2. 레이블 - %s : %s\n' % ( item.code, flag_download) if flag_download: ret = LogicNormal.check_option( '%s_option_genre' % item.av_type, item.genre) if ret is not None: flag_download = not ret item.log += u'3. 장르 - %s : %s\n' % ( item.genre, flag_download) if flag_download: ret = LogicNormal.check_option( '%s_option_performer' % item.av_type, item.performer) if ret is not None: flag_download = not ret item.log += u'4. 배우 - %s : %s\n' % ( item.performer, flag_download) else: flag_download = False item.log += u'%s\n' % flag_download if not flag_download and item.av_type == 'western': ret = LogicNormal.check_option( '%s_option_foldername_filter' % item.av_type, item.dirname) if ret is not None: flag_download = ret item.log += u'0. 폴더명 - %s : %s\n' % ( item.dirname, flag_download) if not flag_download: ret = LogicNormal.check_option( '%s_option_filter' % item.av_type, item.filename) if ret is not None: flag_download = ret item.log += u'1. 파일명 - %s : %s\n' % ( item.filename, flag_download) if not flag_download: ret = LogicNormal.check_option( '%s_option_label' % item.av_type, item.code) if ret is not None: flag_download = ret item.log += u'2. 레이블 - %s : %s\n' % ( item.code, flag_download) if not flag_download: ret = LogicNormal.check_option( '%s_option_genre' % item.av_type, item.genre) if ret is not None: flag_download = ret item.log += u'3. 장르 - %s : %s\n' % ( item.genre, flag_download) if not flag_download: ret = LogicNormal.check_option( '%s_option_performer' % item.av_type, item.performer) if ret is not None: flag_download = ret item.log += u'4. 배우 - %s : %s\n' % ( item.performer, flag_download) if flag_download: # and item.av_type == 'censored': try: option_min_size = float( str( ModelSetting.get('%s_option_min_size' % item.av_type))) * (2** 30) option_max_size = float( str( ModelSetting.get('%s_option_max_size' % item.av_type))) * (2** 30) if option_min_size != 0 and item.total_size < option_min_size: flag_download = False item.log += u'5. 최소크기 - %s : %s\n' % ( Util.sizeof_fmt( item.total_size, suffix='B'), flag_download) if option_max_size != 0 and item.total_size > option_max_size: flag_download = False item.log += u'5. 최대크기 - %s : %s\n' % ( Util.sizeof_fmt( item.total_size, suffix='B'), flag_download) if flag_download: item.log += u'5. 크기 - %s : %s\n' % ( Util.sizeof_fmt( item.total_size, suffix='B'), flag_download) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) item.log += u'6. 다운여부 : %s' % (flag_download) #다운로드 if flag_download: if option_auto_download == '1': import downloader downloader_item_id = downloader.Logic.add_download2( item.magnet, ModelSetting.get('%s_torrent_program' % item.av_type), ModelSetting.get('%s_path' % item.av_type), request_type=package_name, request_sub_type='', server_id='%s_%s_%s' % (item.server_id, item.file_count, item.total_size))['downloader_item_id'] item.downloader_item_id = downloader_item_id item.download_status = 'true' else: item.download_status = 'true_only_status' else: if option_auto_download == '1': item.download_status = 'false' else: item.download_status = 'false_only_status' if ModelSetting.get_bool('result_send_notify'): LogicNormal.send_telegram_message(item) item.download_check_time = datetime.datetime.now() db.session.add(item) logger.debug('%s - %s %s', item.code, flag_download, item.log) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) new_last_id = last_id if flag_first and len(items) == 0: new_last_id = '0' else: if len(items) > 0: new_last_id = '%s' % items[len(items) - 1].id if new_last_id != last_id: ModelSetting.set('last_id', str(new_last_id)) db.session.commit() except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def second_menu(sub, sub2): try: arg = ModelSetting.to_dict() job_id = '%s_%s' % (package_name, sub) if sub == 'base': arg['sub'] = sub if sub2 == 'setting': arg['size_upload'] = Util.sizeof_fmt( ModelSetting.get_int('size_upload'), suffix='B') arg['size_download'] = Util.sizeof_fmt( ModelSetting.get_int('size_download'), suffix='B') return render_template( '{package_name}_{sub}_{sub2}.html'.format( package_name=package_name, sub=sub, sub2=sub2), arg=arg) elif sub == 'av_sub': arg['sub'] = sub if sub2 == 'setting': return render_template( '{package_name}_{sub}_{sub2}.html'.format( package_name=package_name, sub=sub, sub2=sub2), arg=arg) elif sub2 == 'list': return render_template( '{package_name}_{sub}_{sub2}.html'.format( package_name=package_name, sub=sub, sub2=sub2), arg=arg) elif sub2 == 'detail': if 'folder_name' in request.form: arg['folder_name'] = request.form['folder_name'] ModelSetting.set('av_sub_folder_name', arg['folder_name']) else: arg['folder_name'] = ModelSetting.get('av_sub_folder_name') try: from plex.model import ModelSetting as PlexModelSetting arg['plex_url'] = PlexModelSetting.get('server_url') arg['plex_machineIdentifier'] = PlexModelSetting.get( 'machineIdentifier') except: pass return render_template( '{package_name}_{sub}_{sub2}.html'.format( package_name=package_name, sub=sub, sub2=sub2), arg=arg) elif sub2 == 'transfer': arg['mode'] = None if 'mode' not in request.form else request.form[ 'mode'] arg['server_type'] = None if 'mode' not in request.form else request.form[ 'server_type'] #arg['folder_id'] = 'zn4TpiHrBMtj8/S4j2q6WcUm8C2jB7YxzVaHI0M9lElk17NZKT1JjZ6Zkhe3ruFIfmPtBhpnSgmxsH2xTqZb6w==' if 'folder_id' not in request.form else request.form['folder_id'] arg['folder_id'] = '' if 'folder_id' not in request.form else request.form[ 'folder_id'] arg['folder_name'] = '' if 'folder_name' not in request.form else request.form[ 'folder_name'] arg['server_filename'] = '' if 'server_filename' not in request.form else request.form[ 'server_filename'] arg['defalut_remote_path'] = arg[ 'defalut_remote_path'] if 'remote_path' not in request.form or request.form[ 'remote_path'] == '' else request.form['remote_path'] # 2020-07-23 by soju # server_filename == '' 인 경우가 폴더채다운로드. server_filename 파일명이 있다면 이미 맞는 remote_path if ModelSetting.get_bool('av_sub_library_match') and arg[ 'mode'] == 'download' and arg['server_filename'] == '': arg['defalut_remote_path'] = LogicAVSub.get_download_remote_path( arg['folder_name']) return render_template( '{package_name}_{sub}_{sub2}.html'.format( package_name=package_name, sub=sub, sub2=sub2), arg=arg) elif sub2 == 'plex': return render_template( '{package_name}_{sub}_{sub2}.html'.format( package_name=package_name, sub=sub, sub2=sub2), arg=arg) elif sub == 'user': arg['sub'] = sub if sub2 == 'setting': return render_template( '{package_name}_{sub}_{sub2}.html'.format( package_name=package_name, sub=sub, sub2=sub2), arg=arg) elif sub2 == 'upload': return render_template( '{package_name}_{sub}_{sub2}.html'.format( package_name=package_name, sub=sub, sub2=sub2), arg=arg) elif sub2 == 'list': return render_template( '{package_name}_{sub}_{sub2}.html'.format( package_name=package_name, sub=sub, sub2=sub2), arg=arg) return render_template('sample.html', title='%s - %s' % (package_name, sub)) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def find_by_filename_part(keyword): try: query = "SELECT metadata_items.id, media_items.id, file, media_items.duration, media_items.bitrate, media_parts.created_at, media_items.size, media_items.width, media_items.height, media_items.video_codec, media_items.audio_codec FROM media_parts, media_items, metadata_items WHERE media_parts.media_item_id = media_items.id and media_items.metadata_item_id = metadata_items.id and LOWER(media_parts.file) LIKE '%{keyword}%' and media_items.width > 0 ORDER BY media_items.bitrate DESC".format(keyword=keyword) url = '%s/:/plugins/com.plexapp.plugins.SJVA/function/db_query?query=%s&X-Plex-Token=%s' % (ModelSetting.get('server_url'), py_urllib.quote(query.encode('utf8')), ModelSetting.get('server_token')) data1 = requests.get(url).json() query = "SELECT metadata_items.id, media_items.id, file, media_streams.url FROM media_parts, media_items, metadata_items, media_streams WHERE media_streams.media_item_id = media_items.id and media_parts.media_item_id = media_items.id and media_items.metadata_item_id = metadata_items.id and media_streams.stream_type_id = 3 and media_parts.file LIKE '%{keyword}%' ORDER BY media_items.bitrate DESC".format(keyword=keyword) url = '%s/:/plugins/com.plexapp.plugins.SJVA/function/db_query?query=%s&X-Plex-Token=%s' % (ModelSetting.get('server_url'), py_urllib.quote(query.encode('utf8')), ModelSetting.get('server_token')) data2 = requests.get(url).json() #logger.debug(data2) #logger.debug(data1) ret = {'ret' : True} ret['list'] = [] ret['metadata_id'] = [] for tmp in data1['data']: if tmp == '': continue tmp = tmp.split('|') item = {} item['metadata_id'] = '/library/metadata/%s' % tmp[0] item['media_id'] = tmp[1] item['filepath'] = tmp[2] item['filename'] = tmp[2] lastindex = 0 if tmp[2][0] == '/': lastindex = tmp[2].rfind('/') else: lastindex = tmp[2].rfind('\\') item['dir'] = tmp[2][:lastindex] item['filename'] = tmp[2][lastindex+1:] item['duration'] = int(tmp[3]) item['bitrate'] = int(tmp[4]) item['created_at'] = tmp[5] item['size'] = int(tmp[6]) item['size_str'] = Util.sizeof_fmt(item['size'], suffix='B') item['width'] = int(tmp[7]) item['height'] = int(tmp[8]) item['video_codec'] = tmp[9] item['audio_codec'] = tmp[10] ret['list'].append(item) if item['metadata_id'] not in ret['metadata_id']: ret['metadata_id'].append(item['metadata_id']) for tmp in data2['data']: if tmp == '': continue tmp = tmp.split('|') for item in ret['list']: if item['media_id'] == tmp[1] and item['filepath'] == tmp[2]: item['sub'] = tmp[3] break logger.debug(ret) return ret except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) return None