예제 #1
0
	def rmdir(dir):
		return os_rmdir(dir)
예제 #2
0
async def func(filepath: str, client: Client, message: Message, delete=False):
    if not os_path.exists(filepath):
        LOGGER.error(f'File not found : {filepath}')
        await message.edit_text(
            LOCAL.UPLOAD_FAILED_FILE_MISSING.format(
                name=os_path.basename(filepath)))
        return

    if os_path.isdir(filepath):
        ls = os_lisdir(filepath)
        async for filepath in ls:
            await message.edit(
                LOCAL.UPLOADING_FILE.format(name=os_path.basename(filepath)))
            await func(filepath, message, delete)
        if delete:
            os_rmdir(filepath)
        return

    video = ['.mp4', '.mkv', '.avi', '.webm', '.wmv', '.mov']
    photo = ['.jpg', '.jpeg', '.png']

    file_ext = os_path.splitext(filepath)[1].lower()
    LOGGER.debug(f'Uploading : {filepath}')

    if STATUS.UPLOAD_AS_DOC:
        upload_fn = client.send_document
    elif file_ext in photo:
        upload_fn = client.send_photo
    elif file_ext in video:

        async def upload_fn(chat_id, file, **kwargs):
            probe = await ffprobe.func(file.path)

            duration = int(float(probe["format"]["duration"]))

            video_stream = next((stream for stream in probe['streams']
                                 if stream['codec_type'] == 'video'), None)
            width = int(video_stream['width'] if 'width' in
                        video_stream else 0)
            height = int(video_stream['height'] if 'height' in
                         video_stream else 0)

            await message.edit(LOCAL.GENERATE_THUMBNAIL.format(name=file.name))
            thumb_image_path = CONFIG.DOWNLOAD_LOCATION + "/" + str(
                update.from_user.id) + ".jpg"

        if not os.path.exists(thumb_image_path):
            mes = await thumb(update.from_user.id)
            if mes != None:
                m = await bot.get_messages(update.chat.id, mes.msg_id)
                await m.download(file_name=thumb_image_path)
                thumb_image_path = thumb_image_path
            else:
                if "thumbnail" in response_json:
                    if response_json["thumbnail"] is not None:
                        thumbnail = response_json["thumbnail"]
                        thumbnail_image = response_json["thumbnail"]
                thumb_image_path = DownLoadFile(
                    thumbnail_image,
                    CONFIG.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) +
                    ".jpg",
                    CONFIG.CHUNK_SIZE,
                    None,  # bot,
                    LOCAL.DOWNLOAD_START,
                    update.message_id,
                    update.chat.id)
            await client.send_video(chat_id,
                                    file,
                                    supports_streaming=True,
                                    thumb=thumb_image_path,
                                    height=height,
                                    width=width,
                                    duration=duration,
                                    **kwargs)
            if not use_default_thumbnail:
                os_remove(str(thumbnail))
    else:
        upload_fn = client.send_document

    if os_path.getsize(filepath) > int(CONFIG.UPLOAD_MAX_SIZE):
        LOGGER.debug(f'File too large : {filepath}')
        await message.edit_text(
            LOCAL.SPLIT_FILE.format(name=os_path.basename(filepath)))

    async for file in split.func(filepath, int(CONFIG.UPLOAD_MAX_SIZE)):
        await message.edit(LOCAL.UPLOADING_FILE.format(name=file.name))

        info = {
            "time": time(),
            "name": file.name,
            "last_update": 0,
            "prev_text": ""
        }
        await upload_fn(message.chat.id,
                        file,
                        disable_notification=True,
                        progress=progress_upload_tg,
                        progress_args=(message, info),
                        caption=f'<code>{file.name}</code>')
        LOGGER.debug(f'Uploaded : {file.name}')
    if delete:
        os_remove(filepath)
