-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsg.py
67 lines (51 loc) · 2.12 KB
/
wsg.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
import sys
import xbmcgui, xbmcplugin
from urllib import urlencode
from urlparse import urlparse, parse_qsl
import requests
import re
from bs4 import BeautifulSoup as Soup
_url = sys.argv[0]
_handle = int(sys.argv[1])
_args = dict(parse_qsl(sys.argv[2][1:]))
index_url = 'https://boards.4chan.org/wsg/'
thread_url = 'https://boards.4chan.org/wsg/thread/%s'
def index(page=''):
soup = Soup(requests.get(index_url + str(page)).text, 'html.parser')
for br in soup.find_all("br"):
br.replace_with("\n")
for thread in soup.find_all(class_='thread'):
id_ = thread['id'][1:]
title = thread.div.find(class_='subject').text
description = thread.div.find(class_='postMessage').text
image = 'http:' + thread.div.img['src']
item=xbmcgui.ListItem(title)
item.setArt({'poster': image})
xbmcplugin.addDirectoryItem(_handle, url=_url+'?action=thread&id='+id_, listitem=item, isFolder=True)
if page == '': page = 1
item=xbmcgui.ListItem('Next Page (%s)' % (str(page+1)))
xbmcplugin.addDirectoryItem(_handle, url=_url+'?action=index&page='+str(page+1), listitem=item, isFolder=True)
xbmcplugin.endOfDirectory(_handle)
def thread(id_):
xbmcplugin.setContent(_handle, 'videos')
soup = Soup(requests.get(thread_url % (id_)).text, 'html.parser')
for file_ in soup.find_all(class_='file'):
name = file_.a.text
media = 'http:' + file_.a['href']
thumbnail = 'http:' + file_.img['src']
item=xbmcgui.ListItem(name, iconImage=thumbnail, thumbnailImage=thumbnail)
item.setArt({'poster': thumbnail})
item.setProperty('IsPlayable', 'true')
xbmcplugin.addDirectoryItem(_handle, url=media, listitem=item)
xbmcplugin.endOfDirectory(_handle)
if __name__ == '__main__':
if 'action' in _args:
if _args['action'] == 'thread':
thread(_args['id'])
if _args['action'] == 'index':
if 'page' in _args:
index(int(_args['page']))
else:
index()
else:
index()