导入 TEASOFT

Posted 卓晴

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了导入 TEASOFT相关的知识,希望对你有一定的参考价值。

视频脚本 目 录
Contents
视频脚本文件格式 Python 程序 总 结

 

01 频脚本


在 CSDN 中编写的视频脚本文件,在导入 TEASOFT 的过程中,现在还需要一节一节进行手工导入,极大限制导入速度。现在编写 Python 程序实现一键 CSDN 视频脚本文件导入 TEASOFT 的功能。

一、视频脚本文件格式

根据 CSDN 视频脚本文件的以下格式定义,先将 脚本文件对应的 Markdown 内容进行分割,对于能够导入的内容提炼出来。然后在利用 DOPASTE Python 脚本文件导入 TEASOFT 软件。 脚本视频文件的格式:

  1. 分别所有一级、二级、三级级标题之内的内容;
  2. 对于每一段之间,判断是否存在如下 Markdown 文档标致:
    • 具有 &thinsp 或者 “”、“【】” 等表示符
    • 具有 #pic_left 表示。
      对于每一段分割之后,在调用 “dopaste” 软件通过 clipboard 进行内容传送。

二、Python 程序

导入软件为 “CSDN2DOP”。

1、Python代码

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# CSDN2DOP.PY                  -- by Dr. ZhuoQing 2022-10-01
#
# Note:
#============================================================

from head import *

csdn_title = '写文章-CSDN博客'

#------------------------------------------------------------
tspsendwindowkey(csdn_title, " ", noreturn=1)
tspsendwindowkey(csdn_title, "ac", control=1,noreturn=1)
strall = clipboard.paste()
tspsendwindowkey(csdn_title, "z", control=1)


#------------------------------------------------------------
segdim = []
tempdim = []

strdim = strall.split('\\n')

#------------------------------------------------------------
def titlestring(s):
    if s[:1] != '#':    return 0
    ss = s.split(' ')
    if len(ss) < 2:     return 0
    if ss[0] == '#':    return 1
    if ss[0] == '##':   return 2
    if ss[0] == '###':  return 3
    if ss[0] == '####': return 4
    if ss[0] == '#####':  return 5
    if ss[0] == '######': return 6

    return 0

def spaceofflen(s):
    return len(s.replace(' ','').replace('\\n', '').replace('\\r',''))

def stringflag(s):
    if s.find('&thinsp;') >= 0: return 1
    if s.find('&thinsp;') >= 0:     return 1
    if s.find('【】') >= 0:     return 1
 &emsp;&emsp;if s.find('#pic_left') >= 0: return 1
return 0

#------------------------------------------------------------
addflag = 0
for s in strdim:
    if spaceofflen(s) == 0: continue

    sharpnum = titlestring(s)
    if sharpnum == 1:
        if len(tempdim) > 1:
            segdim.append(tempdim)

        tempdim = []
        addflag = 1
        tempdim.append(s)
        continue

    if sharpnum == 2:
        if len(tempdim) > 1:
            segdim.append(tempdim)

        tempdim = []
        addflag = 2
        tempdim.append(s)
        continue

    if sharpnum == 3:
        if len(tempdim) < 2 or addflag >= 3:
            if len(tempdim) > 1:
                segdim.append(tempdim)

            tempdim = []
            addflag = 3
            tempdim.append(s)
            continue

    if addflag > 0:
        if stringflag(s):
            tempdim.append(s)


#------------------------------------------------------------
for sd in segdim:
    printf(sd)
    printf('  \\a')

    clipboard.copy('\\n'.join(sd))
    tspexecutepythoncmd('dopaste # *')

    for i in range(20):
        time.sleep(1)
        s = clipboard.paste()
        if s.find('DOPASTE END') >= 0:
            clipboard.copy("")
            break

        tspbeep(2200, 25)


printf('CSDN2DOP END.\\a')


#------------------------------------------------------------
#        END OF FILE : CSDN2DOP.PY
#============================================================

2、DOPASTE

需要对于DOPASTE 软件进行修改。具体代码为:

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# DOPASTE.PY                     -- by Dr. ZhuoQing 2021-10-07
#
#       dopaste <ssss               # 【ssss.zip】
#       dopaste =ssss               # 【ssss】
#
# Note:
#============================================================

from head import *
import urllib.request
from PIL                    import Image
from io import BytesIO
import win32clipboard
import requests
import zipfile
import cv2

csdn_title = '写文章-CSDN博客'


#------------------------------------------------------------
outdir = r'd:\\temp'
microvideo_dir = r'd:\\Nutdisk\\MicroVideo'
microvideo_mooc = r'd:\\MooC\\MicroVideo'

MAX_LENGTH = 10
picselflag = 0
FILENAME_LENGTH     = 128

#------------------------------------------------------------

