Skip to content

Commit 610f4c8

Browse files
committed
alpha testing of 0.6.7 version - audio mp3 fix for android
1 parent 69434df commit 610f4c8

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Added `-lb`option to provide comma delimited labels/tags in the cli for import
66
- Added creation and validation of both the import and import-completed folders on launch
77
- Added `-q` option for quiet/silent mode when importing or exporting notes
8+
- Added `-d` option to remove duplicate tags at the end of notes if already embedded in the note text
9+
- Fixed audio file extension error for Android mp3 audio types vs Apple m4a audio
810
- Cleaned up cli structure
911

1012
## 0.6.6 Release (N/A - reverted)

EXAMPLES.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#### Export all active notes in batch without user prompts
1919
`python kim.py -b --all`
2020

21-
#### Export only notes with the label #science in batch without user prompts
22-
`python kim.py -b "#science"`
21+
#### Export only notes with the label #science and remove duplicate trailing hashtags in batch without user prompts
22+
`python kim.py -d -b "#science"`
2323

2424
#### Export all active notes with silent mode with output to kim.log in batch with create dates after Jan 1, 2023
2525
`python kim.py -q -cd "> 2023-01-01" -b --all`
@@ -61,6 +61,7 @@ Options:
6161
-j Prepend notes with Joplin front matter tags and dates
6262
-m Move any exported Keep notes to Archive
6363
-w Convert pre-formatted markdown note-to-note links to wikilinks
64+
-d Remove any duplicate labels that are already embedded in a note as hashtags
6465
-q Execute exporting or importing in silent mode - output to kim.log
6566
-i Import notes from markdown files WARNING - RATE LIMITS!!
6667
-lb TEXT Comma delimited labels for import - for use with only with (-i) flag

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,18 @@ or
171171
```
172172
will execute KIM without input prompts as long as you have your Google ID in the setting.cfg file and you have stored your Keep access token by running KIM once manually on your device. Be sure the -b flag is the last of all option flags when combining them.
173173

174-
### Silent Mode
174+
#### Silent Mode
175175
KIM can suppress any screen prompts or status messages using the -q flag. Silent or quiet mode will pipe all output to at file called `kim.log` in the install diretory. This is useful for batch mode execution. You must have `settings.cfg` setup with your google id so the user prompt will not display. This works both for exporting and importing:
176176
```bash
177177
> python kim.py -q -b '#mylabel'
178178
```
179179

180+
#### Remove Duplicate Labels/Hashtags
181+
KIM by default appends labels as hashtags at the end of notes. However, Keep can create labels either from the menu or by using hashtags embedded within the note text. KIM can remove any duplicate tags at the end of exported notes using the -d flag. This will allow in-line tags in notes so that apps like Obsidian and Logseq won't have duplicates appended:
182+
```bash
183+
> python kim.py -d
184+
```
185+
180186
#### Archive Notes
181187
KIM has an option to export only Keep archive notes. All other note types are ignored with this option
182188
```bash
@@ -213,9 +219,9 @@ NOTE: the import switches -i and -lb are incompatible with all other switches fo
213219

214220

215221
#### Combinations
216-
Example: to export all non-archived notes, using content for blank note titles, with overwriting, preserving Keep label format, Logseq style paragraphs, with create dates > Oct 3, 2023 in batch:
222+
Example: to export all non-archived notes, using content for blank note titles, with overwriting, preserving Keep label format, Logseq style paragraphs, removing trailing hashtags if embedded in note, with create dates > Oct 3, 2023 in batch:
217223
```bash
218-
> python kim.py -c -o -p -l -cd "> 2023-10-03" -b --all
224+
> python kim.py -c -o -p -l -d -cd "> 2023-10-03" -b --all
219225
```
220226
Note: skip -s and overwrite -o cannot be used at the same time
221227

kim.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
__version__ = "0.6.7"
2+
13
import os
24
import gkeepapi
35
import keyring
@@ -17,7 +19,7 @@
1719
from importlib.metadata import version
1820
from PIL import Image
1921

20-
KIM_VERSION = "0.6.7"
22+
2123

2224
KEEP_KEYRING_ID = 'google-keep-token'
2325
KEEP_NOTE_URL = "https://keep.google.com/#NOTE/"
@@ -86,6 +88,7 @@ class Options:
8688
joplin_frontmatter: boolean
8789
move_to_archive: boolean
8890
wikilinks: boolean
91+
delete_labels: boolean
8992
silent_mode: boolean
9093
import_files: boolean
9194
import_labels: str
@@ -430,8 +433,7 @@ def set_file_extensions(self, data_file, file_name, file_path):
430433
what = image.format.lower()
431434
image.close()
432435
except:
433-
what = ".m4a"
434-
436+
what = ".audio"
435437

