Tuesday 8 September 2015

How to Download lynda.com Courses Using youtube-dl

How to Download lynda.com Courses Using youtube-dl

learn-programming (2)This how to download lynda.com videos tutorial will help you download whole courses instead of individually downloading the videos, if you either have an individual or an organization login access to lynda.com on Linux.
If you don’t have access to lynda.com you might find them on torrent websites or on this very generous sharer:http://p30download.com/tag/lynda.
This how to download lynda.com videos tutorial can also be followed on Windows by knowing how to download and use youtube-dl tool in Windows. Their documentation (https://github.com/rg3/youtube-dl/blob/master/README.md#readme) will help you in it, it’s a simple .exe installer. There are easy tutorials for using youtube-dl on Windows. It’s almost similar to that of Linux.
If you have access to the massive lynda.com library (which in itself is amazing), you can download the whole courses (all videos of any course in one go) instead of going the hectic way of  individually downloading the individual videos one by one by using your favorite download manager. Though there are online and desktop tools that provide this functionality to download whole lynda.com courses at one go, they often include malware and most importantly they don’t run on Linux without Wine.
So, there is this awesome Python script called youtube-dl written for various platforms, that is clean and safe to use, that we are going to leverage in this how to download lynda.com videos tutorial.
You need to install youtube-dl using your distro’s package manager. I’m using ubuntu 14.04, so I’ll open my terminal and I’ll do:
Or alternately, as they have instructed in their download manual (https://rg3.github.io/youtube-dl/download.html) online, you can do either one of the following (downloading from the sources.
It’s always safer to download from the source, as there have been instances where installing from the package manager has resulted in some problems like not being able to update youtube-dl version. Check that your youtube-dl is the latest version by typing
in your command line.
lynda-videos-download

How to download lynda.com videos tutorial with individual login?

  • Create a file using your favorite text editor, called lynda.py (you can name it anything provided it has an extension ‘.py’ (for python))
  • Copy paste the following code in it and then save it
#(The space after _password is necessary, keep in attention).
This script will do 3 things. First it will scrape all the links from a specific lynda tutorial that you want to have- in this case, the placeholder is “http://www.lynda.com/Git-tutorials/Git-Essential-Training/100222-2.html”. Second, it will parse out only those links which have a key URL that all the videos share in common. In this case, the placeholder is ‘http://www.lynda.com/Bootstrap-tutorials/’. This is extremely important; you need to put the key URL that all the videos share in common because there are many more links in the page and you don’t want youtube-dl returning a bunch of invalid URL errors.
Finally, after it parses all the links from the actual tutorial videos, it runs “youtube-dl –username your_lynda_username –password your_lynda_password” for every link that it found. There it is! youtube-dl will collect all the videos and download them automatically. Remember you’ll need to install BeautifulSoup library before you run the script!
To install BeautifulSoup library:
  • Extract the tar file in any directory/ directory of the download, by either right click and clicking ‘Extract Here’ or through terminal by going in the directory where the tar file is and typing:
Once extracted, remain in the same directory and type in the terminal
Or, you can directory install it from the ubuntu apt-get package manager (or check if your distro’s package manager contains it)
Install the latest version by doing
Now that we are all set, go to the terminal and change the directory to where lynda.py file is and then type
And it will start downloading all the files of that course, in the default directory (where youtube-dl stores the videos by default). If you want to choose where to download the videos, instead of using
in the last line of lynda.py you can add another flag -o to change the location of the download, like this:

How to download lynda.com videos tutorial using organizational login?

Now the things get tricky. If you have an organizational login, you won’t simply be able to use a username and password in the youtube-dl command because your HTTP request has to redirect from lynda to sapient and then back. The simplest way to do it, is to login to your organizational lynda account and export cookies and then using the –cookies flag of youtube-dl to use them. It sounds complicated, but isn’t really, let’s go step by step.
The only cookie manager that I used was a firefox add on  “Cookie Exporter 1.5.1-signed” by fliwatüt.
Go to the firefox addons and install this plugin and restart firefox. You’d be able to see the ‘export cookies’ option.
lynda-videos-download
Login to your organizational lynda.com account and export cookies to any desired location. I’m exporting it to  my Videos->lynda-hack directory.
Now that we have a cookies.txt file, we have to edit it a bit, because youtube-dl can only read and use cookies which are in netscape format. To convert the cookies in netscape format, all you have to do is add “# Netscape HTTP Cookie File” without the quotes as the first line in the cookie and save it.
lynda-videos-download
Now there is another invisible problem with the cookies. The new lines in the cookies.txt file are Windows formated (‘\r\n’), we have to make them Linux format (‘\n’). The simplest way of doing it is by using a hex editor. To download a hex editor called bless type in your terminal.
Open bless and open the cookies.txt file in it. Hit Cltr+R and search for 0D0A(which is the ascii code for \r\n type newline) and in the replace text holder enter 0A ( which is the ascii code for \n type newline) and click ‘Replace All’.
lynda-videos-download
lynda-videos-download
Now press Cltr+A to select the new edited text file in bless and paste it in the original cookie1.txt and hit save.
lynda-videos-download
Remember to put the cursor on the txt area (and not on the hex code area) before copying the edited cookies.txt file in bless hex editor.
lynda-videos-download
Now you all the steps regarding the script execution is the same except that the last line of the lynda.txt will look like
In my case path to the cookies is Videos/lynda-hack
lynda-videos-download
That’s it! now you relax and wait for the videos to download on by their own!
The Videos will be downloaded in the directory where the lynda.py script is. You can use youtube-dl’s -o “path_where_you_want_videos_downloaded” flag, but it didn’t work for me, and I couldn’t fix it. If anybody could, post it in the comments!
Now you are all up and running and equipped with downloading your lynda.com courses in one go.
Also, the downloaded videos have very excruciatingly different file names. So, I wrote a not so efficient but workable python script to ensure that the videos are arranged by their order of the download.
In “put_all_the_unwanted_characters_here” argument in .translate method, you put every lowercase and uppercase alphabet(from a to z and A-Z) and other unwanted characters like “(“, “)”,” ”(newline) etc, and check if the file names are in a sequential number list order. Keep checking and running this python script til you get the order right (don’t forget to enable the view by name in your file manager’s toolbar). In the end it will be an ordered numbered list like this.
lynda-videos-download
Did you find this how to download lynda.com videos tutorial helpful? Did you face any difficulty? Tell your views in comments below.

1 comment:

  1. Allavsoft provides two methods to save lynda videos offline
    Method 1: Copy and paste the lynda video link to Allavsoft and Click Download button.
    Method 2: Click RED to record the lynda videos
    It has both Mac and Windows version.

    ReplyDelete