Skip to content

Commit a842c6a

Browse files
author
yuanjun_liu
committed
first commit
0 parents  commit a842c6a

22 files changed

+803
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
.idea/
3+
*.iml

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# kindle note project
2+
3+
## 目的
4+
该软件的产生灵感:主要来自个人长期使用 kindle 却无法导出辛辛苦苦做的笔记;
5+
6+
目的:开发该软件以帮助那些需要导出 kindle 笔记的朋友。
7+
8+
## 使用方式
9+
1. 将 kindle 中的 `My Clippings.txt` 文件拷贝到 `下载` 目录下;
10+
2. 执行该软件,软件会到 `下载` 目录下去搜索 `My Clippings.txt` 文件;
11+
3. 在应用程序界面选择一个书名,进行笔记生成;
12+
4. 生成的笔记文件会直接放在 `下载` 目录下。
13+
14+
## 体验方式
15+
1. 在 resources 目录下有一份 `My Clippings.txt` 文件,将其拷贝到 `下载` 目录下;
16+
2. 按照[使用方式](#使用方式)的步骤操作即可。
17+
18+
## 待办
19+
1. - [x] 文件解析成 Java 对象
20+
2. - [x] Java 对象生成 Markdown 笔记文件
21+
3. - [ ] Markdown 转 Word/PDF
22+
4. - [ ] 增加 log 模块
23+
5. - [ ] 增加 release:exe 应用程序,支持 Windows
24+
6. - [ ] 增加 release:dmg 应用程序,支持 Mac
25+
26+
## 后记
27+
如果有帮助到您,是我的荣幸!
28+
如果有任何建议/问题,欢迎提 issue !

pom.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.eugene</groupId>
8+
<artifactId>kindle_note</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>8</maven.compiler.source>
13+
<maven.compiler.target>8</maven.compiler.target>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>junit</groupId>
19+
<artifactId>junit</artifactId>
20+
<version>4.13.2</version>
21+
<scope>test</scope>
22+
</dependency>
23+
</dependencies>
24+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.eugene.kindle;
2+
3+
import com.eugene.kindle.service.impl.ConvertServiceImpl;
4+
import com.eugene.kindle.service.impl.NoteServiceImpl;
5+
import com.eugene.kindle.utils.NoteConfig;
6+
import java.util.List;
7+
import java.util.Scanner;
8+
9+
/**
10+
* 主程序入口
11+
*
12+
* @author EUGENE
13+
* @version 1.0.0
14+
* @since 2022/8/1
15+
*/
16+
public class Application {
17+
18+
private static final String TIPS = "1. A: 显示所有书的列表;"
19+
+ "\n2. [num]: 列表的前面数字输出笔记;"
20+
+ "\n3. h: 输出提示";
21+
22+
public static void main(String[] args) {
23+
System.out.println("===请将文件'My Clippings.txt'放在'下载'目录下===");
24+
System.out.println(TIPS);
25+
try {
26+
exec();
27+
} catch (Exception exception) {
28+
System.out.println(exception.getMessage());
29+
exec();
30+
}
31+
}
32+
33+
private static void exec() {
34+
ConvertServiceImpl convertService = new ConvertServiceImpl();
35+
NoteServiceImpl noteService = new NoteServiceImpl();
36+
while (true) {
37+
Scanner scanner = new Scanner(System.in);
38+
String param = scanner.nextLine();
39+
switch (param) {
40+
case "h":
41+
System.out.println(TIPS);
42+
break;
43+
case "A":
44+
List<String> bookNames = convertService
45+
.getBookNames(NoteConfig.getSourcePath());
46+
for (int i = 1; i <= bookNames.size(); i++) {
47+
System.out.printf("%s: %s%n", i, bookNames.get(i - 1));
48+
}
49+
break;
50+
default:
51+
noteService.createNoteByIndex(Integer.parseInt(param));
52+
break;
53+
}
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.eugene.kindle.bean;
2+
3+
import com.eugene.kindle.constant.NoteType;
4+
import java.time.LocalDateTime;
5+
6+
/**
7+
* 笔记对象
8+
*
9+
* @author EUGENE
10+
* @version 1.0.0
11+
* @since 2022/7/29
12+
*/
13+
public class Note {
14+
15+
private String name;
16+
private float location;
17+
private NoteType type;
18+
private LocalDateTime dateTime;
19+
private String content;
20+
21+
public String getName() {
22+
return name;
23+
}
24+
25+
public void setName(String name) {
26+
this.name = name;
27+
}
28+
29+
public float getLocation() {
30+
return location;
31+
}
32+
33+
public void setLocation(float location) {
34+
this.location = location;
35+
}
36+
37+
public NoteType getType() {
38+
return type;
39+
}
40+
41+
public void setType(NoteType type) {
42+
this.type = type;
43+
}
44+
45+
public LocalDateTime getDateTime() {
46+
return dateTime;
47+
}
48+
49+
public void setDateTime(LocalDateTime dateTime) {
50+
this.dateTime = dateTime;
51+
}
52+
53+
public String getContent() {
54+
return content;
55+
}
56+
57+
public void setContent(String content) {
58+
this.content = content;
59+
}
60+
61+
@Override
62+
public String toString() {
63+
return String.format("%s#%s#%s#%s#%s", this.name, this.location, this.type.getName(),
64+
this.dateTime, this.content);
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.eugene.kindle.constant;
2+
3+
/**
4+
* 笔记类型
5+
*
6+
* @author EUGENE
7+
* @version 1.0.0
8+
* @since 2022/7/29
9+
*/
10+
public enum NoteType {
11+
CALLOUT("标注", 1),
12+
NOTE("笔记", 2),
13+
UNKNOWN("未知", 3);
14+
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public int getType() {
20+
return type;
21+
}
22+
23+
private final String name;
24+
private final int type;
25+
26+
NoteType(String name, int type) {
27+
this.name = name;
28+
this.type = type;
29+
}
30+
31+
public static NoteType fromVal(String name) {
32+
for (NoteType value : NoteType.values()) {
33+
if (value.name.equals(name)) {
34+
return value;
35+
}
36+
}
37+
return UNKNOWN;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.eugene.kindle.service;
2+
3+
import com.eugene.kindle.bean.Note;
4+
import java.util.List;
5+
6+
/**
7+
* 笔记转换服务
8+
*
9+
* @author EUGENE
10+
* @version 1.0.0
11+
* @since 2022/7/29
12+
*/
13+
public interface IConvertService {
14+
15+
List<Note> getNotes(String path, String bookName);
16+
17+
List<String> getBookNames(String path);
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.eugene.kindle.service;
2+
3+
import com.eugene.kindle.bean.Note;
4+
import java.util.List;
5+
6+
/**
7+
* 创建笔记
8+
*
9+
* @author EUGENE
10+
* @version 1.0.0
11+
* @since 2022/7/29
12+
*/
13+
public interface INoteService {
14+
15+
/**
16+
* 生成 Markdown 笔记文件
17+
*
18+
* @param notes 笔记对象
19+
*/
20+
void createMarkDownNote(List<Note> notes);
21+
22+
/**
23+
* 通过索引创建笔记
24+
*/
25+
void createNoteByIndex(int index);
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.eugene.kindle.service.impl;
2+
3+
import com.eugene.kindle.constant.NoteType;
4+
import com.eugene.kindle.bean.Note;
5+
import com.eugene.kindle.service.IConvertService;
6+
import com.eugene.kindle.utils.DateFormatter;
7+
import com.eugene.kindle.utils.DateUtils;
8+
import com.eugene.kindle.utils.FileUtils;
9+
import java.time.LocalDateTime;
10+
import java.util.ArrayList;
11+
import java.util.HashSet;
12+
import java.util.List;
13+
import java.util.Set;
14+
15+
public class ConvertServiceImpl implements IConvertService {
16+
17+
@Override
18+
public List<Note> getNotes(String path, String bookName) {
19+
List<String> lines = FileUtils.readLine(path);
20+
List<Note> result = new ArrayList<>();
21+
for (int i = 1; i <= lines.size(); i = i + 5) {
22+
// 书名不匹配
23+
if (!lines.get(i - 1).equals(bookName)) {
24+
continue;
25+
}
26+
Note note = new Note();
27+
note.setName(lines.get(i - 1));
28+
setNodeInfo(note, lines.get(i));
29+
note.setContent(lines.get(i + 2));
30+
result.add(note);
31+
}
32+
return result;
33+
}
34+
35+
/**
36+
* 翻译标注的位置、时间行
37+
*
38+
* @param line - 您在位置 #1877-1878的标注 | 添加于 2022年5月30日星期一 下午6:19:37
39+
*/
40+
private void setNodeInfo(Note node, String line) {
41+
// System.out.println(line);
42+
if (!line.startsWith("-")) {
43+
return;
44+
}
45+
String[] split = line.replaceFirst("-", "").trim().split("\\|");
46+
// 0:您在位置 #1877-1878的标注
47+
// 1:添加于 2022年5月30日星期一 下午6:19:37
48+
String locationAndType = split[0].replace("您在位置 #", "").trim();
49+
// 1877-1878的标注
50+
String[] local = locationAndType.split("的");
51+
int location = Integer.parseInt(local[0].split("-")[0].trim())
52+
+ Integer.parseInt(local[0].split("-")[0].trim());
53+
node.setLocation((float) location / 2);
54+
node.setType(NoteType.fromVal(local[1].trim()));
55+
String dateTimeStr = split[1].replace("添加于", "").trim();
56+
// 2022年5月30日星期一 下午6:19:37
57+
dateTimeStr = DateUtils.makeUpZero(dateTimeStr);
58+
LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, DateFormatter.RFC_1123_DATE_TIME);
59+
node.setDateTime(dateTime);
60+
}
61+
62+
@Override
63+
public List<String> getBookNames(String path) {
64+
List<String> lines = FileUtils.readLine(path);
65+
Set<String> names = new HashSet<>();
66+
for (int i = 1; i <= lines.size(); i = i + 5) {
67+
names.add(lines.get(i - 1));
68+
}
69+
return new ArrayList<>(names);
70+
}
71+
}

0 commit comments

Comments
 (0)