File size: 2,057 Bytes
a20d046
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import requests
import json
from bs4 import BeautifulSoup
headers = {
    'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0',
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'en-US,en;q=0.5',
    # 'Accept-Encoding': 'gzip, deflate, br, zstd',
    'X-Requested-With': 'XMLHttpRequest',
    'DNT': '1',
    'Sec-GPC': '1',
    'Connection': 'keep-alive',
    'Referer': 'https://eduboom.it/',
    # 'Cookie': 'PHPSESSID=ibmi18fulfuhve42sq49tbkkme',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'Pragma': 'no-cache',
    'Cache-Control': 'no-cache',
    # Requests doesn't support trailers
    # 'TE': 'trailers',
}


def get_m3u8(temp_url):
    response = requests.get(temp_url, headers=headers)
    soup = BeautifulSoup(response.text, 'lxml')
    data_params = soup.find('div', class_='ucha-player play-button')['data-params']
    real_data = json.loads(data_params)
    m3u8_link = real_data['sources']['main']['smil']
    if "smil:trailer" in m3u8_link:
        m3u8_link = m3u8_link.replace("smil:trailers","smil:videos").replace("/registration","")
        print("Found .m3u8 link:", m3u8_link)
        return m3u8_link



def eduboom(query):
    try:
        params = {
            'term': query,
        }
        response = requests.get('https://eduboom.it/ajax/lessons-search', params=params, headers=headers)
        data = response.json()
        i = 0
        for item in data:
            i = i + 1
            name = item['value']
            category = item['category']
            grade = item['grade']
            print("ID:",i,"Name:",name,"Category:",category,"Grade:",grade)
        user_input = int(input("Enter the id of the video you want to watch: "))
        selected_item = data[user_input-1]
        link = selected_item['url']
        m3u8_link = get_m3u8(link)
        return m3u8_link

    except Exception as e:
        print("Nothing",e)
        return None
    

a = eduboom("Parini")