Skip to content

Commit

Permalink
add DM switch
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueCitizens committed Mar 25, 2024
1 parent 7c4ceaa commit 56b26fb
Show file tree
Hide file tree
Showing 10 changed files with 483 additions and 198 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@mdui/icons": "^1.0.2",
"axios": "^1.6.7",
"electron-updater": "^6.1.7",
"mdui": "^2.0.3",
"mdui": "^2.0.6",
"python-shell": "^5.0.0",
"vue-clipboard3": "^2.0.0",
"vue-router": "^4.2.5"
Expand Down
Binary file modified src/flask/scripts/__pycache__/bili.cpython-311.pyc
Binary file not shown.
27 changes: 15 additions & 12 deletions src/flask/scripts/bili.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ def convert(val):
outputDir = val['output'] # output video file root

CREATE_UP_DIR = val['isUp'] # 如果需要将同一个up的视频放在单独一个文件夹,则改为True
TRANS_DM = val['isDm']
REMOVE_ORI = val['isDel'] # True if would like to delete origin cache file

logging.info(CREATE_UP_DIR)
logging.info("CREATE_UP_DIR: " + str(CREATE_UP_DIR))
logging.info("TRANS_DM: " + str(TRANS_DM))
logging.info("REMOVE_ORI: " + str(REMOVE_ORI))

# collect failed
failedVideos = []
Expand Down Expand Up @@ -108,13 +111,13 @@ def convert(val):
# videoQualityWidth = row_data.get('page_data', 'no page data').get('width', 'no width')
# videoQualityHeight = row_data.get('page_data', 'no page data').get('height', 'no height')
logging.info("Current resolution: " + str(videoQualityWidth) + '*' + str(videoQualityHeight))
if TRANS_DM:
# 转换后的danmaku.ass在与danmaku.xml同级目录下
danmakuXMLPath = Path(PDir, "danmaku.xml")
danmakuASSPath = Path(PDir, "danmaku.ass")

# 转换后的danmaku.ass在与danmaku.xml同级目录下
danmakuXMLPath = Path(PDir, "danmaku.xml")
danmakuASSPath = Path(PDir, "danmaku.ass")

danmaku2ass.Danmaku2ASS(str(danmakuXMLPath), 'Bilibili', str(danmakuASSPath), videoQualityWidth, videoQualityHeight, 0,
'Microsoft YaHei', 40)
danmaku2ass.Danmaku2ASS(str(danmakuXMLPath), 'Bilibili', str(danmakuASSPath), videoQualityWidth, videoQualityHeight, 0,
'Microsoft YaHei', 40)

for M4SDir in list(filter(Path.is_dir, Path.iterdir(PDir))): # 视频一般放在分p文件夹中的数字文件夹中,一般数字文件夹仅一个
sepPath = M4SDir
Expand Down Expand Up @@ -163,11 +166,11 @@ def convert(val):
logging.info(out.stdout)
Path.rename(filePathOrigin, filePathOutput)
logging.info("Output video: " + str(currentOutputDir))

if Path.exists(danmakuPathOutput):
Path.unlink(danmakuPathOutput)
logging.warning('Ass already exist, but replace it with new one.')
Path.rename(danmakuASSPath, danmakuPathOutput)
if TRANS_DM:
if Path.exists(danmakuPathOutput):
Path.unlink(danmakuPathOutput)
logging.warning('Ass already exist, but replace it with new one.')
Path.rename(danmakuASSPath, danmakuPathOutput)

except Exception as e:
logging.error(e)
Expand Down
33 changes: 30 additions & 3 deletions src/renderer/src/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

