-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaddon.py
1647 lines (1569 loc) · 73.3 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json, datetime
import calendar
from calendar import month_name, month_abbr
import os.path as path
import re
import urllib
import urlquick
from urlquick import get as UrlGet
try:
import urllib2
except:
pass
#from kodiswift import Plugin, xbmc, ListItem, download_page, clean_dict, SortMethod
from xbmcswift2 import Plugin, xbmc, ListItem, download_page, clean_dict, SortMethod, common
from xbmcswift2.common import download_page as DL
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
plugin = Plugin()
__addondir__ = xbmc.translatePath(plugin.addon.getAddonInfo('path'))
__resdir__ = path.join(__addondir__, 'resources')
__imgsearch__ = path.join(__resdir__, 'search.png')
lstSorts = [SortMethod.UNSORTED, SortMethod.LABEL]
HTML = None
try:
from HTMLParser import HTMLParser
HTML = HTMLParser()
except:
HTML = None
def makeVideoItems(itemlist, sitename=None):
"""
Takes a list of dict's returned from the API and looks for the specific fields to build XBMC ListItem for each item
:param itemlist:
:return: List of dict(Label, Label2, Icon, Thumb, Path) items created for each dict returned from the API
"""
litems = []
allitems = []
vitem = dict()
vid = dict()
item = dict()
SKIP = False
try:
for vitem in itemlist:
assert isinstance(vitem, dict)
vitem = clean_dict(vitem)
lbl = ''
lbl2 = ''
vcats = ''
tagstring = ''
plotstring = ''
thumbnail = ''
thumb2 = ''
thumbslist = []
length = ''
lengthnum = ''
vidid = ''
vurl = ''
views = ''
vtitle = ''
title = ''
pubdate = ''
reldate = ''
SITE = ''
if sitename is not None:
if sitename == 'surfgay':
sitename = 'surfgayvideos'
SITE = sitename
else:
sitename = ''
SITE = ''
if vitem.has_key('video'):
vid = vitem.get('video')
else:
vid = vitem
if vid is not None:
try:
assert isinstance(vid, dict)
if vid.has_key('url'):
vurl = vid.get('url')
elif vid.has_key('link'):
vurl = vid.get('link')
elif vid.has_key('embed'):
vurl = vid.get('embed')
if vurl.find('xtube') != -1 or vurl.find('spankwire') != -1:
SKIP = True
try:
if SITE is None or len(SITE)<1:
SITE = vurl.replace('http://', '').partition('/')[0].split('.', 1)[1].replace('.com', '').title()
except:
pass
SITE = sitename.lower()
if vid.has_key('default_thumb'):
thumbnail = vid.get('default_thumb')
elif vid.has_key('main_thumb'):
thumbnail = vid.get('main_thumb').replace(' ', '%20')
elif vid.has_key('thumbnail'):
if thumbnail == '':
thumbnail = vid.get('thumbnail')
else:
thumb2 = vid.get('thumbnail')
if vid.has_key('thumb'):
if thumbnail == '':
thumbnail = vid.get('thumb')
else:
thumb2 = vid.get('thumb')
if vid.has_key('views'):
views = vid.get('views')
if vid.has_key('duration'):
length = vid.get('duration')
if vid.has_key('length'):
length = vid.get('length')
elif vid.has_key('size'):
length = vid.get('size').get('seconds')
if vid.has_key('id'):
vidid = vid.get('id')
elif vid.has_key('video_id'):
vidid = vid.get('video_id')
else:
vidid = vurl.rsplit('-', 1)[0]
if vid.has_key('title'):
vtitle = vid.get('title').title().decode('utf-8', 'ignore') # .encode('ascii', 'ignore')
elif vitem.has_key('title'):
vtitle = vitem.get('title').title()
title = vtitle
if vid.has_key('publish_date'):
pubdate = vid.get('publish_date')
elif vitem.has_key('publish_date'):
pubdate = vitem.get('publish_date')
if len(pubdate) > 0:
reldate = pubdate
pubdate = pubdate.split(' ', 1)[0]
vtitle = vtitle.replace('"', '')
vtitle = vtitle.replace("'", '')
vtitle = vtitle.replace('*', '')
vtitle = vtitle.strip()
if len(vtitle) < 2:
vtitle = vurl.rpartition('/')[2]
lbl = vtitle.replace('&', 'and')
try:
if vid.has_key('category'):
vcats = vid.get('category')
plotstring = vcats
elif vid.has_key('categories'): # and not SKIP:
vcatlist = vid.get('categories')
vcats = str(vcatlist[:]).replace("category':", "")
plotstring = vcats.replace("{", "").replace("}", "").replace("u'", "").replace("'", "").strip('[]')
except:
pass
try:
if vid.has_key("tags") and SITE.lower().find('motherless') == -1: # and not SKIP:
tagslist = vid.get("tags")
tagstring = str(tagslist[:]).replace("tag_name':", "").replace("tag':", "").replace("{","").replace(
"}", "").replace("u'", "").replace("'", "").strip('[]')
except:
pass
if length == "00:00:00":
lengthnum = length
length = ''
elif len(length) > 0:
lengthnum = length
if length.find(':') == -1:
lenint = 0
seconds = int(length)
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
length = "%02d:%02d:%02d" % (h, m, s)
lengthnum = length
if vid.has_key('thumbs'):
thumbsdict = vid.get('thumbs')
if thumbsdict[0].has_key('src'):
for i in thumbsdict:
thumbslist.append(i.get('src'))
thumb2 = thumbslist[-1]
elif vitem.has_key('thumbs'):
if vitem.get('thumbs').has_key('big'):
thumbslist = vitem.get('thumbs').get('big')
thumb2 = thumbslist[-1]
lbl += ' {0} [COLOR yellow]{1}[/COLOR]\n[COLOR red]{2}[/COLOR]'.format(SITE, length, pubdate )
except:
xbmc.log("*****ERROR MAKING VIDEO ITEM PARSING FIELDS LOOPING TO NEXT ITEMS\n---- {0}\n".format(str(vid)))
#thumbnail = thumbnail.replace(' ', '%20')
plotstring += "\n" + thumbnail + ' '
lbl2 = "ID: {2} * Tags: {1} * {0} ".format(plotstring, tagstring, vidid)
if len(vtitle) < 3:
vtitle = vurl.partition('.com')[0]
#vtitle = urllib2.unquote(vtitle).replace('http://', '').partition('.')[2]
vpath = plugin.url_for(play, title=vtitle, video=thumbnail, url=vurl) #.encode('utf-8', 'ignore'))
#xli = ListItem(label=lbl, label2=lbl2, icon=thumbnail, thumbnail=thumbnail, path=vpath) #.encode('utf-8', 'ignore'))
xli = ListItem(label=lbl, label2=lbl2, icon=thumbnail, thumbnail=thumbnail, path=vpath) #.encode('utf-8', 'ignore'))
xli.thumbnail = thumbnail
xli.icon = thumbnail
xli.poster = vitem.get('main_thumb', 'DefaultVideo.png')
#xli.set_art({'thumbnail': thumbnail, 'poster': thumbnail, 'icon': thumbnail})
infolbl = {'Duration': lengthnum, 'Genre': SITE, 'Plot': plotstring + tagstring, 'Rating': views, 'Premiered': reldate, 'Year': reldate, 'Title': title}
xli.set_info('video', info_labels=infolbl)
#thumb2 = ''
#if thumb2 != '':
# if len(thumbslist) > 0:
# xli.poster = thumbslist[0]
# xli.thumbnail = thumbslist[1]
# xli.icon = thumbslist[2]
# #xli.set_art({'fanart': thumbslist[-1]})
# else:
# xli.poster = thumb2
#xli.set_art({'fanart': thumb2})
xli.playable = True
litems.append(xli)
except:
xbmc.log("***LAST FAIL AFTER ALL ITEMS -- ERROR MAKINGVIDEOITEMS: {0}\n".format(vitem))
if plugin.get_setting('sortresultsby') == 'date':
litems.sort(key=lambda litems: litems.label)
return litems
def parseVideosUrl(url):
"""
Sends request to API and returns the JSON object as a List of Dicts which is parsed into XBMC ListItems by makeVideoItems
:param url:
:return: List(dict())
"""
obj = dict()
resp = None
webresp = None
if url.find('xtube.com') != -1 or url.find('motherless') != -1: obj = []
headers = {}
headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36'})
headers.update({'Accept': 'application/json,text/x-json,text/x-javascript,text/javascript,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;charset=utf-8'})#;charset=utf8'})
headers.update({'Accept-Language': 'en-US,en;q=0.5'})
# resp = urllib2.urlopen(req).read()
try:
try:
req = urllib.request.Request(url, data=None, headers=headers)
webresp = urlopen(req)
resp = webresp.read()
except:
try:
from urllib2 import Request
req = Request(url, headers=headers)
webresp = urllib2.urlopen(req)
resp = webresp.read()
except:
pass
obj = json.loads(resp.decode('latin', 'ignore'))
assert isinstance(obj, dict)
obj = clean_dict(obj)
if url.find('xtube.com') != -1:
tlist = []
for i in obj.iterkeys(): tlist.append(obj.get(i))
return tlist
except:
try:
webresp = urlquick.get(url) # download_page(url)
obj = webresp.json()
except:
obj = None
try:
newobj = []
assert isinstance(obj, list)
for ditem in obj:
assert isinstance(ditem, dict)
newobj.append(clean_dict(ditem))
obj = newobj
except:
pass
if url.find('xtube.com') != -1 or url.find('motherless') != -1: return obj
try:
if len(obj.keys()) == 1:
return obj.get(obj.keys()[0])
elif obj.has_key('videos'):
return obj.get('videos')
elif obj.has_key('data'):
return obj.get('data')
else:
return obj
except:
xbmc.log("*** PARSE ERROR \n{0}".format(resp))
return None
def readjson(filename='allcats.json'):
dictallcats = dict()
try:
txt = file(path.join(__addondir__, 'resources', filename), 'r').read()
dictallcats = json.loads(txt) # dictallcats = json.JSONDecoder().decode(txt)
if len(dictallcats.keys) == 1:
return dictallcats.get(dictallcats.get(dictallcats.keys[0]))
else:
return dictallcats
except:
return []
def savejson(obj, filename):
try:
f = file(filename, 'w')
txt = json.dump(obj, f)
f.close()
except:
pass
def myvidster():
url = ""
resp = urlquick.get(url)
src = resp.content
html = src.rpartition('<ul class="slides clearfix">')[-1].split('<div class="pagination">',1)[0]
matches = re.findall('href="(.+?)">(.+?)</a>', html)
def catlist_tube8(isGay=True):
urlapi = "http://api.tube8.com/api.php?action=getcategorieslist&output=json"
turl = getAPIURLS('tube8').replace('search=&', 'search={0}&')
turl = turl.replace('search=gay&', 'search={0}+gay&')
resp = ''
litems = []
allitems = []
catlist = []
resp = DL(urlapi)
#resp = urllib2.urlopen(urlapi).read()
obj = json.loads(unicode(resp).decode('latin', 'ignore'))
try:
if isGay:
catlist = obj.get("gay")
else:
catlist = obj.get("straight")
for catname in catlist:
cname = catname.title()
cimg = 'DefaultFolder.png'
curl = turl.format(catname)
cpath = plugin.url_for(site, sitename='tube8', section='index', url=curl)
citem = dict(label=cname, icon=cimg, thumbnail=cimg, path=cpath)
citem.setdefault(citem.keys()[0])
allitems.append(citem)
litems = sorted(allitems, key=lambda allitems: allitems['label'])
except:
pass
return finish(litems)
def catlist_xtube():
urlapi = "http://www.xtube.com/webmaster/api.php?action=getCategoryList"
gturl = getAPIURLS('xtube')
gturl = gturl.replace('&category=&', '&category={0}&')
resp = ''
html = ''
catlist = []
litems = []
allitems = []
resp = DL(urlapi)
#resp = urllib2.urlopen(urlapi).read()
obj = json.loads(unicode(resp).decode('latin', 'ignore'))
try:
assert isinstance(obj, list)
for item in obj:
assert isinstance(item, dict)
catlist.append(item.values().pop())
for catname in catlist:
cimg = 'DefaultFolder.png'
curl = gturl.format(urllib.quote_plus(catname))
cpath = plugin.url_for(site, sitename='xtube', section='index', url=curl)
citem = dict(label=catname.title(), icon=cimg, thumbnail=cimg, path=cpath)
citem.setdefault(citem.keys()[0])
allitems.append(citem)
litems = sorted(allitems, key=lambda allitems: allitems['label'])
except:
pass
return finish(litems)
def catlist_youporn():
urlapi = "http://www.youporn.com/api/webmasters/categories/"
gturl = getAPIURLS('youporn')
gturl = gturl.replace('&category=&', '&category={0}&')
resp = ''
html = ''
catlist = []
litems = []
allitems = []
resp = DL(urlapi)
#resp = urllib2.urlopen(urlapi).read()
obj = json.loads(unicode(resp).decode('latin', 'ignore'))
try:
assert isinstance(obj, list)
for item in obj:
assert isinstance(item, dict)
catlist.append(item.values().pop())
for catname in catlist:
# assert isinstance(catname, dict)
# cname = catname.get('category')
cimg = 'DefaultFolder.png'
curl = gturl.format(urllib.quote_plus(catname))
cpath = plugin.url_for(site, sitename='youporn', section='index', url=curl)
citem = dict(label=catname.title(), icon=cimg, thumbnail=cimg, path=cpath)
citem.setdefault(citem.keys()[0])
allitems.append(citem)
litems = sorted(allitems, key=lambda allitems: allitems['label'])
except:
pass
return finish(litems)
def catlist_gaytube():
# urlhtml = "http://www.gaytube.com/c/abc?m=azl"
# Above is to try and scrape category pictures so defaultfolder doesn't have to be used but can't get a Regex to work
urlapi = "http://www.gaytube.com/api/webmasters/categories/"
gturl = getAPIURLS('gaytube').replace('&category=', '&category={0}')
resp = ''
html = ''
catlist = []
litems = []
allitems = []
resp = download_page(urlapi).decode('utf-8', 'ignore')
obj = json.loads(resp)
catlist = obj.get('categories')
try:
for catname in catlist:
assert isinstance(catname, dict)
cname = catname.get('category')
cimg = 'DefaultFolder.png'
curl = gturl.format(urllib.quote_plus(cname))
cpath = plugin.url_for(site, sitename='gaytube', section='index', url=curl)
citem = dict(label=cname.title(), icon=cimg, thumbnail=cimg, path=cpath)
citem.setdefault(citem.keys()[0])
allitems.append(citem)
litems = sorted(allitems, key=lambda allitems: allitems['label'])
except:
pass
return finish(litems)
def catlist_pornhub():
urlapi = "http://www.pornhub.com/webmasters/categories"
gturl = getAPIURLS('pornhub')
ISGAY = True
if gturl.find('=gay') != -1:
gturl = gturl.replace('&category=gay&', '&category={0}&')
else:
ISGAY = False
gturl = gturl.replace('&category=&', '&category={0}&')
resp = ''
html = ''
catlist = []
litems = []
allitems = []
resp = download_page(urlapi).decode('utf-8', 'ignore')
obj = json.loads(resp)
#resp = DL(urlapi)
#resp = urllib2.urlopen(urlapi).read()
#obj = json.loads(unicode(resp).decode('ascii'))
catlist = obj.get('categories')
try:
for catname in catlist:
assert isinstance(catname, dict)
cname = catname.get('category')
cimg = 'DefaultFolder.png'
curl = gturl.format(urllib.quote_plus(cname))
cpath = plugin.url_for(site, sitename='pornhub', section='index', url=curl)
citem = dict(label=cname.title(), icon=cimg, thumbnail=cimg, path=cpath)
citem.setdefault(citem.keys()[0])
if ISGAY and cname.find('gay') != -1:
allitems.append(citem)
if not ISGAY and cname.find('gay') == -1:
allitems.append(citem)
litems = sorted(allitems, key=lambda allitems: allitems['label'])
except:
pass
return finish(litems)
def catlist_redtube():
urlapi = "http://api.redtube.com/?data=redtube.Categories.getCategoriesList&output=json"
gturl = getAPIURLS('redtube').replace('&category=&', '&category={0}&')
resp = ''
html = ''
catlist = []
litems = []
allitems = []
resp = DL(urlapi)
#resp = urllib2.urlopen(urlapi).read()
obj = json.loads(unicode(resp).decode('ascii'))
catlist = obj.get('categories')
try:
for catname in catlist:
assert isinstance(catname, dict)
cname = catname.get('category')
cimg = 'DefaultFolder.png'
curl = gturl.format(urllib.quote_plus(cname))
cpath = plugin.url_for(site, sitename='redtube', section='index', url=curl)
citem = dict(label=cname.title(), icon=cimg, thumbnail=cimg, path=cpath)
citem.setdefault(citem.keys()[0])
allitems.append(citem)
litems = sorted(allitems, key=lambda allitems: allitems['label'])
except:
pass
return finish(litems)
def groupslist_motherless():
vitems = []
litems = []
allitems = []
listofurls = groupurls_motherless()
for url in listofurls:
try:
vitems = parseVideosUrl(url)
litems = makeVideoItems(vitems)
allitems.extend(litems)
except:
xbmc.log("Failed parsing URL {0}".format(url))
allitems.sort(key=lambda allitems: allitems.label)
return finish(allitems)
def groupurls_motherless():
MOGROUPS2 = ['straight_men_having_fun_with_men', 'twinks', 'debbie_hearts_favorite_twinks', 'mmmmm_boys',
'selfshot_guys', 'boy_twink_ass', 'male_oral_sex_boys_18_', 'gay_incest', 'amateur_boys',
'naked_men_in_public', 'amateur_male_masturbation']
MOGROUPS = ['amateur_boys', 'daddies___bros___bears_oh_my_', 'amateur_male_masturbation', 'naked_men_in_public',
'twinks', 'debbie_hearts_favorite_twinks', 'straight_men_having_fun_with_men', 'men_gay_homosexuals',
'real_hardcore_gay_group', 'selfshot_guys', 'boy_twink_ass', 'male_oral_sex_boys_18_',
'nude_men_at_the_beach', 'gay_incest', 'father___son', '_gay_incest___family_fun_']
burl = "http://motherless.com/feeds/groups/{0}/videos?page=1&format=json"
# burl = str(getAPIURLS(sitename='motherless'))
grouplist = []
for grp in MOGROUPS:
grouplist.append(burl.format(grp))
return grouplist
def allcats_make():
litems = []
catlist = []
allcatslist = []
urltpl_list = []
allitems = []
caturls = getAPIURLS('CATEGORIES')
DOSTR8 = plugin.get_setting(key='dostr8')
if not (DOSTR8 == True or DOSTR8 == 'true'): DOSTR8 = False
else: DOSTR8 = True
for sitename, urlapi in caturls.items():
resp = ''
html = ''
resp = DL(urlapi).decode('utf-8', 'ignore')
obj = json.loads(resp)
if isinstance(obj, list):
for item in obj:
if isinstance(item, dict): catlist.append(item.values().pop())
elif isinstance(obj, dict):
if obj.has_key('categories'):
catlist = obj.get('categories')
elif obj.has_key('gay'):
catlist = obj.get("gay")
elif obj.has_key('straight'):
catlist = obj.get("straight")
if isinstance(catlist[0], dict):
newcatlist = []
for item in catlist: newcatlist.append(item.values().pop())
catlist = newcatlist
for catname in catlist:
catname = catname.replace('-gay','')
catname = catname.replace('&', ' ').replace('/',' ').replace('-', ' ')
catname = catname.split(' ', 1)[0]
catname = catname.lower()
if not catname.endswith('s'): catnameplural = catname.lower()+'s'
else: catnameplural = catname.lower()
if catnameplural in allcatslist:
pass
elif catname in allcatslist:
pass
else:
allcatslist.append(catname.lower())
allcatslist.sort()
allitems = []
for catname in allcatslist:
cimg = 'DefaultFolder.png'
cimgname = catname.title().replace(' ', '').replace('&', '').replace('/','')
cimg = __imgsearch__.replace('search.png', 'caticons/{0}.jpg'.format(cimgname))
if not (path.exists(cimg) and path.isfile(cimg)):
cimg = "http://cdn2.static.spankwire.com/images/category/Gay/{0}.jpg".format(cimgname)
try:
#resp = urllib2.urlopen(cimg)
resp = DL(cimg)
if resp.getcode() == 404: cimg = 'DefaultFolder.png'
except:
cimg = 'DefaultFolder.png'
cpath = plugin.url_for(category, catname=catname.title())
citem = dict(label=catname.title(), icon=cimg, thumbnail=cimg, path=cpath)
citem.setdefault(citem.keys()[0])
allitems.append(citem)
savejson(allitems, __imgsearch__.replace('search.png', 'allcats.json'))
return allitems
def getAPIURLS(sitename=None):
"""
If a sitename is passes then just the URL to that sites API is returned if nothing is passed then a dictionary of Key=Sitename, Value=API URL is returned
This function handles looking at the Plugin Settings to determine the Sorting/Ordering which defaults to NEWEST
bugs still exist on ordering as dif API's use a dif word for other sortings but NEWEST works on all
STR8 setting is checked and if it is enabled then the correct URL's are selected which doesn't specify segment=gay or gay in tags/search
:param sitename:
:return: URL of API for sitename specified or DICT(sitename: URL, sitename2: URL)
"""
b = "http://www."
a = "http://api."
sitecatsapis = dict(spankwire=b+"spankwire.com/api/HubTrafficApiCall?data=getCategoriesList&output=json&segment=gay",
xtube=b+"xtube.com/webmaster/api.php?action=getCategoryList",
youporn=b+"youporn.com/api/webmasters/categories/",
gaytube=b+"gaytube.com/api/webmasters/categories/",
pornhub=b+"pornhub.com/webmasters/categories",
redtube=a+"redtube.com/?data=redtube.Categories.getCategoriesList&output=json",
tube8=a+"tube8.com/api.php?action=getcategorieslist&output=json")
siteapis = dict(
gaytube=b+"gaytube.com/api/webmasters/search/?ordering=newest&period=alltime&thumbsize=preview&category=&page=1&search=&tags[]=&count=250",
pornhub=b+"pornhub.com/webmasters/search?id=44bc40f3bc04f65b7a35&category=gay&ordering=newest&tags[]=gay&search=&page=1&thumbsize=large",
redtube=a+"redtube.com/?data=redtube.Videos.searchVideos&output=json&thumbsize=big&ordering=newest&page=1&search=&tags[]=gay&category=&period=alltime",
spankwire=b+"spankwire.com/api/HubTrafficApiCall?data=searchVideos&output=json&ordering=newest&page=1&segment=gay&count=100&search=&tags=gay&thumbsize=big",
tube8=a+"tube8.com/api.php?action=searchVideos&output=json&ordering=newest&search=gay&thumbsize=big&page=1&orientation=gay",
xtube=b+"xtube.com/webmaster/api.php?action=getVideosBySearchParams&tags=&ordering=newest&thumbsize=400x300&fields=title,tags,duration,thumbnail,url,embed,categories&search=gay&category=&page=1&count=100",
youporn=b+"youporn.com/api/webmasters/search?search=&page=1&ordering=newest&tags[]=gay&category=&thumbsize=big",
motherless=b+"motherless.com/feeds/tags/gay/videos?format=json&limit=250&offset=0",
motherless_search=b+"motherless.com/feeds/search/gay+{0}/videos?format=json&sort=date&offset=0&limit=250",
porkytube=b+"porkytube.com/api/?output=json&command=media.newest&type=videos&offset=0&page=1&amount=500",
porkytube_search=b+"porkytube.com/api/?output=json&command=media.search&q={0}&type=videos&offset=0&page=1&amount=500",
surfgay=b+"surfgayvideo.com/api/?output=json&command=media.newest&type=videos&offset=0&page=1&amount=500",
surfgay_search=b+"surfgayvideo.com/api/?output=json&command=media.search&q={0}&type=videos&offset=0&page=1&amount=500")
#porn5=b+'porn5.com/api/videos/find.json?cats=gay&limit=250&page=1&search=&order=date',
#bonertube=b + 'bonertube.com/api/?output=json&command=media.newest&type=videos&offset=0&page=1&amount=500',
#bonertube_search=b+'bonertube.com/api/?output=json&command=media.search&q={0}&type=videos&offset=0&page=1&amount=500')
urls_straight = dict(
gaytube=b + "gaytube.com/api/webmasters/search/?ordering=newest&period=alltime&thumbsize=all&count=100&page=1&search=&tags[]=",
pornhub=b + "pornhub.com/webmasters/search?id=44bc40f3bc04f65b7a35&category=&ordering=newest&tags[]=&search=&page=1&thumbsize=medium",
redtube=a + "redtube.com/?data=redtube.Videos.searchVideos&output=json&thumbsize=medium&ordering=newest&page=1&search=&tags[]=&category=&period=alltime",
spankwire=b + "spankwire.com/api/HubTrafficApiCall?data=searchVideos&output=json&ordering=newest&page=1&segment=straight&count=100&search=&tags=&thumbsize=all",
tube8=a + "tube8.com/api.php?action=searchVideos&output=json&ordering=newest&search=&thumbsize=big&page=1&orientation=straight",
xtube=b + "xtube.com/webmaster/api.php?action=getVideosBySearchParams&tags=&ordering=newest&thumbsize=400x300&fields=title,tags,duration,thumbnail,url,embed,categories&search=&category=&page=1&count=100",
youporn=b + "youporn.com/api/webmasters/search?search=&page=1&ordering=newest&tags[]=&category=&thumbsize=medium",
motherless=b+"motherless.com/feeds/search/{0}/videos?format=json&offset=0&limit=250&sort=date")
DOSTR8 = plugin.get_setting(key='dostr8')
DOFILTER = plugin.get_setting(key='dofilter')
if DOFILTER == 'true' or DOFILTER == True:
DOFILTER = True
else:
DOFILTER = False
MYTAGS = plugin.get_setting(key='tags').replace(',', '+')
ORDERBY = plugin.get_setting(key='sortby')
if DOSTR8 == True or DOSTR8 == 'true':
DOSTR8 = True
siteapis = urls_straight
sitecatsapis.update(spankwire=b+"spankwire.com/api/HubTrafficApiCall?data=getCategoriesList&output=json&segment=straight")
if ORDERBY != 'newest':
urlstemp = siteapis
tempdict = dict()
for k, v in urlstemp.iteritems():
url = v.replace('ordering=newest', 'ordering={0}'.format(ORDERBY))
tempdict.update(k=url)
siteapis = tempdict
if DOFILTER and len(MYTAGS) > 0:
urlstemp = siteapis
tempdict = dict()
if not DOSTR8:
for k, v in urlstemp.iteritems():
newurl = str(v).replace('&tags[]=gay&', '&tags[]=gay+{0}&'.format(MYTAGS))
newurl = newurl.replace('&tags[]=&', '&tags[]={0}&'.format(MYTAGS))
newurl = newurl.replace('&tags=&', '&tags={0}&'.format(MYTAGS))
newurl = newurl.replace('&tags=gay&', '&tags=gay+{0}&'.format(MYTAGS))
tempdict.update(k=newurl)
siteapis.update(tempdict)
else:
for k, v in urlstemp.iteritems():
newurl = str(v).replace('&tags[]=&', '&tags[]={0}&'.format(MYTAGS))
newurl = newurl.replace('&tags=&', '&tags={0}&'.format(MYTAGS))
tempdict.update(k=newurl)
siteapis.update(tempdict)
if sitename is None:
return siteapis
else:
if sitename == 'CATEGORIES' or sitename == 'CATS':
return sitecatsapis
if siteapis.has_key(sitename):
return siteapis.get(sitename)
else:
return siteapis
def find_video(url):
matches = None
vidurl = ''
vidhtml = ''
try:
vidhtml = download_page(url).decode('utf-8', 'ignore')
if url.find('youporn') != -1:
matches = re.compile(ur'.(http://cdn.+?mp4.+?[^"])"', re.DOTALL + re.S + re.U).findall(vidhtml)
elif url.find('porkytube') != -1:
matches = re.compile(ur'href="(http://porkytube.com/media/videos/.+?)"', re.DOTALL + re.S + re.U).findall(vidhtml)
elif url.find('bonertube') != -1:
matches = re.compile(ur'.["\'](http://.+?mp4)["\'].', re.DOTALL + re.S + re.U).findall(vidhtml)
elif url.find('tube8') != -1:
matches = re.compile(ur'["\'](http://cdn.+?public.+?mp4.+?)["\']', re.DOTALL + re.S + re.U).findall(vidhtml)
elif url.find('xtube') != -1:
matches = re.compile(ur'"(http.+?mp4.+?[^"])"', re.DOTALL + re.S+re.U).findall(vidhtml)
elif url.find('gaytube') != -1:
matches = re.compile(ur'p="(http.+?mp4.+?[^"])"', re.DOTALL + re.S+re.U).findall(vidhtml)
elif url.find('pornhub') != -1:
matches = re.compile(ur'.(http.+?mp4.ipa=.+?[^\'])\'', re.DOTALL + re.S+re.U).findall(vidhtml)
elif url.find('redtube') != -1:
matches = re.compile(ur'="(http.+?mp4.+?[^"])"', re.DOTALL + re.S+re.U).findall(vidhtml)
elif url.find('spankwire') != -1 or url.find('motherless') != -1:
matches = re.compile(ur"'(http.+?mp4.+?[^'])'", re.DOTALL + re.S+re.U).findall(vidhtml)
except:
xbmc.log("\n****Failed to Resolve VID URL from REGEXes {0}\n{1}".format(url, str(repr(matches))))
if matches is not None:
vidurl = matches[0]
vidurl = vidurl.replace('&', '&')
vidurl = vidurl.replace('http%3A%2F%2F', 'http://')
vidurl = vidurl.replace('%2F','/')
vidurl = vidurl.replace('%3F','?')
vidurl = vidurl.replace('%3D', '=')
if vidurl.startswith('http:\/\/'):
vidurl = vidurl.replace('\/', '/')
if vidurl.startswith('http:///'):
urlparts = vidurl.split(':///')
urlp2 = urlparts[1].replace('//', '/')
vidurl = "http://{0}".format(urlp2)
return vidurl
else:
return matches
@plugin.route('/tumblrhome')
def tumblrhome():
blogname = 'gaypublicvideos'
blogurlbase = "http://{0}.tumblr.com"
blogs = plugin.get_setting('tumblrblog')
bloglist = blogs.split('|')
nowd = datetime.datetime.now()
litems = []
thre = re.compile(r'link rel=.+icon.+href="(http://68.media.tumblr.com/avatar_.+)"')
titlere = re.compile(r'property="og:title" content="(.+[^"])" />')
aboutre = re.compile(r'property="og:description" content="(.+[^"])" />')
DEBUG = bool(plugin.get_setting('debugon'))
if DEBUG:
for blog in bloglist:
path = plugin.url_for(endpoint=tumblr, blogname=blog, year=nowd.year.numerator, month=nowd.month.numerator, mostrecent=False)
li = ListItem(label=blog, label2=blogurlbase.format(blog), icon='DefaultFolder.png', thumbnail='DefaultFolder.png', path=path)
litems.append(li)
else:
if len(bloglist) > 100:
bloglist = bloglist[0:100]
for blog in bloglist:
html = DL(blogurlbase.format(blog)).decode('utf-8')
matchest = titlere.findall(html)
matchesd = aboutre.findall(html)
blogtitle = u''
blogabout = u''
bloglabel = blog.title()
if len(matchest) > 0:
blogtitle = matchest.pop().split('"',1)[0]
if len(matchesd) > 0:
blogabout = matchesd.pop().split('"',1)[0]
if len(blogabout) > 22:
blogabout = blogabout[:22].strip() + ".."
if HTML is not None:
blogtitle = HTML.unescape(blogtitle).title()
blogabout = HTML.unescape(blogabout).title()
if len(blogtitle) < 2:
blogtitle = blog
if blogtitle.lower().find('untitled') != -1:
blogtitle = blog
bloglabel = blogtitle + "\n" + blogabout
matches = thre.findall(html)
blogthumb = 'DefaultFolder.png'
if len(matches) > 0:
blogthumb = matches.pop().split('"',1)[0]
li = {'label': bloglabel, 'label2': blogabout, 'icon': blogthumb, 'thumbnail': blogthumb, 'path': plugin.url_for(endpoint=tumblr, blogname=blog, year=nowd.year.numerator, month=nowd.month.numerator, mostrecent=False)}
li.setdefault(li.keys()[0])
item = ListItem.from_dict(**li)
item.set_info('video', {'genre': blog, 'year': blogabout})
item.set_property('genre', blog)
item.set_property('year', blogabout)
litems.append(item)
#plugin.add_items(items=litems)
return finish(litems)
@plugin.route('/playtumblr/<url>')
def playtumblr(url):
vidurl = None
try:
import YDStreamExtractor
info = YDStreamExtractor.getVideoInfo(url, resolve_redirects=True)
vidurl = info.streamURL()
except:
vidurl = url
if vidurl is not None:
#xbmc.Player().play(vidurl)
plugin.set_resolved_url(vidurl)
vitem = ListItem(label='Tumblr', label2=str(vidurl), icon='DefaultVideo.png', thumbnail='DefaultVideo', path=vidurl)
vitem.set_info('video', {'Title': 'Tumblr {0}'.format(url), 'Plot': vidurl})
vitem.set_is_playable(True)
vitem.add_stream_info(stream_type='video', stream_values={})
return vitem
return None
def tumblrhtml(url, section="START CONTENT", sectionend="END CONTENT"):
# section="Following"
htmlbit = download_page(url).split('<!-- {0} -->'.format(section), 1)[-1]
htmlbit = htmlbit.split('<!-- {0} -->'.format(sectionend), 1)[0]
return htmlbit
def tumblrfollows():
fre = re.compile(r'<a href="https://(.+)\.tumblr.com/".*?data-tumblelog-popover="(.*?)"', re.M)
furl = "https://api.tumblr.com/v2/user/following"
tumblrauth = { 'consumer_key': '5wEwFCF0rbiHXYZQQeQnNetuwZMmIyrUxIePLqUMcZlheVXwc4', 'consumer_secret': 'GCLMI2LnMZqO2b5QheRvUSYY51Ujk7nWG2sYroqozW06x4hWch', 'token': '7IuPrj2L6cfxMwOdbWV8yYYFafopwrYR3RYSdIc8YxMKJc8Dl5', 'token_secret': 'WSnl65etymR8m5KuK3rAX67emMCYzASpLrzIHQ2SKejYSqZmmh'}
urlfollows = "https://api.tumblr.com/v2/user/following?limit=250"
headers = {'Authorization': 'OAuth oauth_consumer_key = "5wEwFCF0rbiHXYZQQeQnNetuwZMmIyrUxIePLqUMcZlheVXwc4", oauth_nonce = "XiuBW4", oauth_signature = "N2hLobvUJd%2BK8OMZKr2YLlLC99M%3D", oauth_signature_method = "HMAC-SHA1", oauth_timestamp = "1485035014", oauth_token = "7IuPrj2L6cfxMwOdbWV8yYYFafopwrYR3RYSdIc8YxMKJc8Dl5", oauth_version = "1.0"'}
#req = urllib2.Request(url=urlfollows, headers=headers)
req = DL(urlfollows)
@plugin.route('/tumblr/<blogname>/<year>/<month>/<mostrecent>')
def tumblr(blogname, year, month, mostrecent):
year = int(year)
month = int(month)
mostrecent = bool(mostrecent)
fal = re.compile(r'class="post_thumb.+data-imageurl="(http://media.tumblr.com/tumblr.+frame1.jpg)".*?href="(http://.+tumblr.com/post/.+)".+data-peepr=".*?post_date">([^<]*)<', re.M+re.I)
months = {v: k for k, v in enumerate(calendar.month_abbr)}
blogurl = "http://{0}.tumblr.com".format(blogname)
dateurl = blogurl + "/archive/{0}/{1}"
recenturl = blogurl + "/archive/filter-by/video"
vids = []
lyear = ''
lmonth = ''
url = ''
link = ''
html = ''
pubdate = ''
numpages = 0
nowd = datetime.datetime.now()
if nowd.year == year and nowd.month == month:
for monthnum in range(nowd.month, 0, -1):
url = dateurl.format(nowd.year, monthnum)
html += tumblrhtml(url)
numpages += 1
endmonth = numpages
year = nowd.year - 1
for monthnum in range(12, endmonth, -1):
url = dateurl.format(year, monthnum)
htmlbit = tumblrhtml(url)
numpages += 1
if len(htmlbit) > 0:
html += htmlbit
else:
break
else:
for monthnum in range(int(month), 0, -1):
url = dateurl.format(year, monthnum)
html += tumblrhtml(url)
numpages += 1
endmonth = numpages
year -= 1
for monthnum in range(12, endmonth, -1):
url = dateurl.format(year, monthnum)
htmlbit = tumblrhtml(url)
numpages += 1
if len(htmlbit) > 0:
html += htmlbit
else:
break
matches = fal.findall(html) # list(set(fal.findall(html)))
for thumbnail, url, dateof in matches:
try:
putdate = dateof.strip()
monthstring, yearstr = putdate.split(',', 1)
lyear = int(x=yearstr.strip())
lmonths, ldays = monthstring.strip().split(' ', 1)
lday = int(x=ldays.strip())
shortmonth = lmonths.strip()[0:3]
lmonth = months.get(shortmonth.title())
numberdate = datetime.date(lyear, lmonth, lday)
itemname = url.rpartition('/')[-1]
if itemname.isdigit(): itemname = blogname
itemname = itemname.replace('-', ' ').title()
#lbl2 = '{0} | {1}'.format(putdate, blogname)
lbl = "{0}\n[COLOR yellow]({1})[/COLOR]".format(itemname, putdate)
plugpath = plugin.url_for(playtumblr, url=url)
li = {'label': lbl, 'label2': url, 'thumbnail': thumbnail, 'icon': thumbnail, 'path': plugpath, 'is_playable': True,'is_folder': False, 'info_type': 'video', 'info_labels': {}}
li.setdefault(li.keys()[0])
item = ListItem.from_dict(**li)
vids.append(li)
except:
plugin.log.error("Failed to add item")
imgnext = __imgsearch__.replace("search.", "next.")
lbl = '-> Before {0} {1} ->'.format(month_abbr[lmonth], lyear)
nextyear = lyear
if lmonth > 1:
nextmonth = lmonth - 1
else:
nextyear = nextyear - 1
nextmonth = 12
urlnext = plugin.url_for(endpoint=tumblr, blogname=blogname, year=int(nextyear), month=int(nextmonth), mostrecent=False)
nextitem = {'label': lbl, 'label2': 'ZZZ next', 'thumbnail': imgnext, 'icon': imgnext, 'path': urlnext}
nextitem.setdefault(nextitem.keys()[0])
vids.append(nextitem)
litems = []
for item in vids:
litem = ListItem.from_dict(**item)
if litem.label2 != 'ZZZ next':
litem.add_context_menu_items([('Download', 'RunPlugin("{0}")'.format(
plugin.url_for(download, name=item.get('label'), url=item.get('label2'))),)])
litems.append(litem)
return finish(litems)
@plugin.route('/')
def index():
"""
Index for plugin this just builds the main items for the site's linked to the SITEROOT destination
:return: List of ListItems for Index of all sites
"""
litems = []
allitems = []
viewmode = int(plugin.get_setting('viewmode'))
if viewmode is None: viewmode = 500
plugin.set_view_mode(viewmode)
DOSTR8 = plugin.get_setting(key='dostr8')
if not (DOSTR8 == True or DOSTR8 == 'true'): DOSTR8 = False
else: DOSTR8 = True
for sitename in getAPIURLS().keys():
if sitename.find('_search') == -1:
sicon = __imgsearch__.replace('search.', 'f{0}.'.format(sitename))
spath = plugin.url_for(site, sitename=sitename, section='index', url='0')
sitem = {'label': sitename.title(), 'icon': sicon, 'thumbnail': sicon, 'path': spath}
sitem.setdefault(sitem.keys()[0])
litems.append(sitem)
allitems = sorted(litems, key=lambda litems: litems['label'])
ifolder = __imgsearch__.replace('search.', 'folder.')
itemallcats = {'label': 'Global Category List', 'path': plugin.url_for(allcats), 'icon': ifolder,
'thumbnail': ifolder}
itemsearch = {'label': 'Search All Sites', 'path': plugin.url_for(search), 'icon': __imgsearch__,
'thumbnail': __imgsearch__}
itemstream = {'label': 'Play Web URL', 'path': plugin.url_for(resolver), 'icon': 'DefaultFolder.png',
'thumbnail': 'DefaultFolder.png'}
timg = __imgsearch__.replace('search.', 'ftumblr.')
itemtumblr = {'label': 'Tumblr', 'icon': timg, 'thumbnail': timg, 'path': plugin.url_for(tumblrhome)}
itemtumblr.setdefault(itemtumblr.keys()[0])
itemallcats.setdefault(itemallcats.keys()[0])
itemstream.setdefault(itemstream.keys()[0])
itemsearch.setdefault(itemsearch.keys()[0])
allitems.append(itemallcats)
allitems.append(itemtumblr)
allitems.append(itemsearch)
allitems.append(itemstream)
return finish(allitems)
@plugin.route('/site/<sitename>/<section>/<url>/')
def site(sitename, section, url):
"""
Main working function for the addon and handles Site specific calls to Search a site, Next Page, and Index.
Index and Search sections call back into this section for Next Page support
A shortcut helper SITEROOT simply calls this function for each site but looks up the correct URL to pass to section=Index
:param sitename: Name of site to perform section actions on
:param section: Index, Search, Next
:param url: API URL for the section
:return: Listitems for results plus a Search Site Item and Next Page Item
"""
litems = []
itemslist = []
viewmode = int(plugin.get_setting('viewmode'))
if viewmode is None: viewmode = 500
plugin.set_view_mode(viewmode)
DOSTR8 = plugin.get_setting(key='dostr8')
__imgnext__ = __imgsearch__.replace('search.png', 'next.png')
siteurl = getAPIURLS(sitename=sitename)
if url == '0':
url = siteurl
pagenum = 2
if siteurl.find('search=gay&') != -1:
surl = siteurl.replace('search=gay&', 'search={0}+gay&')
elif siteurl.find('porkytube') != -1 or siteurl.find('bonertube') != -1:
surl = getAPIURLS(sitename='{0}_search'.format(sitename))
elif siteurl.find('motherless') != -1:
surl = siteurl
surl = surl.replace('offset=1&','offset=0&')
pagenum = 250
else:
surl = siteurl.replace('search=', 'search={0}')
itemsearch = {'label': 'Search {0}'.format(sitename.title()),
'path': plugin.url_for(site, sitename=sitename, section='search', url=surl), 'icon': __imgsearch__,
'thumbnail': __imgsearch__}
itemsearch.setdefault(itemsearch.keys()[0])