5p3ll

LinkedIn Learning Playlist Downloader (try)

Jul 31st, 2022
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 KB | None | 0 0
  1. # Made by 5p3ll
  2.  
  3. # LinkedIn Learning Playlist Downloader (LLPD)
  4.  
  5. import requests
  6. from bs4 import BeautifulSoup as BS
  7.  
  8.  
  9. def make_soup(url):
  10.     reqs = requests.get(url)
  11.     soup = BS(reqs.text, 'html.parser')
  12.     return soup
  13.  
  14.  
  15. def get_all_playlist_links(input_url):
  16.     soup = make_soup(input_url)
  17.    
  18.     all_links = []
  19.     playlist_links = []
  20.  
  21.     for link in soup.find_all('a'):
  22.         all_links.append(link.get('href'))
  23.  
  24.     for link in all_links:
  25.         if link[-1:-8:-1] == "metIcot":
  26.             playlist_links.append(link)
  27.  
  28.     return playlist_links
  29.  
  30.  
  31.  
  32. def get_video_url(page_url):
  33.     # Make a soup for every page, yammi
  34.     soup = make_soup(page_url)
  35.  
  36.     # I try to get the src of the video tag but it gives me None
  37.     # So I go one tag back (data-sources) then extract the url with string-formatting.
  38.     data_sources = soup.find('video')
  39.     if data_sources == '' or data_sources == None:
  40.         return False
  41.     else:
  42.         data_sources = data_sources.get('data-sources')
  43.  
  44.     data_sources = data_sources.strip('[]{}"')
  45.     video_url = data_sources[6:]
  46.     return str(video_url)
  47.    
  48.  
  49.  
  50. def download_video(video_url, counter):
  51.     # Check the url first
  52.     if video_url == None or video_url == '':
  53.         return False
  54.     # Print starting download msg
  55.     print("Start Downloading from " + "'" + str(video_url) + "'")
  56.  
  57.     # Download the video
  58.     response = requests.get(video_url)
  59.     open(r"video " + str(counter) + ".mp4", 'wb').write(response.content)
  60.  
  61.     # Print end msg means no errors
  62.     print(r"Download " + '"' + "video " + str(counter) + '"' + " Was Ended")
  63.  
  64.  
  65.  
  66. def main():
  67.     print("Linkedin Learning Playlist Downloader (LLPD)")
  68.     input_url = input("Enter url of video to download the all playlist: ")
  69.     playlist_links = get_all_playlist_links(input_url)
  70.     counter = 0 # for naming the files
  71.    
  72.     # Print how many links was caught
  73.     print(str(len(playlist_links)) + " links caught")
  74.  
  75.     # Download playlist (work sometimes... lmao)
  76.     for link in playlist_links:
  77.         try:
  78.             counter += 1
  79.             download_video(get_video_url(link), counter)
  80.         except:
  81.             pass
  82.        
  83. if __name__ == '__main__':
  84.     main()
  85.  
Advertisement
Add Comment
Please, Sign In to add comment