{"id":1542,"date":"2014-04-28T22:19:19","date_gmt":"2014-04-28T16:49:19","guid":{"rendered":"http:\/\/judepereira.com\/blog\/?p=1542"},"modified":"2014-04-28T22:25:35","modified_gmt":"2014-04-28T16:55:35","slug":"download-your-coursera-lectures-using-js-bash-and-wget","status":"publish","type":"post","link":"https:\/\/judepereira.com\/blog\/download-your-coursera-lectures-using-js-bash-and-wget\/","title":{"rendered":"Download your Coursera lectures using JS, bash and wget"},"content":{"rendered":"<p>So, in light of recent events, I was unable to follow up on my Coursera  Algorithms course.<\/p>\n<p>Trying to find a way to download all the lectures at once, I couldn&#8217;t find a way that worked for me &#8211; I found two, but they simply didn&#8217;t work. With the help of some JavaScript that I got from one of these sources, I cooked up the following steps to easily download all the lectures at once:<\/p>\n<p><strong>Step 1: Extract the lecture names, and their IDs from the Coursera page<\/strong><br \/>\nNavigate to your lecture page(for me, it was https:\/\/class.coursera.org\/algs4partII-003\/lecture).<br \/>\nExecute the following JavaScript in the Console(in Chrome, use the Inspect Element option):<br \/>\n[code lang=&#8221;javascript&#8221;]<br \/>\nfunction findLectures () {<br \/>\n  var link_elems = document.querySelectorAll(&#8216;.lecture-link&#8217;);<br \/>\n  var lectures = &#8220;&#8221;;<br \/>\n  Array.prototype.slice.call(link_elems).forEach(function (elem, i) {<br \/>\n    var lecture = i + &#8220;|&#8221; + elem.getAttribute(&#8216;data-lecture-id&#8217;) + &#8220;|&#8221; + elem.innerText.trim();<br \/>\n    lectures += lecture + &#8220;\\n&#8221;;<br \/>\n  });<br \/>\n  return lectures;<br \/>\n}<br \/>\n[\/code]<br \/>\nThen call the method findLectures(). This will print each lecture in the following format: Lecture position in page|Lecture ID|Lecture name.<br \/>\nExample output:<\/p>\n<blockquote><p>\n0|43|Course Introduction (9:22)<br \/>\n1|1|Introduction to Graphs (9:32)<br \/>\n2|2|Graph API (14:47)<br \/>\n&#8230;\n<\/p><\/blockquote>\n<p>Save this to a file named lectures.txt(exclude any quotes that get pasted)<\/p>\n<p><strong>Step 2: Export Coursera&#8217;s cookies<\/strong><br \/>\nUse the Chrome plugin <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/cookietxt-export\/lopabhfecdfhgogdbojmaicoicjekelh\" title=\"cookie.txt export for Chrome\" target=\"_blank\">cookie.txt export<\/a> to export all the cookies that Coursera has saved. Save the result to a file named cookies.txt<\/p>\n<p><strong>Step 3: Download them!<\/strong><br \/>\nRun the following in the terminal:<br \/>\n[code lang=&#8221;javascript&#8221;]<br \/>\nexport COUNT=1; while read line; do lecture_name=`echo $line | awk -F &#8216;|&#8217; {&#8216;print $3&#8217;}` lecture_id=`echo $line | awk -F &#8216;|&#8217; {&#8216;print $2&#8217;}`; echo &#8220;Downloading lecture $COUNT; ID=$lecture_id; Name=$lecture_name&#8230;&#8221;; ((COUNT++)); wget &#8211;load-cookies cookies.txt https:\/\/class.coursera.org\/algs4partII-003\/lecture\/download.mp4?lecture_id=$lecture_id -O &#8220;$COUNT &#8211; $lecture_name&#8221;; done < lectures.txt\n[\/code]\nMake sure you <strong>replace the link to where your lectures are listed<\/strong>. The above link has &#8220;https:\/\/class.coursera.org\/algs4partII-003\/lecture\/&#8221; in it. <\/p>\n<p>This will download all the lectures in the current working directory. It does not maintain any relationship with the week that the lecture was released in. It downloads them in the order that they are listed on the Coursera lecture page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, in light of recent events, I was unable to follow up on my Coursera Algorithms course. Trying to find a way to download all the lectures at once, I couldn&#8217;t find a way that worked for me &#8211; I found two, but they simply didn&#8217;t work. With the help of some JavaScript that I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[52,10],"tags":[484,485,487,486],"class_list":["post-1542","post","type-post","status-publish","format-standard","hentry","category-code","category-linux","tag-coursera","tag-download","tag-download-lectures","tag-lectures"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pqtyx-oS","jetpack-related-posts":[{"id":694,"url":"https:\/\/judepereira.com\/blog\/visual-basic-6-revisited-linux-wine\/","url_meta":{"origin":1542,"position":0},"title":"visual basic 6 revisited &#8211; linux &#8211; wine","author":"Jude Pereira","date":"August 5, 2010","format":false,"excerpt":"Earlier this year, I had written an article on running Visual Basic 6 on linux under wine, this is an update for it, the prior one is deprecated Getting Visual Basic 6 to work on linux is pretty easy, not much trouble, all the basic things work, as of what\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":903,"url":"https:\/\/judepereira.com\/blog\/usrlocalbinwaitpid\/","url_meta":{"origin":1542,"position":1},"title":"\/usr\/local\/bin\/waitpid","author":"Jude Pereira","date":"April 26, 2011","format":false,"excerpt":"A quick script to wait for a certain pid, then once that quits, execute a command. You may ask, why not just do command1 && command2 ? Well, if command1 exits with a non-zero exit status value, command2 will not get executed. Hence, I've brewed a quick script for this\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":893,"url":"https:\/\/judepereira.com\/blog\/coloured-varlogmessages-at-tty12\/","url_meta":{"origin":1542,"position":2},"title":"Coloured \/var\/log\/messages at tty12","author":"Jude Pereira","date":"April 26, 2011","format":false,"excerpt":"Reading logs could never become any more easier, at just a keystroke, you have your logs displayed where you want, in some fancy colour. They look great too. TTY's can be accessed by pressing Alt + Ctrl + F[1 - 12] simultaneously. In the following, you'll get a decent, colourized\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1830,"url":"https:\/\/judepereira.com\/blog\/ios-mac-ipsec\/","url_meta":{"origin":1542,"position":3},"title":"How to tunnel all traffic from your iOS device to your own server via IPSec","author":"Jude Pereira","date":"May 11, 2018","format":false,"excerpt":"TL;DR: A DigitalOcean droplet, strongSwan, and a custom Configuration Profile for iOS routes all the traffic from my iPhone via my droplet. Why? Just because I can. Note: This setup does not require you to download Apple Configurator and switch your iPhone into Supervised mode (we will create a configuration\u2026","rel":"","context":"In &quot;gnu linux&quot;","block_context":{"text":"gnu linux","link":"https:\/\/judepereira.com\/blog\/category\/linux\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screen-Shot-2018-05-10-at-20.34.32-1024x134.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screen-Shot-2018-05-10-at-20.34.32-1024x134.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screen-Shot-2018-05-10-at-20.34.32-1024x134.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1675,"url":"https:\/\/judepereira.com\/blog\/sending-notifications-via-apples-new-http2-api-using-jetty-9-3-6\/","url_meta":{"origin":1542,"position":4},"title":"Sending notifications via Apple&#8217;s new HTTP\/2 API (using Jetty 9.3.6)","author":"Jude Pereira","date":"January 9, 2016","format":false,"excerpt":"HTTP\/2 is still very much new to Java, and as such, there are just two libraries who support it - Jetty (from 9.3), and Netty (in alpha). If you're going the Jetty way (as I have), you'll need to add their ALPN library to your boot classpath. Note: Jetty 9.3.x\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1950,"url":"https:\/\/judepereira.com\/blog\/getting-the-aws-cli-to-accept-cloudflare-warps-root-certificate\/","url_meta":{"origin":1542,"position":5},"title":"Getting the AWS CLI to accept Cloudflare WARP&#8217;s root certificate","author":"Jude Pereira","date":"August 11, 2021","format":false,"excerpt":"Download, convert, and install the Cloudflare WARP root certificate into your local set of trusted root CAs, and then tell the AWS CLI to use it.","rel":"","context":"In &quot;miscellaneous&quot;","block_context":{"text":"miscellaneous","link":"https:\/\/judepereira.com\/blog\/category\/misc\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screenshot-2021-08-11-at-17.27.10.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screenshot-2021-08-11-at-17.27.10.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screenshot-2021-08-11-at-17.27.10.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screenshot-2021-08-11-at-17.27.10.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/1542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/comments?post=1542"}],"version-history":[{"count":8,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/1542\/revisions"}],"predecessor-version":[{"id":1550,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/1542\/revisions\/1550"}],"wp:attachment":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/media?parent=1542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/categories?post=1542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/tags?post=1542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}