Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Made by 5p3ll
- # LinkedIn Learning Playlist Downloader (LLPD)
- import requests
- from bs4 import BeautifulSoup as BS
- def make_soup(url):
- reqs = requests.get(url)
- soup = BS(reqs.text, 'html.parser')
- return soup
- def get_all_playlist_links(input_url):
- soup = make_soup(input_url)
- all_links = []
- playlist_links = []
- for link in soup.find_all('a'):
- all_links.append(link.get('href'))
- for link in all_links:
- if link[-1:-8:-1] == "metIcot":
- playlist_links.append(link)
- return playlist_links
- def get_video_url(page_url):
- # Make a soup for every page, yammi
- soup = make_soup(page_url)
- # I try to get the src of the video tag but it gives me None
- # So I go one tag back (data-sources) then extract the url with string-formatting.
- data_sources = soup.find('video')
- if data_sources == '' or data_sources == None:
- return False
- else:
- data_sources = data_sources.get('data-sources')
- data_sources = data_sources.strip('[]{}"')
- video_url = data_sources[6:]
- return str(video_url)
- def download_video(video_url, counter):
- # Check the url first
- if video_url == None or video_url == '':
- return False
- # Print starting download msg
- print("Start Downloading from " + "'" + str(video_url) + "'")
- # Download the video
- response = requests.get(video_url)
- open(r"video " + str(counter) + ".mp4", 'wb').write(response.content)
- # Print end msg means no errors
- print(r"Download " + '"' + "video " + str(counter) + '"' + " Was Ended")
- def main():
- print("Linkedin Learning Playlist Downloader (LLPD)")
- input_url = input("Enter url of video to download the all playlist: ")
- playlist_links = get_all_playlist_links(input_url)
- counter = 0 # for naming the files
- # Print how many links was caught
- print(str(len(playlist_links)) + " links caught")
- # Download playlist (work sometimes... lmao)
- for link in playlist_links:
- try:
- counter += 1
- download_video(get_video_url(link), counter)
- except:
- pass
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment