Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all except cards and endscreens #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions lib/yt/annotations/for.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
require 'yt/annotations/branding'
require 'yt/annotations/card'
require 'yt/annotations/end_screen'
require 'yt/annotations/label'
require 'yt/annotations/note'
require 'yt/annotations/speech'
require 'yt/annotations/spotlight'
require 'yt/annotations/title'
require 'yt/annotations/pause'
require 'yt/annotations/promotion'

# An object-oriented Ruby client for YouTube.
# @see http://www.rubydoc.info/gems/yt/
Expand Down Expand Up @@ -44,7 +37,6 @@ def fetch(path)
def xml_to_annotations(xml)
annotations = xml['document']['annotations']
annotations = Array.wrap (annotations || {})['annotation']
annotations = merge_highlights annotations
annotations = exclude_drawers annotations
annotations.map{|data| annotation_class(data).new data}
end
Expand All @@ -56,34 +48,17 @@ def json_to_annotations(json)

def annotation_class(data)
case data['style']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these nested conditionals be simplified now? Seems like it could just be

if data['style'] == 'branding'
  Annotations::Branding
else
  Annotations::Card
end

when 'anchored', 'speech' then Annotations::Speech
when 'branding' then Annotations::Branding
when 'highlightText' then Annotations::Spotlight
when 'label' then Annotations::Label
when 'popup' then Annotations::Note
when 'title' then Annotations::Title
else case data['type']
else
case data['type']
when 'card' then Annotations::Card
when 'pause' then Annotations::Pause
when 'promotion' then Annotations::Promotion
end
end
end

def exclude_drawers(annotations)
annotations.reject{|a| a['type'] == 'drawer'}
end

def merge_highlights(annotations)
highlights, others = annotations.partition{|a| a['type'] == 'highlight'}
highlights.each do |highlight|
match = others.find do |a|
(a['segment'] || {})['spaceRelative'] == highlight['id']
end
match.merge! highlight if match
end
others
end
end
end
end
10 changes: 0 additions & 10 deletions lib/yt/annotations/label.rb

This file was deleted.

44 changes: 0 additions & 44 deletions lib/yt/annotations/note.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/yt/annotations/pause.rb

This file was deleted.

30 changes: 0 additions & 30 deletions lib/yt/annotations/promotion.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/yt/annotations/speech.rb

This file was deleted.

10 changes: 0 additions & 10 deletions lib/yt/annotations/spotlight.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/yt/annotations/title.rb

This file was deleted.

Loading