def go():
  url = sys.argv[0].replace("plugin://%s" % ADDON_ID, VIETMEDIA_HOST ) + sys.argv[2]
  if url == VIETMEDIA_HOST + '/':
    url += '?action=menu'
  
  #Settings
  if '__settings__' in url:
    ADDON.openSettings()
    return
  #Search
  if '__search__' in url:
    keyboardHandle = xbmc.Keyboard('','Enter search text')
    keyboardHandle.doModal()
    if (keyboardHandle.isConfirmed()):
      queryText = keyboardHandle.getText()
      if len(queryText) == 0:
        return
      queryText = urllib.quote_plus(queryText)
      url = url.replace('__search__', queryText)
    else:
      return
  data = fetch_data(url)
  if not data:
    return
  if data.get('error'):
    alert(data['error'])
    return
  
  if data.get("url"):
    play(data)
    return

  if data.get("content_type") and len(data["content_type"]) > 0:
    xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
    xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
    xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_DATE)
    xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_GENRE)
    xbmcplugin.setContent(HANDLE, data["content_type"])

  listitems = range(len(data["items"]))
  for i, item in enumerate(data["items"]):
      listItem = xbmcgui.ListItem(label=item["label"], label2=item["label2"], iconImage=item["icon"], thumbnailImage=item["thumbnail"])
      if item.get("info"):
          listItem.setInfo("video", item["info"])
      if item.get("stream_info"):
          for type_, values in item["stream_info"].items():
              listItem.addStreamInfo(type_, values)
      if item.get("art"):
          listItem.setArt(item["art"])
      if item.get("context_menu"):
          listItem.addContextMenuItems(item["context_menu"])
      listItem.setProperty("isPlayable", item["is_playable"] and "true" or "false")
      if item.get("properties"):
          for k, v in item["properties"].items():
              listItem.setProperty(k, v)
      listitems[i] = (item["path"], listItem, not item["is_playable"])

  xbmcplugin.addDirectoryItems(HANDLE, listitems, totalItems=len(listitems))
  xbmcplugin.endOfDirectory(HANDLE, succeeded=True, updateListing=False, cacheToDisc=True)
Example #2
0
def go():
  
	url = sys.argv[0].replace("plugin://%s" % ADDON_ID, VIETMEDIA_HOST ) + sys.argv[2]
  
	if url == VIETMEDIA_HOST + '/':
		url += '?action=menu'
	
	#Settings
	if 'textbox' in url or 'Textbox' in url:
		url = url.replace(VIETMEDIA_HOST+'/?action=textbox&', '')
		
		url = urllib.unquote_plus(url)
		content = openURL(url)
		TextBoxes(ADDON_NAME, content)
		return
		
	if 'checkupdate' in url:
		forceUpdate()
	if 'check_fshare' in url:
		#notify('đang check')
		check_fshare()
		return
	if 'addon' in url:
		url = url.replace(VIETMEDIA_HOST+'/?action=addon&', '')
		url=urllib.unquote(url)
		install_repo(url)
		return
		
	if 'clearCache' in url:
		clearCache()
		return
	if 'viewlog' in url:
		viewLogFile()
		return
	if '__settings__' in url:
		ADDON.openSettings()
		return
	if 'addon' in url:
		install_repo(url)
		return
	#Search
	if '__search__' in url:
		
		keyboardHandle = xbmc.Keyboard('','VietmediaF')
		keyboardHandle.doModal()
		if (keyboardHandle.isConfirmed()):
			queryText = keyboardHandle.getText()
			if len(queryText) == 0:
				return
			queryText = urllib.quote_plus(queryText)
			url = url.replace('__search__', queryText)
		else:
			return
	if '__download__' in url:
		download(url)
		return
	if '__lock__' in url:
		add_lock_dir(url)
		return
	if '__unlock__' in url:
		remove_lock_dir(url)
		return
	
	
	if check_lock(url):
		dialog = xbmcgui.Dialog()
		result = dialog.input('Nhập mã khoá', type=xbmcgui.INPUT_ALPHANUM, option=xbmcgui.ALPHANUM_HIDE_INPUT)
		if len(result) == 0 or result != LOCK_PIN:
			notify('Sai mật mã, vui lòng nhập lại')
			return

	data = fetch_data(url)
	if not data:
		return
	if data.get('error'):
		alert(data['error'])
		return
  
	if data.get("url"):
		play(data)
		return

	if not data.get("items"):
		return
    
	if data.get("content_type") and len(data["content_type"]) > 0:
		xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
		xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
		xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_DATE)
		xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_GENRE)
		xbmcplugin.setContent(HANDLE, data["content_type"])

	listitems = range(len(data["items"]))
	for i, item in enumerate(data["items"]):
		lock_url = item["path"].replace("plugin://%s" % ADDON_ID, VIETMEDIA_HOST )
		lock_url = re.sub('\?','/?',lock_url)
		label = item["label"]
		if check_lock(lock_url):
			label = "*" + label
		listItem = xbmcgui.ListItem(label=label, label2=item["label2"], iconImage=item["icon"], thumbnailImage=item["thumbnail"])
		if item.get("info"):
			listItem.setInfo("video", item["info"])
		if item.get("stream_info"):
			for type_, values in item["stream_info"].items():
				listItem.addStreamInfo(type_, values)
		if item.get("art"):
			listItem.setArt(item["art"])
      
		menu_context = []
		if item.get("context_menu"):
			listItem.addContextMenuItems(item["context_menu"])
		elif item["is_playable"] == True:
          
			title = item["label"]
			title = re.sub('\[.*?]','',title)
			title = re.sub('\s','-',title)
			title = re.sub('--','-',title)
			title = re.sub('--','-',title)
			title = re.sub('[\\\\/*?:"<>|#]',"",title)
			title = remove_accents.remove_accents(title)
			command = 'XBMC.RunPlugin(%s&d=__download__&file_name=%s)' % (item["path"], title)
			menu_context.append(( 'Download...', command, ))

		command = 'XBMC.RunPlugin(%s&d=__lock__)' % item["path"]
		menu_context.append(( 'Khoá mục này', command, ))
		command = 'XBMC.RunPlugin(%s&d=__unlock__)' % item["path"]
		menu_context.append(( 'Mở khoá mục này', command, ))
		listItem.addContextMenuItems( menu_context )

		listItem.setProperty("isPlayable", item["is_playable"] and "true" or "false")
		if item.get("properties"):
			for k, v in item["properties"].items():
				listItem.setProperty(k, v)
		listitems[i] = (item["path"], listItem, not item["is_playable"])

	xbmcplugin.addDirectoryItems(HANDLE, listitems, totalItems=len(listitems))
  
	if VIEWMODE == 'true':
		if '?action=menu' in url or 'node_id=77' in url or 'node_id=86' in url or 'node_id=79' in url or 'thread_id=18666' in url or 'thread_id=15858' in url or 'thread_id=21762' in url or 'thread_id=21802' in url or 'thread_id=15492' in url or 'thread_id=104' in url or 'node_id=13' in url or 'node_id=19' in url:
			xbmc.executebuiltin('Container.SetViewMode(%d)' % 500)
  
  
	hello()
	
	xbmcplugin.endOfDirectory(HANDLE, succeeded=True, updateListing=False, cacheToDisc=True)