436438
if what == 'png':
437439
media_name = file_name + ".png"
@@ -446,7 +448,12 @@ def set_file_extensions(self, data_file, file_name, file_path):
446448
media_name = file_name + ".webp"
447449
blob_final_path = dest_path + ".webp"
448450
else:
449-
extension = ".m4a"
451+
with open(data_file, 'rb') as file:
452+
val = file.read(8).hex()
453+
if val == "0000001c66747970":
454+
extension = ".m4a"
455+
else:
456+
extension = ".mp3"
450457
media_name = file_name + extension
451458
blob_final_path = dest_path + extension
452459

@@ -493,6 +500,14 @@ def save_md_file(note, note_tags, note_date, opts):
493500
try:
494501
fs = FileService()
495502

503+
# 0.6.6 - if label hashtags are embedded then don't append
504+
if opts.delete_labels:
505+
for label in note_tags.split():
506+
pattern = rf"{re.escape(label)}"
507+
if re.search(pattern, note.text):
508+
note_tags = note_tags.replace(label, "")
509+
510+
496511
md_text = Markdown().format_check_boxes(note.text)
497512
note.title = NameService().check_duplicate_name(note.title, note_date)
498513

@@ -627,7 +642,8 @@ def keep_query_convert(keep, keepquery, opts):
627642
)
628643
if opts.move_to_archive:
629644
gnote.archived = True
630-
645+
646+
631647
filter_date = opts.create_date or opts.edit_date or None
632648
coperator = ""
633649
compare_date = None
@@ -702,9 +718,7 @@ def keep_query_convert(keep, keepquery, opts):
702718

703719
note.title = note.title.replace("/", "")
704720
note.text = note.text.replace("(" + NOTE_PREFIX,"(" + KEEP_URL)
705-
# 0.6.6 for label in note_labels.split():
706-
# note.text = note.text.replace(label, "")
707-
721+
708722
if opts.archive_only:
709723
if note.archived and note.trashed == False:
710724
keep_get_blobs(keep, note)
@@ -745,7 +759,7 @@ def keep_query_convert(keep, keepquery, opts):
745759
def ui_login(master_token, opts):
746760

747761
try:
748-
intro = "\r\nWelcome to Keep it Markdown or KIM " + KIM_VERSION + "!\r\n"
762+
intro = "\r\nWelcome to Keep it Markdown or KIM " + __version__ + "!\r\n"
749763
if opts.silent_mode:
750764
now = datetime.datetime.now()
751765
intro = "\r\n------\r\n" + now.strftime("%Y-%m-%d %H:%M:%S") + intro + "\r\n"
@@ -818,9 +832,9 @@ def ui_query(keep, search_term, opts):
818832
def _validate_options(opts) -> None:
819833
VALID_PREFIXES = ("< ", "> ")
820834
#reduced attribute names for compactness
821-
r, o, a, p, s, c, l, j, m, w, q, i, lb, cd, ed = opts
835+
r, o, a, p, s, c, l, j, m, w, d, q, i, lb, cd, ed = opts
822836

823-
if i and any([o, a, p, s, c, l, j, m, w]):
837+
if i and any([o, a, p, s, c, l, j, m, w, d]):
824838
raise click.UsageError("Import mode (-i) is not compatible "
825839
"with export options. Please use only "
826840
"(-i) to import notes.")
@@ -902,6 +916,7 @@ def _validate_paths() -> None:
902916
@click.option('-j', 'joplin_frontmatter', is_flag=True, help="Prepend notes with Joplin front matter tags and dates")
903917
@click.option('-m', 'move_to_archive', is_flag=True, help="Move any exported Keep notes to Archive")
904918
@click.option('-w', 'wikilinks', is_flag=True, help="Convert pre-formatted markdown note-to-note links to wikilinks")
919+
@click.option('-d', 'delete_labels', is_flag=True, help="Remove any duplicate labels that are already embedded in a note as hashtags")
905920
@click.option('-q', 'silent_mode', is_flag=True, help="Execute in silent mode - output in kim.log")
906921
@click.option('-i', 'import_files', is_flag=True, help="Import notes from markdown files WARNING - EXPERIMENTAL!!")
907922
@click.option('-lb', 'import_labels', '--lb', help="Labels for import - use only with (-i) flag")
@@ -921,6 +936,7 @@ def main(
921936
joplin_frontmatter: boolean,
922937
move_to_archive: boolean,
923938
wikilinks: boolean,
939+
delete_labels: boolean,
924940
silent_mode: boolean,
925941
import_files: boolean,
926942
import_labels: str,
@@ -942,6 +958,7 @@ def main(
942958
joplin_frontmatter,
943959
move_to_archive,
944960
wikilinks,
961+
delete_labels,
945962
silent_mode,
946963
import_files,
947964
import_labels,

0 commit comments

Comments
 (0)