TA的每日心情 | 开心 2019-4-4 17:54 |
---|
签到天数: 2 天 [LV.1]初来乍到
星辰大海
- 积分
- 477288
|
本帖最后由 NoobNeo 于 2019-4-26 07:42 编辑
附上源码
python要3.0及以上
代码简单注释了一下, 楼主想要批量处理的话, 自己再稍微改造下吧
- # -*- coding: UTF-8 -*-
- import codecs
- import json
- import requests
- # 字幕保存路径, {}用于替换文件名
- format_path = 'D:/youtube-dl/{}.ass'
- # song_pk: 歌曲PK
- def api(song_pk):
- # 样式名修改的话这里也要修改
- format_ass = 'Dialogue: 0,{},{},Jp,,0,0,0,,{}\r\n'
- format_tr_ass = 'Dialogue: 0,{},{},Tr,,0,0,0,,{}\r\n'
- user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36'
- referer = 'https://www.jpmarumaru.com/tw/JPSongPlay-' + str(song_pk) + '.html'
- api_url = 'https://www.jpmarumaru.com/tw/api/json_JPSongTrack.asp'
- song_data = 'SongPK=' + str(song_pk)
- # api headers
- headers = {
- 'Connection': 'Keep-alive',
- 'User-Agent': user_agent,
- 'Referer': referer,
- 'Origin': 'https://www.jpmarumaru.com',
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
- }
- req = requests.post(api_url, headers=headers, data=song_data)
- js = json.loads(req.text)
- ass_file = codecs.open(format_path.format(js['Name']), 'w', 'utf-8')
- # ass Header
- ass_file.write('[Script Info]\r\n'
- '; Script generated by Aegisub 3.2.2\r\n'
- '; http://www.aegisub.org/\r\n'
- 'Title: Default Aegisub file\r\n'
- 'ScriptType: v4.00+\r\n'
- 'WrapStyle: 0\r\n'
- 'ScaledBorderAndShadow: yes\r\n'
- 'YCbCr Matrix: None\r\n'
- '[V4+ Styles]\r\n'
- 'Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\r\n'
- # 日文样式
- 'Style: Jp,Noto Sans CJK SC Medium,36,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,2,10,10,20,1\r\n'
- # 译文样式
- 'Style: Tr,Noto Sans CJK SC Medium,36,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,8,10,10,20,1\r\n'
- # 注音样式
- 'Style: TEXT_JP-furigana,Noto Sans CJK SC Medium,36,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,8,10,10,20,1\r\n'
- '[Events]\r\n'
- 'Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\r\n')
- start_time = js['StartTime']
- end_time = js['EndTime']
- ass_yomi = []
- ass_tr = js['Translate_zh']
- for i in js['LyricsYomi']:
- ass_yomi.append(i.replace('<ruby><rb>', '(').replace('</rb><rt>', ',').replace('</rt></ruby>', ')'))
- # 先写入日文歌词, 方便后期自动化时选定
- for index in range(0, len(ass_yomi)):
- ass_file.write(format_ass.format(start_time[index], end_time[index], ass_yomi[index]))
- # 再写入译文歌词, 不需要的话注解掉
- for index in range(0, len(ass_tr)):
- ass_file.write(format_tr_ass.format(start_time[index], end_time[index], ass_tr[index]))
- ass_file.close()
- # Demo
- api(642)
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|