2424import requests
2525import os
2626import urllib2
27+ # import datetime
2728
2829
2930plugin = Plugin ()
4041# lang : F | D
4142live_json = base_url + '/papi/tvguide/videos/livestream/{lang}/'
4243
43- # http://www.arte.tv/guide/{lang}/plus7/par_dates.json?value={date}
44- # lang : fr | de
45- # date : date sous la forme yyyy-mm-jj
46-
47- # http://www.arte.tv/guide/{lang}/plus7/par_themes.json?value={genre}
48- # lang : fr | de
49- # genre : trigramme du genre (ACT DOC DEC EUR GEO SOC JUN AUT CIN ART CUL ENV)
50-
51- # http://www.arte.tv/guide/{lang}/plus7/par_emissions.json?value={emission}
52- # lang : fr | de
53- # emission : trigramme de l'emission (VMI TSG AJT JTE COU FUM KAR DCA MTR PNB PHI SUA TRA VOX XEN YOU
54-
55- categories = [('new' , 30001 ),
56- ('selection' , 30002 ),
57- ('most_viewed' , 30003 ),
58- ('last_chance' , 30004 ),
59- ('themes' , 30005 )]
60-
61- themes = [('ACT' , 3000501 ),
62- ('DOC' , 3000502 ),
63- ('DEC' , 3000503 ),
64- ('EUR' , 3000504 ),
65- ('GEO' , 3000505 ),
66- ('SOC' , 3000506 ),
67- ('JUN' , 3000507 ),
68- ('AUT' , 3000508 ),
69- ('CIN' , 3000509 ),
70- ('ART' , 3000510 ),
71- ('CUL' , 3000511 ),
72- ('ENV' , 3000512 )]
44+ # http://www.arte.tv/papi/tvguide/videos/plus7/program/{lang}/{detailLevel}/{category}/{cluster}/{recommended}/{sort}/{limit}/{offset}/DE_FR.json
45+ # lang : F | D
46+ # detailLevel : L2 | L3 (the higher the most verbose)
47+ # category : categorie (HIS... see below)
48+ # cluster : emission (VMI... see below)
49+ # recommended : 1 | -1
50+ # sort : AIRDATE_DESC | AIRDATE_ASC | ALPHA | VIEWS | LAST_CHANCE
51+ # limit : n of results
52+ # offset : starts at 1
53+ #
54+ # cluster : emission
55+ # 28 Minutes VMI
56+ # 360° GEO TSG
57+ # ARTE Journal AJT
58+ # ARTE Junior JUN
59+ # ARTE Reportage JTE
60+ # Au cœur de la nuit ACN
61+ # Cinéma sur ARTE FIL
62+ # Court-circuit COU
63+ # Cuisines des terroirs CUI
64+ # Futuremag FUM
65+ # Karambolage KAR
66+ # Le Dessous des cartes DCA
67+ # Maestro MAE
68+ # Metropolis MTR
69+ # Personne ne bouge ! PNB
70+ # Philosophie PHI
71+ # Square SUA
72+ # Tracks TRA
73+ # Vox Pop VOX
74+ # X:enius XEN
75+ # Yourope YOU
76+ #
77+ # category : categories
78+ # Actu & société ACT
79+ # Séries & fiction FIC
80+ # Cinéma CIN
81+ # Arts & spectacles classiques ART
82+ # Culture pop CUL
83+ # Découverte DEC
84+ # Histoire HIS
85+ # Junior JUN
86+ listing_json = base_url + '/papi/tvguide/videos/plus7/program/{lang}/L2/{category}/{cluster}/{highlight}/{sort}/{limit}/{offset}/DE_FR.json'
87+
88+ def get_menu_items ():
89+ return [(plugin .url_for ('listing' ), 30001 ), # new http://www.arte.tv/papi/tvguide/videos/plus7/program/F/L2/ALL/ALL/-1/AIRDATE_DESC/0/0/DE_FR.json
90+ (plugin .url_for ('listing' , highlight = '1' , limit = '6' ), 30002 ), # selection http://www.arte.tv/papi/tvguide/videos/plus7/program/F/L2/ALL/ALL/1/AIRDATE_DESC/6/0/DE_FR.json
91+ (plugin .url_for ('listing' , sort = 'VIEWS' , limit = '20' ), 30003 ), # most_viewed http://www.arte.tv/papi/tvguide/videos/plus7/program/F/L2/ALL/ALL/-1/VIEWS/0/0/DE_FR.json
92+ (plugin .url_for ('listing' , sort = 'LAST_CHANCE' , limit = '20' ), 30004 ), # last chance http://www.arte.tv/papi/tvguide/videos/plus7/program/F/L2/ALL/ALL/-1/LAST_CHANCE/0/0/DE_FR.json
93+ (plugin .url_for ('categories' ), 30005 )] # categories http://www.arte.tv/papi/tvguide/videos/plus7/program/F/L2/XXX/ALL/-1/AIRDATE_DESC/0/0/DE_FR.json
94+
95+
96+ def get_categories ():
97+ return [('ACT' , 3000501 ),
98+ ('FIC' , 3000502 ),
99+ ('CIN' , 3000503 ),
100+ ('ART' , 3000504 ),
101+ ('CUL' , 3000505 ),
102+ ('DEC' , 3000506 ),
103+ ('HIS' , 3000507 ),
104+ ('JUN' , 3000508 )]
73105
74106headers = {'user-agent' : plugin .name + '/' + plugin .addon .getAddonInfo ('version' )}
75107
76108quality_map = {0 : 'SQ' , 1 : 'EQ' , 2 : 'HQ' , 3 : 'MQ' }
77109
78110# Settings
79- language = 'fr ' if plugin .get_setting ('lang' , int ) == 0 else 'de '
111+ language = 'FR ' if plugin .get_setting ('lang' , int ) == 0 else 'DE '
80112prefer_vost = plugin .get_setting ('prefer_vost' , bool )
81113quality = plugin .get_setting ('quality' , int )
82114protocol = 'HBBTV' if plugin .get_setting ('protocol' , int ) == 0 else 'RMP4'
87119@plugin .route ('/' )
88120def index ():
89121 items = [{
90- 'label' : plugin .get_string (value ),
91- 'path' : plugin . url_for ( 'show_' + key )
92- } for key , value in categories ]
122+ 'label' : plugin .get_string (sid ),
123+ 'path' : path
124+ } for path , sid in get_menu_items () ]
93125 items .append ({
94126 'label' : plugin .get_string (30006 ),
95127 'path' : plugin .url_for ('play_live' ),
@@ -98,58 +130,61 @@ def index():
98130 return items
99131
100132
101- @plugin .route ('/new' , name = 'show_new' ,
102- options = {'json_url' : base_url + '/guide/{lang}/plus7.json' })
103- @plugin .route ('/selection' , name = 'show_selection' ,
104- options = {'json_url' : base_url + '/guide/{lang}/plus7/selection.json' })
105- @plugin .route ('/most_viewed' , name = 'show_most_viewed' ,
106- options = {'json_url' : base_url + '/guide/{lang}/plus7/plus_vues.json' })
107- @plugin .route ('/last_chance' , name = 'show_last_chance' ,
108- options = {'json_url' : base_url + '/guide/{lang}/plus7/derniere_chance.json' })
109- @plugin .route ('/themes/<theme>' , name = 'show_theme' ,
110- options = {'json_url' : base_url + '/guide/{lang}/plus7/par_themes.json' })
111- def list_items (json_url , theme = None ):
133+ @plugin .route ('/listing' , name = 'listing' )
134+ def show_listing ():
112135 plugin .set_content ('tvshows' )
113136
114- payload = {}
115- if theme :
116- payload ['value' ] = theme
137+ # very ugly workaround ahead (plugin.request.args.XXX returns an array for unknown reason)
138+ url = listing_json .format (lang = language [0 ],
139+ category = plugin .request .args .get ('category' , ['ALL' ])[0 ],
140+ cluster = plugin .request .args .get ('cluster' , ['ALL' ])[0 ],
141+ highlight = plugin .request .args .get ('highlight' , ['-1' ])[0 ],
142+ sort = plugin .request .args .get ('sort' , ['AIRDATE_DESC' ])[0 ],
143+ limit = plugin .request .args .get ('limit' , ['0' ])[0 ],
144+ offset = plugin .request .args .get ('offset' , ['0' ])[0 ])
145+
146+ data = load_json (url )
117147
118- data = load_json ( json_url .format (lang = language ), payload )
148+ listing_key = 'program{lang}List' .format (lang = language )
119149
120150 items = []
121- for video in data ['videos' ]:
151+ for video in data [listing_key ]:
152+ vdo = video ['VDO' ]
122153 item = {
123- 'label' : video [ 'title' ] ,
124- 'path' : plugin .url_for ('play' , vid = str (video [ 'em' ] )),
125- 'thumbnail' : video [ 'image_url' ] ,
154+ 'label' : vdo . get ( 'VTI' ) ,
155+ 'path' : plugin .url_for ('play' , vid = str (vdo . get ( 'VPI' ) )),
156+ 'thumbnail' : vdo . get ( 'VTU' ). get ( 'IUR' ) ,
126157 'is_playable' : True ,
127158 'info_type' : 'video' ,
128159 'info' : {
129- 'label' : video ['title' ],
130- 'title' : video ['title' ],
131- 'duration' : str (video ['duration' ]),
132- 'genre' : video ['video_channels' ] if video ['video_channels' ] else '' ,
133- 'plot' : video ['desc' ] if video ['desc' ] else '' ,
160+ 'label' : vdo .get ('VTI' ),
161+ 'title' : vdo .get ('VTI' ),
162+ 'duration' : str (vdo .get ('VDU' )),
163+ 'genre' : vdo .get ('VCG' ),
164+ 'plot' : vdo .get ('VDE' ),
165+ 'plotoutline' : vdo .get ('V7T' ),
166+ 'year' : vdo .get ('productionYear' ),
167+ 'director' : vdo .get ('PPD' ),
168+ #'aired': datetime.datetime.strptime(vdo.get('VDA')[:-6], '%d/%m/%Y %H:%M:%S').strftime('%Y-%m-%d') if vdo.get('VDA') else None
134169 },
135170 'properties' : {
136- 'fanart_image' : video [ 'image_url' ] ,
171+ 'fanart_image' : vdo . get ( 'VTU' ). get ( 'IUR' ) ,
137172 },
138173 'context_menu' : [
139- (plugin .get_string (30021 ), actions .background (plugin .url_for ('download' , vid = str (video [ 'em' ] )))),
174+ (plugin .get_string (30021 ), actions .background (plugin .url_for ('download' , vid = str (vdo . get ( 'VPI' ) )))),
140175 ],
141176 }
142177 # item['context_menu'].append((plugin.get_string(30020), plugin.url_for('enqueue', item=item)))
143178 items .append (item )
144179 return plugin .finish (items )
145180
146181
147- @plugin .route ('/show_themes ' , name = 'show_themes ' )
148- def show_themes ():
182+ @plugin .route ('/categories ' , name = 'categories ' )
183+ def show_categories ():
149184 items = [{
150185 'label' : plugin .get_string (value ),
151- 'path' : plugin .url_for ('show_theme ' , theme = key )
152- } for key , value in themes ]
186+ 'path' : plugin .url_for ('listing ' , sort = 'AIRDATE_DESC' , category = key )
187+ } for key , value in get_categories () ]
153188 return plugin .finish (items )
154189
155190
0 commit comments