-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c976d0
commit ab56b20
Showing
16 changed files
with
1,694 additions
and
2,572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# require "active_support/core_ext/hash/keys" | ||
|
||
# This class is used to extract the metadata from a youtube video | ||
# it will try to: | ||
# - extract the speakers from the title | ||
# - remove the event_name from the title to make less redondant | ||
# - remove leading separators from the title | ||
module Youtube | ||
class VideoMetadata | ||
SPEAKERS_SECTION_SEPARATOR = " by " | ||
SEPARATOR_IN_BETWEEN_SPEAKERS = / & |, | and / | ||
|
||
def initialize(metadata:, event_name:, options: {}) | ||
@metadata = metadata | ||
@event_name = event_name | ||
end | ||
|
||
def cleaned | ||
OpenStruct.new( | ||
{ | ||
title: title, | ||
raw_title: raw_title, | ||
speakers: speakers, | ||
event_name: @event_name, | ||
published_at: @metadata.published_at, | ||
description: description, | ||
video_id: @metadata.video_id | ||
} | ||
) | ||
end | ||
|
||
def keynote? | ||
title_without_event_name.match(/keynote/i) | ||
end | ||
|
||
def lighting? | ||
title_without_event_name.match(/lightning talks/i) | ||
end | ||
|
||
private | ||
|
||
def extract_info_from_title | ||
title_parts = title_without_event_name.split(SPEAKERS_SECTION_SEPARATOR) | ||
speakers = title_parts.last.split(SEPARATOR_IN_BETWEEN_SPEAKERS).map(&:strip) | ||
title = title_parts[0..-2].join(SPEAKERS_SECTION_SEPARATOR).gsub(/^\s*-/, "").strip | ||
|
||
{ | ||
title: keynote? ? remove_leading_and_trailing_separators_from(title_without_event_name) : remove_leading_and_trailing_separators_from(title), | ||
speakers: speakers | ||
} | ||
end | ||
|
||
def speakers | ||
return [] if lighting? | ||
|
||
title_parts = title_without_event_name.split(SPEAKERS_SECTION_SEPARATOR) | ||
title_parts.last.split(SEPARATOR_IN_BETWEEN_SPEAKERS).map(&:strip) | ||
end | ||
|
||
def raw_title | ||
@metadata.title | ||
end | ||
|
||
def title_without_event_name | ||
# RubyConf AU 2013: From Stubbies to Longnecks by Geoffrey Giesemann | ||
# will return "From Stubbies to Longnecks by Geoffrey Giesemann" | ||
remove_leading_and_trailing_separators_from(raw_title.gsub(@event_name, "").gsub(/\s+/, " ")) | ||
end | ||
|
||
## remove : - and other separators from the title | ||
def remove_leading_and_trailing_separators_from(title) | ||
title.gsub(/^[-:]?/, "").strip.then do |title| | ||
title.gsub(/[-:,]$/, "").strip | ||
end | ||
end | ||
|
||
def title | ||
if keynote? || lighting? | ||
# when it is a keynote or lighting, usually we want to keep the full title without the event name | ||
remove_leading_and_trailing_separators_from(title_without_event_name) | ||
else | ||
title_parts = title_without_event_name.split(SPEAKERS_SECTION_SEPARATOR) | ||
title = title_parts[0..-2].join(SPEAKERS_SECTION_SEPARATOR).gsub(/^\s*-/, "").strip | ||
remove_leading_and_trailing_separators_from(title) | ||
end | ||
end | ||
|
||
def description | ||
@metadata.description | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# require "active_support/core_ext/hash/keys" | ||
|
||
# This class is used to extract the metadata from a youtube video | ||
# it will try to: | ||
# - extract the speakers from the title | ||
# - remove the event_name from the title to make less redondant | ||
# - remove leading separators from the title | ||
module Youtube | ||
class VideoMetadataRailsWorld | ||
SPEAKERS_SECTION_SEPARATOR = " - " | ||
SEPARATOR_IN_BETWEEN_SPEAKERS = / & |, | and / | ||
|
||
def initialize(metadata:, event_name:, options: {}) | ||
@metadata = metadata | ||
@event_name = event_name | ||
end | ||
|
||
def cleaned | ||
OpenStruct.new( | ||
{ | ||
title: title, | ||
raw_title: raw_title, | ||
speakers: speakers, | ||
event_name: @event_name, | ||
published_at: @metadata.published_at, | ||
description: description, | ||
video_id: @metadata.video_id | ||
} | ||
) | ||
end | ||
|
||
def keynote? | ||
title_without_event_name.match(/keynote/i) | ||
end | ||
|
||
private | ||
|
||
def extract_info_from_title | ||
title_parts = title_without_event_name.split(SPEAKERS_SECTION_SEPARATOR) | ||
speakers = title_parts.last.split(SEPARATOR_IN_BETWEEN_SPEAKERS).map(&:strip) | ||
title = title_parts[0..-2].join(SPEAKERS_SECTION_SEPARATOR).gsub(/^\s*-/, "").strip | ||
|
||
{ | ||
title: keynote? ? remove_leading_and_trailing_separators_from(title_without_event_name) : remove_leading_and_trailing_separators_from(title), | ||
speakers: speakers | ||
} | ||
end | ||
|
||
def speakers | ||
raw_title_parts.first.split(SEPARATOR_IN_BETWEEN_SPEAKERS).map(&:strip) | ||
end | ||
|
||
def raw_title | ||
@metadata.title | ||
end | ||
|
||
def title_without_event_name | ||
# RubyConf AU 2013: From Stubbies to Longnecks by Geoffrey Giesemann | ||
# will return "From Stubbies to Longnecks by Geoffrey Giesemann" | ||
remove_leading_and_trailing_separators_from(raw_title.gsub(@event_name, "").gsub(/\s+/, " ")) | ||
end | ||
|
||
## remove : - and other separators from the title | ||
def remove_leading_and_trailing_separators_from(title) | ||
return title if title.blank? | ||
|
||
title.gsub(/^[-:]?/, "").strip.then do |title| | ||
title.gsub(/[-:,]$/, "").strip | ||
end | ||
end | ||
|
||
def title | ||
remove_leading_and_trailing_separators_from(raw_title_parts[1]) | ||
end | ||
|
||
def description | ||
@metadata.description | ||
end | ||
|
||
def raw_title_parts | ||
title_without_event_name.split(SPEAKERS_SECTION_SEPARATOR) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uAKB/HPZ9hm7lyAIpWgUe+24TG/N8bi2smtvEa7aD0nZNIU1sb0ctVEYNcSQbKJjHWSED68aF9/O7iYBt1QYU93in3J14rDvj0bHJ8GCWNEQFI6QekRPcOVrX4qehGn4Y29ikhsrc1/th6V0EHrkP4q3d+AtK0zazPLpLQgMFSMX5dYjck2vT8HfK3nOvX77+RUPXhyyO9roIBDBpSf8kEayzUi0q/h/k8cGsqbM3aL2InfXNM8gaQgJ7atEAzJsKoyt5yGoFxjWTDoOFEqnIIhXu1uRmW+S5aKUC/h0Kil/nEgsvufZGuPiDQgHvXZmO/3W3MmaCLaO2LHcp4qMySaH5SDBOXdzAmGuEl0SMhdyvtuZBCw60WmWRhh9GnhwBwJs/FdlaGnAGLZyB+lQhYYNTOww--9Tq1/zY6N+kujjV9--iOafU6Imt5fluW+yk+MPWQ== |
Oops, something went wrong.