body {
display: flex;
align-items: center;
justify-content: center;
/* align-items: center; */
/* justify-content: center; */
overflow: hidden;
background-image: url('./bilibili.svg');
/* background-color: transparent; */
Expand Down Expand Up @@ -35,6 +35,31 @@ code {
margin-bottom: 80px;
}

.index-layout-left {
vertical-align: middle;
height: 100vh;
}

.index-layout-main {
/* min-height: 300px; */
height: 100vh;
width: 100vw;
align-items: center;
justify-content: center;
background-color: hsla(0, 0%, 100%, 0.5);
}

.main-card {
width: 400px;
padding: 20px 20px 20px 20px;
background-color: hsl(0, 0%, 100%);
}

.navi {
position: relative;
height: 100%;
}

.logo {
margin-bottom: 20px;
-webkit-user-drag: none;
Expand Down Expand Up @@ -115,6 +140,7 @@ code {
font-size: 12px;
line-height: 14px;
opacity: 0.8;

&:last-child {
border: none;
}
Expand All @@ -133,8 +159,9 @@ code {
}

@media (max-width: 350px) {

.tip,
.actions {
display: none;
}
}
}
177 changes: 177 additions & 0 deletions src/renderer/src/components/Android.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<template>
<div class="text">
<mdui-card class="main-card">
<mdui-linear-progress :style="this.progress.visible"></mdui-linear-progress>
<mdui-text-field style="margin-bottom: 20px;" v-model="this.form.path" variant="outlined"
label="Cache Directory">
<mdui-button-icon slot="end-icon" @click="triggerPath('path')">
<mdui-icon-attach-file></mdui-icon-attach-file>
</mdui-button-icon>
</mdui-text-field>
<mdui-text-field style="margin-bottom: 20px;" v-model="this.form.output" variant="outlined"
label="Output Directory">
<mdui-button-icon slot="end-icon" @click="triggerPath('output')">
<mdui-icon-attach-file></mdui-icon-attach-file>
</mdui-button-icon>
</mdui-text-field>
<mdui-checkbox ref="checkup" checked>UP主独立文件夹</mdui-checkbox>
<mdui-checkbox ref="checkdm" checked>同时转换弹幕</mdui-checkbox>
<mdui-checkbox ref="checkdel" disabled>删除源</mdui-checkbox>
<mdui-button full-width variant="tonal" :disabled="this.btn" v-on:click="requestConvert">
<mdui-icon-autorenew></mdui-icon-autorenew>
</mdui-button>
</mdui-card>

<mdui-dialog fullscreen class="example-dialog">
<mdui-top-app-bar slot="header">
<mdui-button-icon @click="closeDialog()">
<mdui-icon-close></mdui-icon-close>
</mdui-button-icon>
<mdui-top-app-bar-title>部分成功 以下路径出错</mdui-top-app-bar-title>
<mdui-button variant="text" @click="copyPath(JSON.stringify(failedItems))">复制到剪贴板</mdui-button>
</mdui-top-app-bar>
<mdui-list>
<mdui-list-subheader>点击项目可复制路径</mdui-list-subheader>
<mdui-list-item v-for="item in failedItems" @click="copyPath(item.path)">
{{ item.path }}
<span slot="description">{{ item.error }}</span>
</mdui-list-item>
</mdui-list>

<div class="clipboardInner" @click="copyPath" style="display: inline;"></div>
</mdui-dialog>
<div ref="clipboard" @click="handleCopy" style="display: inline; "></div>
</div>
</template>
<script>
import { onMounted, ref } from 'vue';
import useClipboard from "vue-clipboard3";
import { snackbar } from 'mdui/functions/snackbar.js';
import { getTheme } from 'mdui/functions/getTheme.js';
import { setColorScheme } from 'mdui/functions/setColorScheme.js';
import { hello, convert } from '@renderer/api';
export default {
name: 'android',
setup() {
const clipboard = ref(null)
const { toClipboard } = useClipboard()
const text = ref('')
const handleCopy = async () => {
try {
console.log(text)
await toClipboard(text.value, document.querySelector(".clipboardInner"))
console.log('复制成功')
} catch (e) {
console.error(e);
console.error('复制失败')
}
}
const checkup = ref(null)
const checkdm = ref(null)
const checkdel = ref(null)
onMounted(() => {
})
return {
checkup: checkup,
checkdm: checkdm,
checkdel: checkdel,
clipboard: clipboard,
handleCopy,
text
}
},
data() {
return {
form: {
path: '',
output: '',
isUp: false,
isDm: false,
isDel: false
},
checked: false,
btn: false,
progress: {
visible: 'visibility: hidden',
value: '0'
},
failedItems: [],
clipboardTemp: ''
}
},
methods: {
check() {
if (this.checked === false) {
this.checked = true
}
console.log(this.checked)
},
// 触发主进程 打开文件选择
async triggerPath(val) {
const filePath = await window.electronAPI.openFile()
if (val === 'path') {
this.form.path = filePath
} else if (val === 'output') {
this.form.output = filePath
}
},
requestConvert() {
this.form.isUp = this.checkup.checked
this.form.isDm = this.checkdm.checked
this.form.isDel = this.checkdel.checked
console.log(this.form)
this.btn = true
this.progress.visible = ''
let form = JSON.parse(JSON.stringify(this.form));
convert({ form }).then((response) => {
// console.log(response.data)
// if (response.code === 200) {
// }
let res = response.data
console.log(res[1][0])
if (res[0] === 'true') {
if (res[1].length === 0) {
this.info('转换成功 :)')
} else {
console.log(res[1])
// this.warn(res[1])
this.failedItems = res[1]
const dialog = document.querySelector(".example-dialog")
dialog.open = true
}
} else if (res[0] === 'false') {
this.info('致命错误 请检查日志')
}
this.btn = false
this.progress.visible = 'visibility: hidden'
}).catch((error) => {
console.log(error);
});
},
copyPath(val) {
this.text = val
console.log(this.clipboard)
this.clipboard.click()
},
info(message) {
snackbar({
message: message
});
},
closeDialog() {
const dialog = document.querySelector(".example-dialog")
dialog.open = false
this.failedItems = []
}
},
created() {
setColorScheme('#80DAF6');
},
mounted() {
console.log(getTheme())
}
}
</script>
Loading

0 comments on commit 56b26fb

Please sign in to comment.