예제 #3
0
async def func(filepath: str, client: Client, message: Message, delete=False):
    if not os_path.exists(filepath):
        LOGGER.error(f'File not found : {filepath}')
        await message.edit_text(
            LOCAL.UPLOAD_FAILED_FILE_MISSING.format(
                name=os_path.basename(filepath)))
        return

    if os_path.isdir(filepath):
        ls = os_lisdir(filepath)
        async for filepath in ls:
            await message.edit(
                LOCAL.UPLOADING_FILE.format(name=os_path.basename(filepath)))
            await func(filepath, message, delete)
        if delete:
            os_rmdir(filepath)
        return

    video = ['.mp4', '.mkv', '.avi', '.webm', '.wmv', '.mov']
    photo = ['.jpg', '.jpeg', '.png']

    file_ext = os_path.splitext(filepath)[1].lower()
    LOGGER.debug(f'Uploading : {filepath}')

    if STATUS.UPLOAD_AS_DOC:
        upload_fn = client.send_document
    elif file_ext in photo:
        upload_fn = client.send_photo
    elif file_ext in video:

        async def upload_fn(chat_id, file, **kwargs):
            probe = await ffprobe.func(file.path)

            duration = int(float(probe["format"]["duration"]))

            video_stream = next((stream for stream in probe['streams']
                                 if stream['codec_type'] == 'video'), None)
            width = int(video_stream['width'] if 'width' in
                        video_stream else 0)
            height = int(video_stream['height'] if 'height' in
                         video_stream else 0)

            await message.edit(LOCAL.GENERATE_THUMBNAIL.format(name=file.name))
            thumbnail = os_path.join(CONFIG.ROOT, CONFIG.WORKDIR,
                                     CONFIG.THUMBNAIL_NAME)
            use_default_thumbnail = os_path.exists(thumbnail)
            if not use_default_thumbnail:
                thumbnail = await thumbnail_video.func(file.path)
            await client.send_video(chat_id,
                                    file,
                                    supports_streaming=True,
                                    thumb=str(thumbnail),
                                    height=height,
                                    width=width,
                                    duration=duration,
                                    **kwargs)
            if not use_default_thumbnail:
                os_remove(str(thumbnail))
    else:
        upload_fn = client.send_document

    if os_path.getsize(filepath) > int(CONFIG.UPLOAD_MAX_SIZE):
        LOGGER.debug(f'File too large : {filepath}')
        await message.edit_text(
            LOCAL.SPLIT_FILE.format(name=os_path.basename(filepath)))

    async for file in split.func(filepath, int(CONFIG.UPLOAD_MAX_SIZE)):
        await message.edit(LOCAL.UPLOADING_FILE.format(name=file.name))

        info = {
            "time": time(),
            "name": file.name,
            "last_update": 0,
            "prev_text": ""
        }
        await upload_fn(message.chat.id,
                        file,
                        disable_notification=True,
                        progress=progress_upload_tg,
                        progress_args=(message, info),
                        caption=f'<code>{file.name}</code>')
        LOGGER.debug(f'Uploaded : {file.name}')
    if delete:
        os_remove(filepath)
예제 #4
0
                        )  # os_path.join(nameD, os_path.splitext(nameFE0)[0] + '.0000')
                        subprocess.call(runString)
                    else:
                        s = raw_input('File "' + nameFull0 +
                                      '" will be overwrited! Continue?')
                        if 'n' in s or 'N' in s:
                            print('not all joined')
                            exit
                        else:
                            print('continue...')

            print('making archive of replaced files...')
            nameFull0 = make_archive(dst, 'zip', dst)
            if nameFull0 == dst + '.zip':  # think that all archived Ok, so delete source
                for inameSt, inameEn in range_of_files_with_inc_ext(paths):
                    for nameFull in paths[inameSt:inameEn]:
                        os_remove(os_path.join(dst,
                                               os_path.basename(nameFull)))
                try:
                    os_rmdir(dst)
                except WindowsError:
                    print('can not remove directory ' + nameSourceArchive)
            print('ok')  # end

##remove unused characters
# compile_obj = re.compile(rawstr,  re.MULTILINE| re.VERBOSE)
# with open(fileNames, 'r') as f:  matchstr = f.read()
# console.write(compile_obj.sub(repstr, matchstr))

# matchstr= compile_obj.findall(matchstr)