Skip to content

Instantly share code, notes, and snippets.

@julianrubisch
Created June 27, 2021 07:30
Show Gist options
  • Save julianrubisch/946b93cc417f3c89b910623c19a72eb3 to your computer and use it in GitHub Desktop.
Save julianrubisch/946b93cc417f3c89b910623c19a72eb3 to your computer and use it in GitHub Desktop.
URI.open(url) do |uri|
base_uri = uri.base_uri
listable_type = case base_uri.to_s
when /soundcloud.com\/(?<artist>.+)\/tracks/
raise UnparsableTrackUrlError
when /soundcloud.com\/(?<artist>.+)\/sets\/(?<title>.+)/
SoundCloudPlaylist
when /soundcloud.com\/(?<artist>.+)\/(?<title>.+)/
SoundCloudTrack
when /https?:\/\/(?<artist>.+)\.bandcamp.com\/track\/(?<title>.+)/
BandcampTrack
when /https?:\/\/(?<artist>.+)\.bandcamp.com\/album\/(?<title>.+)/
BandcampAlbum
end
new listable: listable_type.new, url: base_uri, list: list, artist: $1, title: $2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment