forked from sacdroid/plugin.video.zeemarathi
/
addon.py
135 lines (98 loc) · 4.07 KB
/
addon.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
from BeautifulSoup import BeautifulSoup
import os.path
import sys
import urlparse
import xbmcplugin
from resources.lib import helpers as h
def main_index():
h.add_dir(addon_handle, base_url, 'Current Shows', SHOWS_URL, 'CurrentShows')
h.add_dir(addon_handle, base_url, 'Archive Shows', SHOWS_URL, 'ArchiveShows')
def current_shows():
url = h.extract_var(args, 'url')
soup = BeautifulSoup(h.make_request(url, cookie_file, cookie_jar))
# XXX: If want sorted
# import operator
# shows = {}
# shows[a_attrs['href']] = a_attrs['title']
# shows = sorted(shows.items(), key=operator.itemgetter(1))
# XXX: View mode thumbnail supported in xbmcswift2
h2 = soup.findAll('h2')
for h2 in soup.findAll('h2'):
if h2.text == 'Shows':
for li in h2.nextSibling.find('ul').findAll('li'):
a = li.find('a')
a_attrs = dict(a.attrs)
title = '%s (%s)' % (h.bs_find_with_class(a, 'div', 'zc-show-title').text, h.bs_find_with_class(a, 'div', 'zc-air-time').text)
img_src = dict(a.find('img').attrs)['src']
h.add_dir(addon_handle, base_url, title, '%s/video/' % a_attrs['href'], 'show', img_src, img_src)
break
def archive_shows():
url = h.extract_var(args, 'url')
soup = BeautifulSoup(h.make_request(url, cookie_file, cookie_jar))
h2 = soup.findAll('h2')
for h2 in soup.findAll('h2'):
if h2.text == 'Archive Shows':
for div in h.bs_find_all_with_class(h2.nextSibling, 'div', 'archive-show'):
a = div.find('a')
a_attrs = dict(a.attrs)
h.add_dir(addon_handle, base_url, a_attrs['title'], '%s/video/' % a_attrs['href'], 'show')
break
def show():
url = h.extract_var(args, 'url')
url = '%s%s' % (ZEEMARATHI_REFERRER, url)
soup = BeautifulSoup(h.make_request(url, cookie_file, cookie_jar))
ul = soup.find('ul', {'class': lambda x: x and 'show-videos-list' in x.split()})
for li in ul:
div = li.find('div', {'class': lambda x: x and 'video-watch' in x.split()})
episode_url = div.find('a')['href']
name = li.find('div', {'class': 'video-episode'}).text
img_src = 'DefaultFolder.png'
img = li.find('img')
if img:
img_src = img['src']
h.add_dir(addon_handle, base_url, name, episode_url, 'episode', img_src, img_src)
pager = soup.find('ul', {'class': lambda x: x and 'pager' in x.split()})
if pager:
next_link = pager.find('li', {'class': lambda x: x and 'pager-next' in x.split()})
if next_link:
next_url = next_link.find('a')['href']
if next_url:
h.add_dir(addon_handle, base_url, 'Next >>', next_url, 'show')
def episode():
url = h.extract_var(args, 'url')
name = h.extract_var(args, 'name')
soup = BeautifulSoup(h.make_request(url, cookie_file, cookie_jar))
div = soup.find('div', {'id': 'block-gec-videos-videopage-videos'})
script = None
scripts = div.findAll('script')
for s in scripts:
if 'babyenjoying' in s.text:
script = s
break
master_m3u8 = script.text.split('babyenjoying = ', 2)[2].split(';')[0][1:-1]
plot = soup.find('p', {'itemprop': 'description'}).text
thumbnail = soup.find('meta', {'itemprop': 'thumbnailUrl'})['content']
h.add_dir_video(addon_handle, name, master_m3u8, thumbnail, plot)
def not_implemented():
pass
ZEEMARATHI_REFERRER = 'http://www.zeemarathi.com'
SHOWS_URL = '%s/shows/' % ZEEMARATHI_REFERRER
addon_id = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
cookie_file, cookie_jar = h.init_cookie_jar(addon_id)
base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urlparse.parse_qs(sys.argv[2][1:])
mode = args.get('mode', ['', ])[0]
if mode == 'CurrentShows':
current_shows()
elif mode == 'ArchiveShows':
archive_shows()
elif mode == 'show':
show()
elif mode == 'episode':
episode()
elif mode == 'not_implemented':
not_implemented()
else:
main_index()
xbmcplugin.endOfDirectory(addon_handle)