Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ pnpm-lock.yaml
test/*
Videos/*
settings-production.toml
startRecord-production.sh
src/utils/cookies.json
startRecord-production.sh
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,4 @@ cookies.json
src/subtitle/models/base.pt
src/subtitle/models/small.pt
src/burn/mergevideo.txt
src/upload/upload.yaml
src/upload/uploadVideoQueue.txt
src/db/data.db
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "src/autoslice/auto_slice_video"]
path = src/autoslice/auto_slice_video
url = https://github.com/timerring/auto-slice-video.git
[submodule "src/upload/bilitool"]
path = src/upload/bilitool
url = https://github.com/timerring/bilitool.git
11 changes: 2 additions & 9 deletions src/burn/render_then_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from src.upload.extract_video_info import get_video_info
from src.log.logger import scan_log
from db.conn import insert_upload_queue
from src.upload.generate_yaml import generate_yaml_template
from uuid import uuid4

def normalize_video_path(filepath):
"""Normalize the video path to upload
Expand Down Expand Up @@ -92,11 +90,6 @@ def render_then_merge(video_path_list):

merge_command(output_video_path, title, artist, date, merge_list)
subprocess.run(['rm', '-r', tmp])

yaml_template = generate_yaml_template(output_video_path)
template_path = os.path.join(VIDEOS_DIR, f'upload_conf/{uuid4()}.yaml')
with open(template_path, 'w', encoding='utf-8') as f:
f.write(yaml_template)

if not insert_upload_queue(output_video_path, template_path):
scan_log('插入待上传条目失败')
if not insert_upload_queue(output_video_path):
scan_log.error('Cannot insert the video to the upload queue')
20 changes: 4 additions & 16 deletions src/burn/render_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
from src.upload.extract_video_info import get_video_info
from src.log.logger import scan_log
from db.conn import insert_upload_queue
from src.upload.generate_yaml import generate_yaml_template, generate_slice_yaml_template
from uuid import uuid4

def normalize_video_path(filepath):
"""Normalize the video path to upload
Expand Down Expand Up @@ -72,13 +70,8 @@ def render_video(video_path):
slice_video_flv_path = slice_path[:-4] + '.flv'
inject_metadata(slice_path, glm_title, slice_video_flv_path)
os.remove(slice_path)
slice_yaml_template = generate_slice_yaml_template(slice_video_flv_path)
slice_template_path = os.path.join(VIDEOS_DIR, f'upload_conf/{uuid4()}.yaml')
with open(slice_template_path, 'w', encoding='utf-8') as f:
f.write(slice_yaml_template)

if not insert_upload_queue(slice_video_flv_path, slice_template_path):
scan_log('插入待上传条目失败')
if not insert_upload_queue(slice_video_flv_path):
scan_log.error('Cannot insert the video to the upload queue')
except Exception as e:
scan_log.error(f"Error in {slice_path}: {e}")

Expand All @@ -91,10 +84,5 @@ def render_video(video_path):
# test_path = original_video_path[:-4]
# os.rename(original_video_path, test_path)

yaml_template = generate_yaml_template(format_video_path)
template_path = os.path.join(VIDEOS_DIR, f'upload_conf/{uuid4()}.yaml')
with open(template_path, 'w', encoding='utf-8') as f:
f.write(yaml_template)

if not insert_upload_queue(format_video_path, template_path):
scan_log('插入待上传条目失败')
if not insert_upload_queue(format_video_path):
scan_log.error('Cannot insert the video to the upload queue')
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


if not os.path.exists(SRC_DIR + '/db/data.db'):
print("初始化数据库")
print("Initialize the database")
create_table()

if not os.path.exists(VIDEOS_DIR):
Expand Down
33 changes: 23 additions & 10 deletions src/db/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create_table():
db = connect()
cursor = db.cursor()
sql = [
"create table upload_queue (id integer primary key autoincrement, video_path text, config_path text, locked integer default 0);",
"create table upload_queue (id integer primary key autoincrement, video_path text, locked integer default 0);",
"create unique index idx_video_path on upload_queue(video_path);",
]
for s in sql:
Expand All @@ -28,17 +28,26 @@ def create_table():
def get_single_upload_queue():
db = connect()
cursor = db.cursor()
cursor.execute("select video_path, config_path from upload_queue where locked = 0 limit 1;")
cursor.execute("select video_path from upload_queue where locked = 0 limit 1;")
row = cursor.fetchone()
result = {'video_path': row[0], 'config_path': row[1]} if row else None
result = {'video_path': row[0]} if row else None
db.close()
return result

def insert_upload_queue(video_path: str, config_path: str):
def get_all_upload_queue():
db = connect()
cursor = db.cursor()
cursor.execute("select video_path from upload_queue;")
rows = cursor.fetchall()
result = [{'video_path': row[0]} for row in rows]
db.close()
return result

def insert_upload_queue(video_path: str):
try:
db = connect()
cursor = db.cursor()
cursor.execute("insert into upload_queue (video_path, config_path) values (?, ?);", (video_path, config_path))
cursor.execute("insert into upload_queue (video_path) values (?);", (video_path,))
db.commit()
db.close()
return True
Expand Down Expand Up @@ -76,12 +85,16 @@ def update_upload_queue_lock(video_path: str, locked: int):
# Create Table
create_table()
# Insert Test Data
insert_upload_queue('test.mp4', 'config.yaml')
insert_upload_queue('')
# Insert again to check the unique index
print(insert_upload_queue('test.mp4', 'config.yaml'))
# Get the single upload queue, shold be {'video_path': 'test.mp4', 'config_path': 'config.yaml'}
print(get_single_upload_queue())
# print(insert_upload_queue(''))
# Get the single upload queue, shold be {'video_path': 'test.mp4'}
# print(get_single_upload_queue())
# Get all upload queue
print(get_all_upload_queue())
# unlock the upload queue
update_upload_queue_lock('test.mp4', 0)
# Delete the upload queue
delete_upload_queue('test.mp4')
delete_upload_queue('')
# Get the single upload queue after delete, should be None
print(get_single_upload_queue())
5 changes: 4 additions & 1 deletion src/upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from .bilitool.bilitool import UploadController, FeedController

__all__ = ['UploadController', 'FeedController']
1 change: 1 addition & 0 deletions src/upload/bilitool
Submodule bilitool added at facd69
46 changes: 27 additions & 19 deletions src/upload/extract_video_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import datetime
from src.upload.query_search_suggestion import get_bilibili_suggestions
from src.config import GPU_EXIST, TITLE, DESC
from src.log.logger import upload_log

def get_video_info(video_file_path):
"""get the title, artist and date of the video file via ffprobe
Expand All @@ -15,28 +16,35 @@ def get_video_info(video_file_path):
Returns:
str: the title of the video file, if failed, return None
"""

command = [
"ffprobe",
"-v", "quiet",
"-print_format", "json",
"-show_format",
video_file_path
]
output = subprocess.check_output(command, stderr=subprocess.STDOUT).decode('utf-8')
parsed_output = json.loads(output)
title_value = parsed_output["format"]["tags"]["title"]
artist_value = parsed_output["format"]["tags"]["artist"]
date_value = parsed_output["format"]["tags"]["date"]
if len(date_value) > 8:
dt = datetime.fromisoformat(date_value)
new_date = dt.strftime('%Y%m%d')
else:
new_date = date_value
return title_value, artist_value, new_date
try:
command = [
"ffprobe",
"-v", "quiet",
"-print_format", "json",
"-show_format",
video_file_path
]
output = subprocess.check_output(command, stderr=subprocess.STDOUT).decode('utf-8')
parsed_output = json.loads(output)
title_value = parsed_output["format"]["tags"]["title"]
artist_value = parsed_output["format"]["tags"]["artist"]
date_value = parsed_output["format"]["tags"]["date"]
if len(date_value) > 8:
dt = datetime.fromisoformat(date_value)
new_date = dt.strftime('%Y%m%d')
else:
new_date = date_value
return title_value, artist_value, new_date
except Exception as e:
# Log the exception if needed
upload_log.error(f"Error occurred in get_video_info: {e}")
return None, None, None

def generate_title(video_path):
title, artist, date = get_video_info(video_path)
if title is None:
upload_log.error(f"Error occurred in generate_title: {title}")
return None
source_link = generate_source(video_path)
prefix = "【弹幕+字幕】" if GPU_EXIST else "【弹幕】"
formatted_title = TITLE.format(artist=artist, date=date, title=title, source_link=source_link)
Expand Down
39 changes: 39 additions & 0 deletions src/upload/generate_upload_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2024 bilive.

import os
import time
import codecs
from datetime import datetime
from src.upload.extract_video_info import generate_title, generate_desc, generate_tag, generate_source
import subprocess
import json

def generate_video_data(video_path):
copyright = 1
title = generate_title(video_path)
desc = generate_desc(video_path)
tid = 138
tag = generate_tag(video_path)
source = generate_source(video_path)
cover = ""
dynamic = ""
return copyright, title, desc, tid, tag, source, cover, dynamic

def generate_slice_data(video_path):
command = [
"ffprobe",
"-v", "quiet",
"-print_format", "json",
"-show_format",
video_path
]
output = subprocess.check_output(command, stderr=subprocess.STDOUT).decode('utf-8')
parsed_output = json.loads(output)
title = parsed_output["format"]["tags"]["generate"]
copyright = 1
tid = 138
tag = "直播切片"
return copyright, title, tid, tag

if __name__ == "__main__":
pass
70 changes: 0 additions & 70 deletions src/upload/generate_yaml.py

This file was deleted.

Loading