Code Monkey home page Code Monkey logo

Comments (2)

djoudi avatar djoudi commented on August 27, 2024

@yhamidullah

from alphormdownloader.

juhnny5 avatar juhnny5 commented on August 27, 2024

Tu peux remplacer le contenu du fichier main.py par:

__author__ = "HAMIDULLAH Yasser"
__copyright__ = "Copyright 2020, MadaGeeksCar"
__credits__ = ["HAMIDULLAH Yasser"]
__license__ = "MIT"
__version__ = "1.0.1"
__maintainer__ = "HAMIDULLAH Yasser"
__email__ = "[email protected]"
__status__ = "Debug" 


from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
import urllib.request,re,os,sys
from driver_support import *
from config import *

#get the available driver
driver = get_available_driver()
if driver == "":
    print("can't find any available driver")
    sys.exit()

LOGIN_URL = "https://www.alphorm.com/account/login"
def login(username,password):
    #load the login page
    driver.get (LOGIN_URL)

    #fill username and password field
    driver.find_element_by_id("username").send_keys(username)
    driver.find_element_by_id ("inputPassword1").send_keys(password)

    #find and click the login button
    driver.find_element_by_class_name("btn-connect").click()
def clean_text(text):
    return text.replace("/","_").replace("\"","").replace(":","_")

def get_course(url):
    #load the course page
    driver.get (url)
    
    #get the course name
    course_name = url.split("/")[4][19:]
    print("Course : ",course_name)

    #create the course folder if not exists
    if not os.path.isdir(course_name):
        os.mkdir(course_name)
    
    #go to the pladetaillé tab
    driver.find_elements_by_class_name("title-tab-tuto")[1]

    #get the lesson list and count for the loop range
    lessons = driver.find_elements_by_class_name("video_plan")
    num_links = len(lessons)
    vid_number = 1
    #loop over the lessons
    for i in range(num_links):
        #implicit wait to let the page load its full features
        #waiting util we can find the play button
        try:
            myElem = WebDriverWait(driver, 100).until(EC.presence_of_element_located((By.CLASS_NAME, 'video_plan')))
        except TimeoutException:
            print ("Loading took too much time!")
        
        #click on a lesson
        lessons[i].click()

        #play the selected lesson
        #driver.find_element_by_class_name("jw-icon jw-icon-inline jw-button-color jw-reset jw-icon-playback").click()
        
        #get the page source for inspection
        page_soup = BeautifulSoup(driver.page_source, 'html.parser')

        #find the active lesson
        lesson = page_soup.find_all('div',class_="menu_point active")[0].div.div.a.text

        #find the active chapter
        chapter = page_soup.find_all('div',class_="menu_point active")[0].parent.p.text

        #get the video link for download
        video_link = page_soup.find_all('video',class_="jw-video jw-reset")[0]['src']
        
        #cleaning special chars
        chapter = re.sub('1234567890[!@#$%^&*()[]{};:,./<>?\|`~-=_+]éà', ' ', chapter.strip())
        chapter = clean_text(chapter)
        lesson = re.sub('1234567890[!@#$%^&*()[]{};:,./<>?\|`~-=_+]éà', ' ', lesson.strip())
        lesson = clean_text(lesson)

        #create chapter's folder if not exists
        if not os.path.isdir(course_name + "/" +chapter.strip()):
            os.mkdir(course_name + "/" +chapter.strip())
            vid_number = 1
        
        #download and save to folder
        print("Downloading : ",chapter,"/",lesson,".mp4")
        urllib.request.urlretrieve(video_link, course_name+"/"+chapter+"/"+str(vid_number)+"-"+lesson+".mp4")
        vid_number += 1

    print("Finished")
login(email,password)

for url in courses:
    get_course(url)

from alphormdownloader.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.