-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcontrol.py
More file actions
121 lines (105 loc) · 3.26 KB
/
control.py
File metadata and controls
121 lines (105 loc) · 3.26 KB
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
import os
import sys
from argparse import Namespace
from api import AppleMusic
from core import getFiles
from core import animartwork
from core import tag
from core import muxhls
from core import download
from utils import logger
def __getPath():
if getattr(sys, 'frozen', False):
return os.path.dirname(
sys.executable
)
else:
return os.path.dirname(
os.path.abspath(
__file__
)
)
def arguments(args: Namespace):
CACHE = os.path.join(
__getPath(),
"cache"
)
if args.url == "reset":
if os.path.exists(
os.path.join(
CACHE,
"config.bin"
)
):
os.remove(
os.path.join(
CACHE,
"config.bin"
)
)
else:
contents = getFiles(args.input)
if os.path.isfile(args.input):
os.chdir(
os.path.abspath(
os.path.dirname(
args.input
)
)
)
else:
os.chdir(
os.path.abspath(
args.input
)
)
applemusic = AppleMusic(
CACHE,
args.sync,
args.skip_video
)
data = applemusic.getInfo(args.url)
if not args.no_cover:
if "coverUrl" in data:
if os.path.exists("Cover.jpg"):
os.remove("Cover.jpg")
download(
data["coverUrl"],
os.getcwd(),
"Cover.jpg",
"Downloading album artwork..."
)
if args.animartwork:
if "animartwork" in data:
anim = animartwork(data["animartwork"])
if anim:
if os.path.exists("Cover.mp4"):
os.remove("Cover.mp4")
download(
anim[0],
os.getcwd(),
"Cover.mp4",
f"Getting {anim[1]} animated artwork..."
)
if os.path.exists("Cover.mp4"):
logger.info("Muxing animated artwork...")
if muxhls("Cover.mp4", "_Cover.mp4") == 0:
os.remove("Cover.mp4")
os.rename("_Cover.mp4", "Cover.mp4")
else:
if os.path.exists("_Cover.mp4"):
os.remove("_Cover.mp4")
else:
logger.warning("No animated artworks available!")
try:
for i, file in enumerate(contents):
tag(
file,
data["streams"][i],
nocover=args.no_cover,
nolrc=args.no_lrc,
mediaUserToken=applemusic.isMediaUserToken
)
except IndexError:
pass
logger.info("Done.")