def data82data(data):
    data[data < 0x80] = 0
    data[data != 0] = 1

    datashape = shape(data)
    W = datashape[-1]//8
    H = datashape[0]

    data = data.reshape(size(data))

    bits = array([1,2,4,8,16,32,64,128])
    data = data.reshape(-1, 8) * bits
    data8 = sum(data.T,0).reshape(H,W)

    return data8

#------------------------------------------------------------
def img2databuf(imagefile):
    img = cv2.imread(imagefile)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY).astype(uint8)

    data = data82data(gray).astype(uint8)
    data = data.reshape(size(data)).tobytes()

    datalen = int.from_bytes(data[:4], 'little')
    filename = data[4:4+FILENAME_LENGTH].decode('gbk').strip('\\x00')
    return datalen, filename, data[4+FILENAME_LENGTH:]


def img2datafile(imagefile, datafile):
    datalen, filename, data = img2databuf(imagefile)

    printff(datalen, filename)
    with open(datafile, 'wb') as f:
        f.write(data[:datalen])

    return filename

#------------------------------------------------------------
def extractGIFimage(giffile, outdir):
    try:
        im = Image.open(giffile)
    except IOError:
        printf("Can not load %s ."%infile)
        sys.exit()

    i = 0
    mypalette = im.getpalette()
    firstfile = ''
    basenameonly = os.path.basename(giffile).split('.')[0]
    strid = basenameonly.find('_-')
    if strid > 0: basenameonly = basenameonly[:strid]

    try:
        while True:
            im.putpalette(mypalette)
            new_im = Image.new("RGB", im.size)
            new_im.paste(im)

            savefile = os.path.join(outdir, '%s_%d.JPG'%(basenameonly, i))
            new_im.save(savefile)

            if i == 0: firstfile = savefile
            i += 1
            im.seek(im.tell() + 1)

    except EOFError:
        pass        # end of sequence
                    #


    im.close()
    return firstfile

#------------------------------------------------------------
def str2bsim(s):
    if s.find('![N]') >= 0: return 0
    if s.find('![n]') >= 0: return 0
    if s.find('![O]') >= 0: return 1
    if s.find('![o]') >= 0: return 1
    if s.find('![L]') >= 0: return 2
    if s.find('![l]') >= 0: return 2
    if s.find('![S]') >= 0: return 1
    if s.find('![s]') >= 0: return 1
    if s.find('![A]') >= 0: return 4
    if s.find('![a]') >= 0: return 4
    if s.find('![F]') >= 0: return 4
    if s.find('![f]') >= 0: return 4
    if s.find('![R]') >= 0: return 3
    if s.find('![r]') >= 0: return 3
    if s.find('![P]') >= 0: return 5
    if s.find('![p]') >= 0: return 5
    if s.find('![Q]') >= 0: return 6
    if s.find('![q]') >= 0: return 6
    if s.find('![S]') >= 0: return 7
    if s.find('![s]') >= 0: return 7
    if s.find('![1]') >= 0: return 9
    if s.find('![2]') >= 0: return 10
    if s.find('![3]') >= 0: return 11
    if s.find('![4]') >= 0: return 12
    if s.find('![5]') >= 0: return 13
    if s.find('![6]') >= 0: return 14
    if s.find('![7]') >= 0: return 15
    if s.find('![8]') >= 0: return 16
    if s.find('![9]') >= 0: return 17
    if s.find('![0]') >= 0: return 18

    return -1

#------------------------------------------------------------
def extractMPGimage(mpegfile, outdir):
    fnonly = os.path.basename(mpegfile).split('.')[0]
    cam = cv2.VideoCapture(mpegfile)
    printf(mpegfile)
    currentframe = 0

    while True:
        ret, frame = cam.read()

        if ret:
            filename = '%s_%04d.JPG'%(fnonly, currentframe)
            outfile = os.path.join(outdir, filename)

            cv2.imwrite(outfile, frame)
            currentframe += 1
        else:
            break

    cam.release()

    return fnonly

#------------------------------------------------------------
def send_to_clipboard(clip_type, data):
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardData(clip_type, data)
    win32clipboard.CloseClipboard()

def image2clipboard(filename):
    image = Image.open(filename)
    output = BytesIO()
    image.convert('RGB').save(output, 'BMP')
    data = output.getvalue()[14:]
    output.close()
    send_to_clipboard(win32clipboard.CF_DIB, data)

#------------------------------------------------------------
def zip2dir(filename, dirs):
    dopfile = ''
    basedir = ''
    bsirfilename = ''


    with以上是关于导入 TEASOFT的主要内容,如果未能解决你的问题,请参考以下文章

Font

font-family 字体

导入 TEASOFT

font-style字体设置

CSS,font-family,好看常用的中文字体

Python常用中文字体对应名称