Skip to content

Commit

Permalink
100% tested! Added manga. Nucks insane method somehow passed simpleco…
Browse files Browse the repository at this point in the history
…v test... no idea how
  • Loading branch information
toyhammered committed Jul 6, 2016
1 parent f924c70 commit 3e0a5a6
Show file tree
Hide file tree
Showing 5 changed files with 462 additions and 189 deletions.
9 changes: 4 additions & 5 deletions server/lib/data_import/my_anime_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ def initialize(opts = {})
end

def get_media(external_id) # anime/1234 or manga/1234
type = external_id.split('/') # going to be used when adding manga
media = Mapping.lookup('myanimelist', external_id) || type.first.classify.constantize.new # should return Anime.new or Manga.new
media = Mapping.lookup('myanimelist', external_id) || external_id.split('/').first.classify.constantize.new # should return Anime.new or Manga.new

get(external_id) do |response|
details = Extractor::Media.new(response)

media.assign_attributes(details.to_h)
media.assign_attributes(details.to_h.compact)
media.genres = details.genres.map do |genre|
Genre.find_by(name: genre)
end.compact
Expand All @@ -40,5 +39,5 @@ def build_url(path)
"#{ATARASHII_API_HOST}#{path}"
end

end # end of class
end # end of module
end
end
45 changes: 35 additions & 10 deletions server/lib/data_import/my_anime_list/extractor/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ def initialize(json)
end

def age_rating
rating = data['classification'].split(' - ')[0]
return unless data['classification']
rating = data['classification'].split(' - ')

case rating
case rating[0]
when 'G','TV-Y7' then :G
when 'PG', 'PG13' then :PG
when 'R', 'R+' then :R
Expand All @@ -31,14 +32,15 @@ def synopsis
end

def youtube_video_id
data['preview'].split('/').last
data['preview']&.split('/')&.last
end

def poster_image
data['image_url']
end

def age_rating_guide
return unless data['classification']
rating = data['classification'].split(' - ')

return "Violence, Profanity" if rating[0] == 'R'
Expand All @@ -49,30 +51,39 @@ def age_rating_guide
when 'G' then 'All Ages'
when 'PG' then 'Children'
when 'PG13', 'PG-13' then 'Teens 13 or older'
when 'R' then 'Violence, Profanity'
# when 'R' then 'Violence, Profanity' # this will NEVER happen because of return
when 'R+' then 'Mild Nudity'
when 'Rx' then 'Hentai'
end
end

def show_type
# needs to match one of these, case statement [TV special OVA ONA movie music]
def subtype # will be renamed to this hopefully
# anime matches [TV special OVA ONA movie music]
# manga matches [manga novel manhua oneshot doujin]

case data['type'].downcase
# anime
when 'tv' then :TV
when 'special' then :special
when 'ova' then :OVA
when 'ona' then :ONA
when 'movie' then :movie
when 'music' then :music
# manga
when 'manga' then :manga
when 'novel' then :novel
when 'manuha' then :manuha
when 'oneshot' then :oneshot
when 'doujin' then :doujin
end
end

def start_date
data['start_date'].to_date
data['start_date']&.to_date
end

def end_date
data['end_date'].try(:to_date)
data['end_date']&.to_date
end

def titles
Expand All @@ -87,10 +98,22 @@ def abbreviated_titles
data['other_titles']['synonyms']
end

# Manga Specific

def chapters
data['chapters']
end

def volumes
data['volumes']
end

# removed subtype (show_type, manga_type issue)
# missing status on manga (anime does automagically)
def to_h
%i[age_rating episode_count episode_length synopsis youtube_video_id
poster_image age_rating_guide show_type start_date end_date
titles abbreviated_titles
poster_image age_rating_guide start_date end_date
titles abbreviated_titles chapters volumes
].map do |k|
[k, send(k)]
end.to_h
Expand All @@ -100,6 +123,8 @@ def genres
data['genres']
end



# synopsis: seriously don't touch this unless you are Nuck.
def br_to_p(src)
src = '<p>' + src.gsub(/<br>\s*<br>/, '</p><p>') + '</p>'
Expand Down
79 changes: 79 additions & 0 deletions server/spec/fixtures/my_anime_list/berserk-manga.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"id": 2,
"title": "Berserk",
"other_titles": {
"english": [
"Berserk"
],
"synonyms": [
"Berserk: The Prototype"
],
"japanese": [
"\u30d9\u30eb\u30bb\u30eb\u30af"
]
},
"rank": 1,
"popularity_rank": 8,
"image_url": "http:\/\/cdn.myanimelist.net\/images\/manga\/1\/157931.jpg",
"type": "Manga",
"status": "publishing",
"members_score": 9.24,
"members_count": 104891,
"favorited_count": 24537,
"synopsis": "Guts, a former mercenary now known as the \"Black Swordsman,\" is out for revenge. After a tumultuous childhood, he finally finds someone he respects and believes he can trust, only to have everything fall apart when this person takes away everything important to Guts for the purpose of fulfilling his own desires. Now marked for death, Guts becomes condemned to a fate in which he is relentlessly pursued by demonic beings.<br><br>\r\nSetting out on a dreadful quest riddled with misfortune, Guts, armed with a massive sword and monstrous strength, will let nothing stop him, not even death itself, until he is finally able to take the head of the one who stripped him\u2014and his loved one\u2014of their humanity.<br><br>\r\n[Written by MAL Rewrite]<br><br><b>Included one-shot:<\/b><br>\r\nVolume 14: Berserk: The Prototype",
"genres": [
"Action",
"Adventure",
"Demons",
"Drama",
"Fantasy",
"Horror",
"Supernatural",
"Military",
"Psychological",
"Seinen"
],
"tags": [

],
"anime_adaptations": [
{
"anime_id": 33,
"title": "Berserk",
"url": "http:\/\/myanimelist.net\/anime\/33\/Berserk"
},
{
"anime_id": 10218,
"title": "Berserk: Ougon Jidai-hen I - Haou no Tamago",
"url": "http:\/\/myanimelist.net\/anime\/10218\/Berserk__Ougon_Jidai-hen_I_-_Haou_no_Tamago"
},
{
"anime_id": 12113,
"title": "Berserk: Ougon Jidai-hen II - Doldrey Kouryaku",
"url": "http:\/\/myanimelist.net\/anime\/12113\/Berserk__Ougon_Jidai-hen_II_-_Doldrey_Kouryaku"
},
{
"anime_id": 12115,
"title": "Berserk: Ougon Jidai-hen III - Kourin",
"url": "http:\/\/myanimelist.net\/anime\/12115\/Berserk__Ougon_Jidai-hen_III_-_Kourin"
},
{
"anime_id": 32379,
"title": "Berserk (2016)",
"url": "http:\/\/myanimelist.net\/anime\/32379\/Berserk_2016"
}
],
"related_manga": [
{
"manga_id": 92299,
"title": "Berserk: Shinen no Kami 2",
"url": "http:\/\/myanimelist.net\/manga\/92299\/Berserk__Shinen_no_Kami_2"
}
],
"alternative_versions": [

],
"personal_tags": [

]
}
Loading

0 comments on commit 3e0a5a6

Please sign in to comment.