-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename_rules.rb
65 lines (59 loc) · 1.73 KB
/
rename_rules.rb
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
# this method should return a path where files should be stored inside the destination directory and
# the name that an identified file should take.
# As a sample, the given file uses the romanji name of the anime as the folder
# and the file is written as anime_name - episode <number> [groupname] and movie files are stored as
# anime_name - Complete Movie or anime_name - Part 1 of 3.
# here is a sample of the "info" you will get if you want to change the name format.
# {
# fid: 271_926,
# file: {
# length: '1778',
# quality: 'high',
# video_resolution: '640x480',
# source: 'LD',
# sub_language: 'none',
# gid: '0',
# dub_language: 'japanese',
# eid: '26772',
# aid: '1179',
# },
# anime: {
# type: 'OVA',
# ep_romaji_name: '',
# highest_episode_number: '2',
# group_name: 'raw/unknown',
# english_name: '',
# group_short_name: 'raw',
# romaji_name: 'Bounty Dog: Getsumen no Ibu',
# year: '1994-1994', epno: '1',
# ep_english_name: 'Code 1'
# },
# }
def generate_name(info)
anime = info[:anime]
name = anime[:romaji_name]
episode = " - episode #{anime[:epno]}"
part =
if movie?(anime)
if /Complete Movie|Part \d of \d/.match(anime[:ep_english_name]) && !special?(anime)
" - #{anime[:ep_english_name]}"
else
"#{episode} - #{anime[:ep_english_name]}"
end
else
episode
end
[anime[:romaji_name], "#{name}#{part}#{group_name(anime)}"]
end
def group_name(anime)
g = anime[:group_short_name]
g == 'raw' ? nil : " [#{g}]"
end
def movie?(anime)
anime[:type] == 'Movie'
end
def special?(anime)
result = /^(?<spc_type>[A-Z])?\d+(?:-\d+)?$/.match anime[:epno]
raise 'unknown' unless result
!result[:spc_type].nil?
end