-
Notifications
You must be signed in to change notification settings - Fork 1
/
anime_parse.py
78 lines (56 loc) · 1.85 KB
/
anime_parse.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
#!/usr/bin/env python3
##
# Dakara Project
#
from karaneko.nekoparse import NekoParseAnime, NekoParseTagsAnime
def extract_tags(tags):
""" From the tags dictionnary, returns list of tags
"""
tags_list = []
for tag in NekoParseTagsAnime.tags:
if tag["category"] == "use":
# ignore use tags
continue
if getattr(tags, tag["name"]):
tags_list.append(tag["serializer"])
return tags_list
def parse_file_name(file_name):
""" From a file name, returns a dictionnary with revelant values
"""
result = {}
anime = NekoParseAnime(file_name)
anime.parse()
result["title_music"] = anime.title_music
result["version"] = anime.extras.version
result["detail"] = anime.details
result["title_work"] = anime.title_anime
result["subtitle_work"] = anime.subtitle_anime or ""
result["work_type_query_name"] = "anime"
tags = anime.tags
if tags.opening:
result["link_type"] = "OP"
result["link_nb"] = tags.opening_nbr
elif tags.ending:
result["link_type"] = "ED"
result["link_nb"] = tags.ending_nbr
elif tags.insert_song:
result["link_type"] = "IN"
elif tags.image_song:
result["link_type"] = "IS"
extras = anime.extras
result["artists"] = []
if extras.artist:
result["artists"].append(extras.artist)
if anime.extras.original_artist:
result["artists"].append(anime.extras.original_artist)
detail_video_list = []
if extras.video:
detail_video_list.append(extras.video)
if extras.amv:
detail_video_list.append(extras.amv)
if extras.title_video:
detail_video_list.append(extras.title_video)
result["detail_video"] = ", ".join(detail_video_list)
result["episodes"] = extras.episodes
result["tags"] = extract_tags(tags)
return result