def openseasons(params): print '=== def openseasons(%s): ===' % params try: series_id = params['series_id'] except: print 'ERROR: Не указан ключевой параметр series_id' return False # Получение метаданных meta_http = kbutils.KBREQUEST('/films/%s?fields_mask=63' % series_id) if meta_http != None: meta_json = demjson.decode(meta_http) # Парсинг метаданных meta_info = kbutils.getmetadata(meta_json, series_id) else: meta_info = None http = kbutils.KBREQUEST('/films/%s/seasons' % series_id) if http == None: return False djson = demjson.decode(http) series_id = djson['series_id'] # int seasons = djson['seasons'] # array if len(seasons) > 0: series_img = kbutils.POSTER(series_id) for season in seasons: info = {} if meta_info != None: info = meta_info.copy() season_num = season['num'] # int 1 episodes_count = season['episodes_count'] # int 29 start_date = season[ 'start_date'] #.encode('utf-8') # str 2003-02-01 end_date = season[ 'end_date'] #.encode('utf-8') # str 2004-03-16 if start_date == None: start_date = '' else: start_date = start_date.encode('utf-8') if end_date == None: end_date = '' else: end_date = end_date.encode('utf-8') if (start_date == '') and (end_date == ''): date_block = '' else: date_block = ' [%s : %s]' % (start_date, end_date) info['title'] = '%s : Сезон %d%s' % (info['title'], season_num, date_block) info['premiered'] = start_date info['season'] = int(season_num) li = xbmcgui.ListItem(info['title'], iconImage=series_img, thumbnailImage=series_img) li.setInfo(type='video', infoLabels=info) uri = '%s?mode=openepisodes&series_id=%s&season_num=%s' % ( sys.argv[0], series_id, season_num) xbmcplugin.addDirectoryItem(h, uri, li, isFolder=True, totalItems=episodes_count) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_DATE) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_TITLE) xbmcplugin.endOfDirectory(h)
def openepisodes(params): print '=== def openepisodes(%s): ===' % params try: series_id = params['series_id'] season_num = params['season_num'] except: print 'ERROR: Не указан ключевой параметр series_id или season_num' return False # Получение метаданных meta_http = kbutils.KBREQUEST('/films/%s?fields_mask=63' % series_id) if meta_http != None: meta_json = demjson.decode(meta_http) # Парсинг метаданных meta_info = kbutils.getmetadata(meta_json, series_id) else: meta_info = None http = kbutils.KBREQUEST('/films/%s/seasons/%s/episodes' % (series_id, season_num)) if http == None: return False djson = demjson.decode(http) series_id = djson['series_id'] # int 1 season_num = djson['season_num'] # int 1 episodes = djson['episodes'] # array if len(episodes) > 0: series_img = kbutils.POSTER(series_id) for episode in episodes: info = {} if meta_info != None: info = meta_info.copy() episode_num = episode['num'] # int 1 episode_name = episode['name'].encode('utf-8') # str Role Play release_date = episode[ 'release_date'] #3.encode('utf-8') # str 2003-02-01 info['title'] = '%d. %s' % (episode_num, episode_name) if release_date != None: info['premiered'] = release_date info['premiered'] = release_date info['episode'] = int(episode_num) info['season'] = int(season_num) li = xbmcgui.ListItem(info['title'], iconImage=series_img, thumbnailImage=series_img) li.setInfo(type='video', infoLabels=info) uri = '%s?mode=openfilm&series_id=%d&season_num=%d&episode_num=%d' % ( sys.argv[0], series_id, season_num, episode_num) xbmcplugin.addDirectoryItem(h, uri, li, isFolder=True) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_DATE) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_TITLE) xbmcplugin.endOfDirectory(h)
def showlanguages(params): http = kbutils.KBREQUEST('/languages') djson = demjson.decode(http) for cur in djson: lang_id = cur['id'] lang_name = cur['name'].encode('utf-8') li = xbmcgui.ListItem('Язык "%s"' % lang_name, iconImage=icon, thumbnailImage=icon) xbmcplugin.addDirectoryItem( h, '%s?mode=openlanguage&lang_id=%s&lang_name=%s' % (sys.argv[0], lang_id, urllib.quote_plus(lang_name)), li, True) xbmcplugin.endOfDirectory(h)
def showgenres(params): http = kbutils.KBREQUEST('/genres/') djson = demjson.decode(http) for cur in djson: genre_id = cur['id'] genre_name = cur['name'].encode('utf-8') li = xbmcgui.ListItem('Жанр "%s"' % genre_name, iconImage=icon, thumbnailImage=icon) xbmcplugin.addDirectoryItem( h, '%s?mode=opengenre&genre_id=%s&genre_name=%s' % (sys.argv[0], genre_id, urllib.quote_plus(genre_name)), li, True) xbmcplugin.endOfDirectory(h)
def showtrackers(params): http = kbutils.KBREQUEST('/trackers') djson = demjson.decode(http) for cur in djson: tracker_id = cur['id'] tracker_name = cur['url'].encode('utf-8') print 'Tracker ID = %s, URL = %s' % (tracker_id, tracker_name) li = xbmcgui.ListItem('Трекер %s' % tracker_name, iconImage=icon, thumbnailImage=icon) xbmcplugin.addDirectoryItem( h, '%s?mode=openlantracker&tracker_id=%s&tracker_name=%s' % (sys.argv[0], tracker_id, urllib.quote_plus(tracker_name)), li, True) xbmcplugin.endOfDirectory(h)
def showcountries(params): http = kbutils.KBREQUEST('/countries/') djson = demjson.decode(http) for cur in djson: country_id = cur['id'] country_name = cur['name'].encode('utf-8') country_iso = cur['iso'] li = xbmcgui.ListItem('Страна "%s"' % country_name, iconImage=icon, thumbnailImage=icon) xbmcplugin.addDirectoryItem( h, '%s?mode=opencountry&country_id=%s&country_name=%s&country_iso=%s' % (sys.argv[0], country_id, urllib.quote_plus(country_name), country_iso), li, True) xbmcplugin.endOfDirectory(h)
def loadtorrent(params): print '=== def loadtorrent(%s): ===' % params try: dhash = params['hash'] film_id = params['film_id'] dlpath = urllib.unquote_plus(params['dlpath']) except: print 'ERROR: Не указан ключевой параметр hash, dlpath или film_id' return False rtc = kbutils.get_rtc() rtpath = rtc.get_directory() print 'rTorrent base dir (rtpath) = %s' % rtpath dpath = rtpath if kbutils.rtc_select == 'true': print 'Указан выбор каталога загрузки...' dpa = [] for ddir in os.listdir(rtpath): dpa.append(ddir) s = xbmcgui.Dialog().select('Куда качать?', dpa) if s < 0: print 'Не выбрано, выход...' return True else: dpath = os.path.join(rtpath, dpa[s]) dpath = os.path.join(dpath, dlpath) print 'Download path [%s]' % dpath if not os.path.exists(dpath): os.makedirs(dpath) print 'Path %s created...' % dpath else: print 'Path %s exists...' % dpath url_gt = '/torrents/%s/direct-link' % dhash print 'url_gt GET: %s' % url_gt http3 = kbutils.KBREQUEST(url_gt) if http3 == None: return False djson2 = demjson.decode(http3) #print djson2 tf_url = djson2['url'] print 'Direct Link = %s' % tf_url meta_http = kbutils.KBREQUEST('/films/%s?fields_mask=63' % film_id) if meta_http != None: meta_json = demjson.decode(meta_http) meta_info = kbutils.getmetadata(meta_json, film_id) else: meta_info = None try: if len(meta_info['cast']) > 0: casts = '' for cucast in meta_info['cast']: casts += ',%s' % urllib.quote_plus(cucast) if casts != '': casts = casts[1:] meta_info['cast'] = casts except: pass custom2 = '&film_id=%s' % film_id if meta_info != None: for cinfo in meta_info: custom2 += '&%s=%s' % (cinfo, urllib.quote_plus(str(meta_info[cinfo]))) custom2 = custom2[1:] # 'd.set_custom2="%s"'%custom2 rtc.load_start(tf_url, 'd.set_directory="%s"' % dpath, 'd.set_custom1="kinobaza"', 'd.set_custom=kbmeta,%s' % custom2)
def openfilm(params): print '=== def openfilm(%s): ===' % params film_type = 0 # 1: movie, 2: series try: film_id = params['series_id'] #'series_id': '357767' season_num = params['season_num'] #'season_num': '1' episode_num = params['episode_num'] #'episode_num': '1' torget = '/films/%s/seasons/%s/episodes/%s/torrents' % ( film_id, season_num, episode_num) dlpath = os.path.join(film_id, season_num, episode_num) film_type = 2 except: pass if film_type == 0: try: film_id = params['film_id'] #'series_id': '357767' torget = '/films/%s/torrents?all_trackers=false' % film_id dlpath = os.path.join(film_id) film_type = 1 except: pass print 'openfilm -> torget = [%s]' % torget if film_type == 0: print 'ERROR: Тип раздачи не был установлен (film_type == 0)' return False http = kbutils.KBREQUEST(torget) if http == None: return False djson = demjson.decode(http) film_id = djson['film_id'] filters = djson['filters'] torrents = djson['torrents'] hash_arrs = [] hash_data = {} rtc = kbutils.get_rtc() for torrent in torrents: approved = torrent['is_approved'] tracker = torrent['tracker_url'].encode('utf-8').replace('http:', '').replace( '/', '') size = int(torrent['size']) try: filetype = torrent['filetype'].encode('utf-8') except: filetype = '?' quality = kbutils.replace_quality(torrent['quality']) quality = quality.replace(',', '') seeders = int(torrent['seeders']) leechers = int(torrent['leechers']) THASH = torrent['hash'].encode('utf-8') hash_arrs.append(THASH) try: percent = (int(rtc.f.get_completed_chunks(THASH, 0)) * 100) / int( rtc.f.get_size_chunks(THASH, 0)) except: percent = 0 subdata = { 'approved': approved, 'tracker': tracker, 'size': size, 'filetype': filetype, 'quality': quality, 'seeders': seeders, 'leechers': leechers, 'percent': percent, 'hash': THASH } hash_data[THASH] = subdata uhash_arrs = set(hash_arrs) # TODO Add METADATA def set_approved(let, li): if let['approved']: li.setProperty('fanart_image', Thumbs_Up) else: li.setProperty('fanart_image', Thumbs_Down) # Поиск полностью загруженных раздач for uhash in uhash_arrs: ninfo = hash_data[uhash] if ninfo['percent'] == 100: it = '%s Тип:%s %s' % (ninfo['tracker'], ninfo['filetype'], ninfo['quality']) li = xbmcgui.ListItem(it, iconImage=iOK, thumbnailImage=iOK) li.setInfo('video', {'title': it, 'size': ninfo['size']}) set_approved(ninfo, li) if rtc.d.get_size_files(uhash) > 1: xbmcplugin.addDirectoryItem(h, rtc.d.get_directory(uhash), li, isFolder=True) else: xbmcplugin.addDirectoryItem(h, os.path.join( rtc.d.get_directory(uhash), rtc.d.get_name(uhash)), li, isFolder=False) # Поиск загружаемых раздач for uhash in uhash_arrs: ninfo = hash_data[uhash] # TODO and paused... try: is_active = int(rtc.d.is_active(ninfo['hash'])) except: is_active = 0 if (ninfo['percent'] < 100) and (is_active == 1): it = '%d%% S=%s, L=%s %s(%s), от %s' % ( ninfo['percent'], ninfo['seeders'], ninfo['leechers'], ninfo['quality'], ninfo['filetype'], ninfo['tracker']) li = xbmcgui.ListItem(it, iconImage=iDOWNLOADING, thumbnailImage=iDOWNLOADING) li.setInfo('video', {'title': it, 'size': ninfo['size']}) set_approved(ninfo, li) # TODO Сделать доп. пункты. ppath = os.path.join(rtc.d.get_directory(uhash), rtc.d.get_name(uhash)) if rtc.d.get_size_files(uhash) > 1: xbmcplugin.addDirectoryItem(h, rtc.d.get_directory(uhash), li, isFolder=True) else: xbmcplugin.addDirectoryItem(h, os.path.join( rtc.d.get_directory(uhash), rtc.d.get_name(uhash)), li, isFolder=False) for uhash in uhash_arrs: ninfo = hash_data[uhash] if ninfo['percent'] == 0: it = 'S=%s, L=%s %s(%s), от %s' % ( ninfo['seeders'], ninfo['leechers'], ninfo['quality'], ninfo['filetype'], ninfo['tracker']) li = xbmcgui.ListItem(it, iconImage=iSTART, thumbnailImage=iSTART) li.setInfo('video', {'title': it, 'size': ninfo['size']}) set_approved(ninfo, li) uri = '%s?mode=loadtorrent&hash=%s&film_id=%s&dlpath=%s' % ( sys.argv[0], uhash, film_id, urllib.quote_plus(dlpath)) xbmcplugin.addDirectoryItem(h, uri, li) xbmcplugin.addSortMethod(h, sortMethod=xbmcplugin.SORT_METHOD_TITLE) xbmcplugin.addSortMethod(h, sortMethod=xbmcplugin.SORT_METHOD_SIZE) xbmcplugin.endOfDirectory(h)
def filmsbrowse(params): print '=== def filmsbrowse(%s): ===' % params try: href = urllib.unquote_plus(params['href']) params['href'] = href except: href = '' try: params['query'] = urllib.unquote_plus(params['query']) except: pass GL = params.copy() del GL['mode'] del GL['href'] #url = http = kbutils.KBREQUEST('%s?%s' % (href, urllib.urlencode(GL))) djson = demjson.decode(http) #print djson # Если подключен rTorrent - генерируем список подкаталогов, для проверки загрузки rtc = kbutils.get_rtc() if rtc != None: base_dl_path = rtc.get_directory() dpa = [] if (kbutils.rtc_select == 'true'): for ddir in os.listdir(base_dl_path): dpa.append(os.path.join(base_dl_path, ddir)) else: dpa.append(os.path.join(base_dl_path)) for cur in djson: info = kbutils.getmetadata(cur, cur['id']) if rtc != None: for chkdir in dpa: if os.path.exists(os.path.join(chkdir, str(cur['id']))): info['title'] = '[DL] %s' % info['title'] break li = xbmcgui.ListItem(label=info['title'], iconImage=info['iconImage'], thumbnailImage=info['thumbnailImage']) li.setInfo(type='video', infoLabels=info) if cur['type'] == 'movie': #li.setProperty('IsPlayable', 'true') uri = '%s?mode=openfilm&film_id=%s' % (sys.argv[0], cur['id']) if not xbmcplugin.addDirectoryItem(h, uri, li, isFolder=True): break elif cur['type'] == 'series': uri = '%s?mode=openseasons&series_id=%s' % (sys.argv[0], cur['id']) if not xbmcplugin.addDirectoryItem(h, uri, li, isFolder=True): break else: kbutils.showMessage('Ой, "%s"' % film_type, 'Не могу добавить этот тип фильма') if len(djson) == int(params['limit']): li = xbmcgui.ListItem('Далее >', iconImage=icon, thumbnailImage=icon) params['offset'] = str(int(params['offset']) + int(params['limit'])) uri = '%s?%s' % (sys.argv[0], urllib.urlencode(params)) xbmcplugin.addDirectoryItem(h, uri, li, isFolder=True, totalItems=kbutils.LIST_LIMIT()) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_UNSORTED) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_ALBUM) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_DATE) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_DURATION) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_GENRE) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_TITLE) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_VIDEO_RATING) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_VIDEO_RUNTIME) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_VIDEO_YEAR) xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_LABEL) xbmcplugin.endOfDirectory(h)