6
6
#
7
7
from future import standard_library
8
8
standard_library .install_aliases ()
9
- from builtins import str
10
9
from builtins import object
11
- from resources .lib .powerunlimited_const import ADDON , LANGUAGE , IMAGES_PATH , HEADERS , convertToUnicodeString , log , getSoup
12
10
import os
13
- import re
14
11
import sys
15
12
import urllib .request , urllib .parse , urllib .error
16
13
import xbmcgui
17
14
import xbmcplugin
18
15
import requests
16
+ import json
17
+
18
+ from resources .lib .powerunlimited_const import ADDON , IMAGES_PATH , HEADERS , VIDEO_LIST_PAGE_URL , convertToUnicodeString , log
19
19
20
20
21
21
#
@@ -34,33 +34,6 @@ def __init__(self):
34
34
35
35
log ("ARGV" , repr (sys .argv ))
36
36
37
- # Parse parameters...
38
- self .plugin_category = urllib .parse .parse_qs (urllib .parse .urlparse (sys .argv [2 ]).query )['plugin_category' ][0 ]
39
- self .video_list_page_url = urllib .parse .parse_qs (urllib .parse .urlparse (sys .argv [2 ]).query )['url' ][0 ]
40
- self .next_page_possible = urllib .parse .parse_qs (urllib .parse .urlparse (sys .argv [2 ]).query )['next_page_possible' ][0 ]
41
-
42
- log ("self.video_list_page_url" , self .video_list_page_url )
43
-
44
- if self .next_page_possible == 'True' :
45
- # Determine current item number, next item number, next_url
46
- # http://www.pu.nl/media/pu-tv/?page=001/
47
- pos_of_page = self .video_list_page_url .rfind ('?page=' )
48
- if pos_of_page >= 0 :
49
- page_number_str = str (
50
- self .video_list_page_url [pos_of_page + len ('?page=' ):pos_of_page + len ('?page=' ) + len ('000' )])
51
- page_number = int (page_number_str )
52
- self .current_page = page_number
53
- page_number_next = page_number + 1
54
- if page_number_next >= 100 :
55
- page_number_next_str = str (page_number_next )
56
- elif page_number_next >= 10 :
57
- page_number_next_str = '0' + str (page_number_next )
58
- else :
59
- page_number_next_str = '00' + str (page_number_next )
60
- self .next_url = str (self .video_list_page_url ).replace (page_number_str , page_number_next_str )
61
-
62
- log ("self.next_url" , self .next_url )
63
-
64
37
#
65
38
# Get the videos...
66
39
#
@@ -73,126 +46,47 @@ def getVideos(self):
73
46
#
74
47
# Init
75
48
#
76
- # thumbnail_urls_index = 0
77
- list_item = ''
78
- # Create a list for our items.
49
+ # Create a list for our items
79
50
listing = []
80
51
81
52
#
82
53
# Get HTML page
83
54
#
84
- response = requests .get (self . video_list_page_url , headers = HEADERS )
55
+ response = requests .get (VIDEO_LIST_PAGE_URL , headers = HEADERS )
85
56
86
57
html_source = response .text
87
58
html_source = convertToUnicodeString (html_source )
88
59
89
- # Parse response
90
- soup = getSoup (html_source )
91
-
92
- # Get video-page-urls
93
- # <a class='article pu-tv featured' href='/media/video/pu-tv/parodie-replacer/'>
94
- # and not <a class='article' href='/games/briquid/'>
95
- video_page_url_items = soup .findAll ('a' , attrs = {'class' : re .compile ("^article" )})
96
-
97
- log ("len(video_page_url_items" , len (video_page_url_items ))
98
-
99
- for video_page_url_item in video_page_url_items :
100
-
101
- log ("video_page_url_item" , video_page_url_item )
102
-
103
- #<a class="article trailer featured" href="/media/video/trailer/pizza-connection-terug-trailer/"><span class="type"></span>
104
- # <article><div class="article-image">
105
- # <img alt="" src="http://cdn.pu.nl/thumbnails/144x123/e8a2a/pizza_maken.jpg" title=""/>
106
- # </div><header><h4><strong>Pizzaatjes bakken</strong> in Pizza Connection -<strong> trailer</strong></h4></header><div class="date hidden-phone">
107
-
108
- href = video_page_url_item ['href' ]
109
-
110
- # skip empty video link
111
- if str (href ) == '' :
112
-
113
- log ("skipped empty href" , href )
114
-
115
- continue
116
-
117
- # skip video link if starts with '/games/'
118
- if str (href ).startswith ("/games/" ):
119
-
120
- log ("skipped href with /games/" , href )
121
-
122
- continue
123
-
124
- # skip video link if starts with '/media/gallery/'
125
- if str (href ).startswith ("/media/gallery/" ):
126
-
127
- log ("skipped href with /media/gallery/" , href )
128
-
129
- continue
130
-
131
- # skip video link if starts with '/artikelen/'
132
- if str (href ).startswith ("/artikelen/" ):
133
-
134
- log ("skipped href with /artikelen/" , href )
135
-
136
- continue
137
-
138
- video_page_url = "http://www.pu.nl/media/video%s" % href
139
-
140
- log ("video_page_url" , video_page_url )
141
-
142
- # Make title
143
- # /media/video/pu-tv/parodie-replacer/
144
- # /media/video/trailer/old-republic-dlc-video-laat-nieuwe-planeet-zien/
145
- # remove the trailing /
146
- title = str (href )
147
- title = title [0 :len (title ) - len ('/' )]
148
- pos_of_last_slash = title .rfind ('/' )
149
- title = title [pos_of_last_slash + 1 :]
150
- title = title .capitalize ()
151
- title = title .replace ('-' , ' ' )
152
- title = title .replace ('/' , ' ' )
153
- title = title .replace (' i ' , ' I ' )
154
- title = title .replace (' ii ' , ' II ' )
155
- title = title .replace (' iii ' , ' III ' )
156
- title = title .replace (' iv ' , ' IV ' )
157
- title = title .replace (' v ' , ' V ' )
158
- title = title .replace (' vi ' , ' VI ' )
159
- title = title .replace (' vii ' , ' VII ' )
160
- title = title .replace (' viii ' , ' VIII ' )
161
- title = title .replace (' ix ' , ' IX ' )
162
- title = title .replace (' x ' , ' X ' )
163
- title = title .replace (' xi ' , ' XI ' )
164
- title = title .replace (' xii ' , ' XII ' )
165
- title = title .replace (' xiii ' , ' XIII ' )
166
- title = title .replace (' xiv ' , ' XIV ' )
167
- title = title .replace (' xv ' , ' XV ' )
168
- title = title .replace (' xvi ' , ' XVI ' )
169
- title = title .replace (' xvii ' , ' XVII ' )
170
- title = title .replace (' xviii ' , ' XVIII ' )
171
- title = title .replace (' xix ' , ' XIX ' )
172
- title = title .replace (' xx ' , ' XXX ' )
173
- title = title .replace (' xxi ' , ' XXI ' )
174
- title = title .replace (' xxii ' , ' XXII ' )
175
- title = title .replace (' xxiii ' , ' XXIII ' )
176
- title = title .replace (' xxiv ' , ' XXIV ' )
177
- title = title .replace (' xxv ' , ' XXV ' )
178
- title = title .replace (' xxvi ' , ' XXVI ' )
179
- title = title .replace (' xxvii ' , ' XXVII ' )
180
- title = title .replace (' xxviii ' , ' XXVIII ' )
181
- title = title .replace (' xxix ' , ' XXIX ' )
182
- title = title .replace (' xxx ' , ' XXX ' )
183
-
184
- log ("title" , title )
185
-
186
- # find thumbnail url
187
- start_pos_src_thumbnail_url = str (video_page_url_item ).find ('src="' )
188
- if start_pos_src_thumbnail_url >= 0 :
189
- start_pos_thumbnail_url = start_pos_src_thumbnail_url + len ('src="' )
190
- end_pos_thumbnail_url = str (video_page_url_item ).find ('"' , start_pos_thumbnail_url )
191
- thumbnail_url = str (video_page_url_item )[start_pos_thumbnail_url :end_pos_thumbnail_url ]
192
- else :
193
- thumbnail_url = ''
194
-
195
- log ("thumbnail_url" , thumbnail_url )
60
+ # let's try and select the json containing all the needed data from the web page source
61
+ index_start = html_source .find ('{"props"' )
62
+ # log("index", index_start)
63
+ index_end = html_source .rfind ('}' )
64
+ # log("index", index_end)
65
+ json_data = html_source [index_start :index_end + 1 ]
66
+ # log("json_data", json_data)
67
+
68
+ # load the json into the json parser
69
+ data = json .loads (json_data )
70
+
71
+ # Access the "mp4Url" properties for each video
72
+ mp4_urls = [video ['video' ]['video' ]['mp4Url' ] for video in data ['props' ]['pageProps' ]['_resources' ]['videos' ]]
73
+ # log("mp4_urls", mp4_urls)
74
+
75
+ # Access the "thumbnailUrl" properties for each video
76
+ thumbnail_urls = [video ['video' ]['video' ]['thumbnailUrl' ] for video in data ['props' ]['pageProps' ]['_resources' ]['videos' ]]
77
+ # log("thumbnail_urls", thumbnail_urls)
78
+
79
+ # Access the "title" properties for each video
80
+ titles = [video ['title' ] for video in data ['props' ]['pageProps' ]['_resources' ]['videos' ]]
81
+ # log("titles", titles)
82
+
83
+ mp4_urls_index = 0
84
+ for mp4_url in mp4_urls :
85
+
86
+ log ("mp4_url" , mp4_url )
87
+ title = titles [mp4_urls_index ]
88
+ thumbnail_url = thumbnail_urls [mp4_urls_index ]
89
+ video_page_url = mp4_urls [mp4_urls_index ]
196
90
197
91
# Add to list
198
92
list_item = xbmcgui .ListItem (label = title )
@@ -208,22 +102,7 @@ def getVideos(self):
208
102
# Add our item to the listing as a 3-element tuple.
209
103
listing .append ((url , list_item , is_folder ))
210
104
211
- # Next page entry
212
- if self .next_page_possible == 'True' :
213
- next_page = self .current_page + 1
214
- thumbnail_url = os .path .join (IMAGES_PATH , 'next-page.png' )
215
- list_item = xbmcgui .ListItem (LANGUAGE (30503 ))
216
- list_item .setArt ({'thumb' : thumbnail_url , 'icon' : thumbnail_url ,
217
- 'fanart' : os .path .join (IMAGES_PATH , 'fanart-blur.jpg' )})
218
- list_item .setProperty ('IsPlayable' , 'false' )
219
- parameters = {"action" : "list" , "plugin_category" : self .plugin_category , "url" : str (self .next_url ),
220
- "next_page_possible" : self .next_page_possible }
221
- url = self .plugin_url + '?' + urllib .parse .urlencode (parameters )
222
- is_folder = True
223
- # Add refresh option to context menu
224
- list_item .addContextMenuItems ([('Refresh' , 'Container.Refresh' )])
225
- # Add our item to the listing as a 3-element tuple.
226
- listing .append ((url , list_item , is_folder ))
105
+ mp4_urls_index = mp4_urls_index + 1
227
106
228
107
# Add our listing to Kodi
229
108
# Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
@@ -232,4 +111,4 @@ def getVideos(self):
232
111
# Disable sorting
233
112
xbmcplugin .addSortMethod (handle = self .plugin_handle , sortMethod = xbmcplugin .SORT_METHOD_NONE )
234
113
# Finish creating a virtual folder.
235
- xbmcplugin .endOfDirectory (self .plugin_handle )
114
+ xbmcplugin .endOfDirectory (self .plugin_handle )
0 commit comments