forked from koudi/plugin.video.mall.tv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mall.py
141 lines (100 loc) · 4.12 KB
/
mall.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
import requests
import re
class MallApi():
BASE = 'https://www.mall.tv'
def __init__(self, plugin):
self.plugin = plugin
def warn(self, *args, **kwargs):
self.plugin.log.warning(*args, **kwargs)
def url_for(self, *args, **kwargs):
return self.plugin.url_for(*args, **kwargs)
def get_page(self, url):
r = requests.get(self.BASE + url)
return BeautifulSoup(r.content, 'html.parser')
def get_categories(self, ):
result = []
page = self.get_page('/kategorie')
category = page.find('section', {'class': 'isCategory'})
cards = category.find_all('div', {'class': 'video-card'})
self.warn(self.url_for('category', link='3'))
for card in cards:
a = card.find('a')
result.append({
'path': self.url_for('category', link=a['href']),
'thumbnail': a['data-src'],
'label': card.find('h2').contents[0]
})
badges = page.find_all('a', {'class': 'badge-kategory'})
for badge in badges:
result.append({
'path': self.url_for('category', link=badge['href']),
'label': badge.contents[0]
})
return result
def get_category(self, link):
page = self.get_page(link)
return self.extract_shows(page)
def get_shows(self):
index = 0
shows = []
while True:
self.warn(index)
page = self.get_page('/Serie/CategorySortedSeries?categoryId=0&sortType=1&page=' + str(index))
if not page:
return shows
slider_item = page.find('div', {'class': 'video-grid__body'})
if slider_item:
count = int(slider_item['slider-total'])
shows += self.extract_shows(page)
if len(shows) >= count:
break
index += 1
return shows
def get_show_videos(self, link):
page = self.get_page(link)
return self.extract_videos(page)
def extract_shows(self, page):
result = []
for item in page.select('.video-card__series figure'):
result.append({
'label': item.find('h4').text,
'path': self.url_for('show', link=item.find('a')['href']),
'thumbnail': item.find('a', attrs={'data-src': True})['data-src']
})
return result
def extract_videos(self, page):
result = []
grid = page.find('section', {'class': ['video-grid', 'isVideo']})
for card in grid.find_all('div', {'class': 'video-card'}):
link = card.select('.video-card__details a.video-card__details-link')[0]
result.append({
'label': link.text,
'thumbnail': card.find('div', {'class': ['video-card__thumbnail', 'lazy']})['data-src'],
'path': self.url_for('video', link=link['href']),
'info': {
'duration': self.get_duration(card.find('span', {'class': 'badge__wrapper-video-duration'}).text)
},
'is_playable': True
})
return result
def get_duration(self, val):
count = 0
coef = [1, 60, 3600]
for index, part in enumerate(reversed(val.split(':'))):
count += int(part) * coef[index]
return count
def get_video_url(self, link):
page = self.get_page(link)
source = page.find('source')
if not source:
main_link = page.find('meta', {'itemprop': 'image'})['content'].replace('standart.jpg', 'index.m3u8')
else:
main_link = source['src'] + '.m3u8'
index_list = requests.get(main_link).text
qualities = re.findall(r'(\d+)/index.m3u8', index_list, flags=re.MULTILINE)
qualities = reversed(sorted(map(int, qualities)))
max_quality = int(self.plugin.get_setting('max_quality'))
selected = filter(lambda x: x <= max_quality, qualities)[0]
return '%s/%s/index.m3u8' % (main_link.replace('/index.m3u8', ''), selected)