Skip to content

Instantly share code, notes, and snippets.

@stupergenius
Last active October 11, 2016 19:02
Show Gist options
  • Save stupergenius/5c55b32bd63ec071ae4d765707074822 to your computer and use it in GitHub Desktop.
Save stupergenius/5c55b32bd63ec071ae4d765707074822 to your computer and use it in GitHub Desktop.
Downloads all video replays from the With The Best conference site. Download and then play them with VLC at 2x speed 🤘. Built to download videos from the Swift conference but could be easily modified to download from other conferences. *PLEASE* use this only for personal use, and do otherwise abide by the conference policies.
# The MIT License (MIT)
# Copyright (c) 2016 Ben Snider
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'net/http'
require 'json'
require 'shellwords'
def sanitize_filename(filename)
# From http://stackoverflow.com/a/10823131/265648
# Split the name when finding a period which is preceded by some
# character, and is followed by some character other than a period,
# if there is no following period that is followed by something
# other than a period (yeah, confusing, I know)
fn = filename.split /(?<=.)\.(?=[^.])(?!.*\.[^.])/m
# We now have one or two parts (depending on whether we could find
# a suitable period). For each of these parts, replace any unwanted
# sequence of characters with an underscore
fn.map! { |s| s.gsub /[^a-z0-9\-]+/i, '_' }
# Finally, join the parts with a period and return the result
Shellwords.escape(fn.join '.')
end
DownloadItem = Struct.new(:title, :url, :filename)
def get_replays(url)
uri = URI(url)
response = Net::HTTP.get(uri)
JSON.parse(response)
end
def get_download_list(replays)
replays.map { |replay|
DownloadItem.new(
replay['title'],
Shellwords.escape(replay['mp4']),
sanitize_filename(replay['title']) + '.mp4'
)
}
end
def download_replays(download_list)
download_list.each { |item|
puts "Downloading '#{item.title}' ..."
command = "curl --create-dirs -o 'replays/#{item.filename}' '#{item.url}'"
# puts command
system command
}
end
## MAIN ##
# Replace the url with the target conference's hostname.
replays = get_replays 'https://swift.withthebest.bemyapp.com/api/replays?conversionState=DONE'
download_list = get_download_list replays
download_replays download_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment