Skip to content

Instantly share code, notes, and snippets.

@cormullion
Last active August 5, 2017 09:08
Show Gist options
  • Select an option

  • Save cormullion/46e7a976822ce62be4476bb7b52f02ce to your computer and use it in GitHub Desktop.

Select an option

Save cormullion/46e7a976822ce62be4476bb7b52f02ce to your computer and use it in GitHub Desktop.
get JuliaCon2017 videos from YouTube as list
using HTTP, JSON, Query
# get data for the julia channel "UC9IuUwwE2xdjQUT_LMLONoA"
function getrawdata(nextpagetoken, apikey)
d = HTTP.get("https://www.googleapis.com/youtube/v3/search?key=$(apikey)&channelId=UC9IuUwwE2xdjQUT_LMLONoA&pageToken=$(nextpagetoken)&part=snippet,id&order=date&maxResults=50")
return d.body
end
jsonpages = [] # store the json pages, 50 records at a time
vidlinks = [] # to hold the video titles and links
# | insert your youtube api key here!
# V
myyoutubeapikey = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
nextpagetoken= "" # fortunately this can be "" to fetch the first batch of 50
for i in 1:3 # 3 gets three batches of 50 records each
linkspage = JSON.parse(getrawdata(nextpagetoken, myyoutubeapikey))
nextpagetoken = linkspage["nextPageToken"]
push!(jsonpages, linkspage)
end
# get titles and links from the JSON pages
for jsonpage in jsonpages
vidlinktitles = @from i in jsonpage["items"] begin
@where i["id"]["kind"] == "youtube#video"
@select i["id"]["videoId"], i["snippet"]["title"]
@collect
end
push!(vidlinks, vidlinktitles)
end
# join the list of titles/links, then sort them by the last word of the title
for i in sort!(union(vidlinks...), by = (x) -> last(split(last(x), " ")))
# in case we pick up ones from last year by mistake:
if contains(last(i), "2017")
# remove unnecessary content
newtitle=replace(last(i), "JuliaCon 2017 | ", "")
println("[$newtitle]($(string("https://www.youtube.com/watch?v=", first(i))))")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment