-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortcut.py
128 lines (109 loc) · 5.17 KB
/
shortcut.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import os
from change import update_tags
from pull import pull_mp3_files
from images import stretch_all_covers, create_image_search_links
from covers import update_covers
from common import get_leaf_dirs, NEW, MAIN, JUMBLED_JUNK_DIR
from organize import clear_notes, clear_playlists, merge, rename_bookdirs
from authors import check_book_authors
from splitter import create_split_files, make_cue_sheets, PadTrackOption
from pathlib import Path
from enum import Enum, auto
class CoverOption(Enum):
ALWAYS = auto()
NEVER = auto()
ONLY_NEEDED = auto()
def pull_and_update(startdir=JUMBLED_JUNK_DIR,
destination=NEW,
check_exists=True, move_without_copying=False):
mp3s = pull_mp3_files(startdir=startdir,
destination=destination,
move_without_copying=move_without_copying,
check_exists=check_exists)
# stretch_all_covers(destination)
if mp3s == []:
print(f"No new mp3 files found in {startdir}")
return
newdirs = set([Path(mp3).parent for mp3 in mp3s])
tagged = update_tags(newdirs)
# update_descriptions(tagged['successes'])
rename_bookdirs(tagged['successes'])
corrected_dirs = [x['directory'] for x in tagged['successes']]
cover_results = update_covers(corrected_dirs)
needed_covers = ['{} audiobook cover'.format(x)
for x in cover_results['failures']]
author_dirs = set([Path(book).parent for book in corrected_dirs])
needed_authors = ['{} author photo'.format(d.name)
for d in author_dirs if (d/'_ needs photo').exists()]
needed_authors.sort()
needed_covers.sort()
create_image_search_links(needed_covers + needed_authors)
return tagged
def split_into_chapters(directory=NEW):
make_cue_sheets(replace_existing=True, pad_option=PadTrackOption.AUTO, directory=directory)
create_split_files(directory=directory)
def clean_up(from_dir=NEW, to_dir=MAIN):
clear_notes(from_dir)
clear_playlists(from_dir)
merge(from_dir=from_dir, to_dir=to_dir)
def update_new(new=NEW, get_images=CoverOption.ONLY_NEEDED):
try:
new = Path(new)
newdirs = set(get_leaf_dirs(new))
except TypeError:
pass
tagged = update_tags(newdirs)
rename_bookdirs(tagged['successes'])
if get_images == CoverOption.NEVER:
dirs_that_need_covers = []
elif get_images == CoverOption.ALWAYS:
dirs_that_need_covers = [x['directory'] for x in tagged['successes']]
elif get_images == CoverOption.ONLY_NEEDED:
tagged_dirs = [x['directory'] for x in tagged['successes']]
dirs_that_need_covers = [bookdir for bookdir in tagged_dirs
if not any((x.stem == 'cover' for x in bookdir.iterdir()))]
cover_results = update_covers(dirs_that_need_covers)
needed_covers = ['{} audiobook cover'.format(x)
for x in cover_results['failures']]
author_dirs = set([Path(book).parent for book in newdirs])
needed_authors = ['{} author photo'.format(d.name)
for d in author_dirs if (d/'_ needs photo').exists()]
needed_authors.sort()
needed_covers.sort()
create_image_search_links(needed_covers + needed_authors)
return tagged
def just_get_images(new=NEW, get_images=CoverOption.ONLY_NEEDED):
dirs = set(get_leaf_dirs(new))
if get_images == CoverOption.NEVER:
dirs_that_need_covers = []
elif get_images == CoverOption.ALWAYS:
dirs_that_need_covers = dirs
elif get_images == CoverOption.ONLY_NEEDED:
dirs_that_need_covers = [bookdir for bookdir in dirs
if not any((x.stem == 'cover' for x in bookdir.iterdir()))]
cover_results = update_covers(dirs_that_need_covers)
needed_covers = ['{} audiobook cover'.format(x)
for x in cover_results['failures']]
author_dirs = set([Path(book).parent for book in dirs])
needed_authors = ['{} author photo'.format(d.name) for d in author_dirs
if (d/'_ needs photo').exists() and not (d/'artist.jpg').exists()]
needed_authors.sort()
needed_covers.sort()
create_image_search_links(needed_covers + needed_authors)
def just_create_search_links(new=NEW, get_images=CoverOption.ALWAYS):
book_dirs = list(set(get_leaf_dirs(new)))
author_dirs = list(set([Path(book).parent for book in book_dirs]))
if get_images == CoverOption.NEVER:
needed_covers = []
needed_authors = []
elif get_images == CoverOption.ALWAYS:
needed_covers = ['{} audiobook cover'.format(d.name) for d in book_dirs]
needed_authors = ['{} author photo'.format(d.name) for d in author_dirs]
elif get_images == CoverOption.ONLY_NEEDED:
needed_covers = ['{} audiobook cover'.format(d.name) for d in book_dirs
if not any((x.stem == 'cover' for x in d.iterdir()))]
needed_authors = ['{} author photo'.format(d.name) for d in author_dirs
if (d/'_ needs photo').exists() and not (d/'artist.jpg').exists()]
needed_authors.sort()
needed_covers.sort()
create_image_search_links(needed_covers + needed_authors)