def __init__(self):
        # Get the command line arguments
        # Get the plugin url in plugin:// notation
        self.plugin_url = sys.argv[0]
        # Get the plugin handle as an integer number
        self.plugin_handle = int(sys.argv[1])

        # Get plugin settings
        self.DEBUG = SETTINGS.getSetting('debug')
        self.VIDEO = SETTINGS.getSetting('video')

        if self.DEBUG == 'true':
            xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s, %s = %s" % (
                ADDON, VERSION, DATE, "ARGV", repr(sys.argv), "File", str(__file__)), xbmc.LOGNOTICE)

        # Parse parameters...
        self.video_page_url = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['video_page_url'][0]
        # Get the title.
        self.title = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['title'][0]
        self.title = str(self.title)

        if self.DEBUG == 'true':
            xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                ADDON, VERSION, DATE, "self.video_page_url", str(self.video_page_url)), xbmc.LOGNOTICE)

        #
        # Play video...
        #
        self.playVideo()
예제 #2
0
    def __init__(self):
        # Get the command line arguments
        # Get the plugin url in plugin:// notation
        self.plugin_url = sys.argv[0]
        # Get the plugin handle as an integer number
        self.plugin_handle = int(sys.argv[1])

        # Get plugin settings
        self.DEBUG = SETTINGS.getSetting('debug')
        self.VIDEO = SETTINGS.getSetting('video')

        if self.DEBUG == 'true':
            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s, %s = %s" %
                (ADDON, VERSION, DATE, "ARGV", repr(
                    sys.argv), "File", str(__file__)), xbmc.LOGNOTICE)

        # Parse parameters...
        self.video_page_url = urlparse.parse_qs(
            urlparse.urlparse(sys.argv[2]).query)['video_page_url'][0]
        # Get the title.
        self.title = urlparse.parse_qs(urlparse.urlparse(
            sys.argv[2]).query)['title'][0]
        self.title = str(self.title)

        if self.DEBUG == 'true':
            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s" %
                (ADDON, VERSION, DATE, "self.video_page_url",
                 str(self.video_page_url)), xbmc.LOGNOTICE)

        #
        # Play video...
        #
        self.playVideo()
    def __init__(self):
        # Get the command line arguments
        # Get the plugin url in plugin:// notation
        self.plugin_url = sys.argv[0]
        # Get the plugin handle as an integer number
        self.plugin_handle = int(sys.argv[1])

        # Get plugin settings
        self.VIDEO = SETTINGS.getSetting('video')

        log("ARGV", repr(sys.argv))

        # Parse parameters...
        self.video_page_url = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['video_page_url'][0]
        # Try and get the title.
        # When starting a video with a browser (f.e. in chrome the 'send to kodi'-extension) the url will be
        # something like this:
        # plugin://plugin.video.dumpert/?action=play&video_page_url=http%3A%2F%2Flegacy.dumpert.nl%2Fmediabase%2F7095997%2F1f72985c%2Fmevrouw_heeft_internetje_thuis.html
        # and there won't be a title available.
        try:
            self.title = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['title'][0]
            self.title = str(self.title)
        except KeyError:
            self.title = ""

        log("self.video_page_url",self.video_page_url)

        #
        # Play video...
        #
        self.playVideo()
    def __init__(self):
        # Get the command line arguments
        # Get the plugin url in plugin:// notation
        self.plugin_url = sys.argv[0]
        # Get the plugin handle as an integer number
        self.plugin_handle = int(sys.argv[1])

        # Get plugin settings
        self.VIDEO = SETTINGS.getSetting('video')

        log("ARGV", repr(sys.argv))

        # Parse parameters...
        self.video_page_url = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['video_page_url'][0]
        # Try and get the title.
        # When starting a video with a browser (f.e. in chrome the 'send to kodi'-extension) the url will be
        # something like this:
        # plugin://plugin.video.dumpert/?action=play&video_page_url=http%3A%2F%2Fwww.dumpert.nl%2Fmediabase%2F7095997%2F1f72985c%2Fmevrouw_heeft_internetje_thuis.html
        # and there won't be a title available.
        try:
            self.title = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['title'][0]
            self.title = str(self.title)
        except KeyError:
            self.title = ""

        log("self.video_page_url",self.video_page_url)

        #
        # Play video...
        #
        self.playVideo()
예제 #5
0
    def __init__(self):
        # Get the command line arguments
        # Get the plugin url in plugin:// notation
        self.plugin_url = sys.argv[0]
        # Get the plugin handle as an integer number
        self.plugin_handle = int(sys.argv[1])

        # Get plugin settings
        self.DEBUG = SETTINGS.getSetting('debug')

        if self.DEBUG == 'true':
            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s, %s = %s" %
                (ADDON, VERSION, DATE, "ARGV", repr(
                    sys.argv), "File", str(__file__)), xbmc.LOGNOTICE)

        # Parse parameters
        self.plugin_category = urlparse.parse_qs(
            urlparse.urlparse(sys.argv[2]).query)['plugin_category'][0]
        self.video_list_page_url = urlparse.parse_qs(
            urlparse.urlparse(sys.argv[2]).query)['url'][0]
        self.next_page_possible = urlparse.parse_qs(
            urlparse.urlparse(sys.argv[2]).query)['next_page_possible'][0]

        if self.DEBUG == 'true':
            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s" %
                (ADDON, VERSION, DATE, "self.video_list_page_url",
                 str(self.video_list_page_url)), xbmc.LOGNOTICE)

        # Determine current page number and base_url
        # http://www.dumpert.nl/toppers/
        # http://www.dumpert.nl/
        # http://www.dumpert.nl/<thema>/
        # find last slash
        pos_of_last_slash = self.video_list_page_url.rfind('/')
        # remove last slash
        self.video_list_page_url = self.video_list_page_url[
            0:pos_of_last_slash]
        pos_of_last_slash = self.video_list_page_url.rfind('/')
        self.base_url = self.video_list_page_url[0:pos_of_last_slash + 1]
        self.current_page = self.video_list_page_url[pos_of_last_slash + 1:]
        self.current_page = int(self.current_page)
        # add last slash
        self.video_list_page_url = str(self.video_list_page_url) + "/"

        if self.DEBUG == 'true':
            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s" %
                (ADDON, VERSION, DATE, "self.base_url", str(self.base_url)),
                xbmc.LOGNOTICE)

        #
        # Get the videos...
        #
        self.getVideos()
    def __init__(self):
        # Get the command line arguments
        # Get the plugin url in plugin:// notation
        self.plugin_url = sys.argv[0]
        # Get the plugin handle as an integer number
        self.plugin_handle = int(sys.argv[1])

        # Get plugin settings
        self.DEBUG = SETTINGS.getSetting('debug')

        if self.DEBUG == 'true':
            xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s, %s = %s" % (
                ADDON, VERSION, DATE, "ARGV", repr(sys.argv), "File", str(__file__)), xbmc.LOGNOTICE)

        # Parse parameters
        self.plugin_category = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['plugin_category'][0]
        self.video_list_page_url = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['url'][0]
        self.next_page_possible = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['next_page_possible'][0]

        if self.DEBUG == 'true':
            xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                ADDON, VERSION, DATE, "self.video_list_page_url", str(self.video_list_page_url)),
                     xbmc.LOGNOTICE)

        # Determine current page number and base_url
        # http://www.dumpert.nl/toppers/
        # http://www.dumpert.nl/
        # http://www.dumpert.nl/<thema>/
        # find last slash
        pos_of_last_slash = self.video_list_page_url.rfind('/')
        # remove last slash
        self.video_list_page_url = self.video_list_page_url[0: pos_of_last_slash]
        pos_of_last_slash = self.video_list_page_url.rfind('/')
        self.base_url = self.video_list_page_url[0: pos_of_last_slash + 1]
        self.current_page = self.video_list_page_url[pos_of_last_slash + 1:]
        self.current_page = int(self.current_page)
        # add last slash
        self.video_list_page_url = str(self.video_list_page_url) + "/"

        if self.DEBUG == 'true':
            xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                ADDON, VERSION, DATE, "self.video_list_page_url", str(self.video_list_page_url)),
                     xbmc.LOGNOTICE)

        #
        # Get the videos...
        #
        self.getVideos()
    def __init__(self):
        # Get the command line arguments
        # Get the plugin url in plugin:// notation
        self.plugin_url = sys.argv[0]
        # Get the plugin handle as an integer number
        self.plugin_handle = int(sys.argv[1])

        # Get plugin settings
        self.DEBUG = SETTINGS.getSetting('debug')

        if self.DEBUG == 'true':
            xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s, %s = %s" % (
                ADDON, VERSION, DATE, "ARGV", repr(sys.argv), "File", str(__file__)), xbmc.LOGNOTICE)

        # Parse parameters
        # urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['url'][0]
        base = urlparse.urlparse(sys.argv[2])
        query = base.query
        args = urlparse.parse_qs(query)
        url = args['url'][0]

        if self.DEBUG == 'true':
            xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                ADDON, VERSION, DATE, "self.video_list_page_url", str(self.video_list_page_url)),
                     xbmc.LOGNOTICE)

	# Get query
        q = ''
        keyboard = xbmc.Keyboard('', LANGUAGE(30508))
        keyboard.doModal()
        if (keyboard.isConfirmed()):
            q = keyboard.getText()

        url = requests.post(url, data = {'q':q,'cat':'','submit':'zoek'} ).url

        # Converting URL argument to proper query string
        args.update({'url':url+'1/'})
        encoded_args = urllib.urlencode(args, doseq=True)

        sys.argv[2] = urlparse.ParseResult(base.scheme, base.netloc, base.path, base.params, encoded_args, base.fragment).geturl()

        # Run list on results
        import dumpert_list as plugin
        plugin.Main()
    def playVideo(self):
        #
        # Init
        #
        no_url_found = False
        unplayable_media_file = False
        have_valid_url = False

        #
        # Get current list item details...
        #
        # title = unicode(xbmc.getInfoLabel("listitem.Title"), "utf-8")
        thumbnail_url = xbmc.getInfoImage("list_item.Thumb")
        # studio = unicode(xbmc.getInfoLabel("list_item.Studio"), "utf-8")
        plot = unicode(xbmc.getInfoLabel("list_item.Plot"), "utf-8")
        genre = unicode(xbmc.getInfoLabel("list_item.Genre"), "utf-8")

        #
        # Show wait dialog while parsing data...
        #
        dialog_wait = xbmcgui.DialogProgress()
        dialog_wait.create(LANGUAGE(30504), self.title)
        # wait 1 second
        xbmc.sleep(1000)

        html_source = ""
        try:
            if SETTINGS.getSetting("nsfw") == "true":
                response = requests.get(self.video_page_url, cookies={"nsfw": "1"})
            else:
                response = requests.get(self.video_page_url)

            html_source = response.text
        except urllib2.HTTPError, error:
            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s" % (ADDON, VERSION, DATE, "HTTPError", str(error)),
                xbmc.LOGDEBUG,
            )
            dialog_wait.close()
            del dialog_wait
            xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30507) % (str(error)))
            exit(1)
예제 #9
0
    def __init__(self):
        # Get the command line arguments
        # Get the plugin url in plugin:// notation
        self.plugin_url = sys.argv[0]
        # Get the plugin handle as an integer number
        self.plugin_handle = int(sys.argv[1])

        # Get plugin settings
        self.VIDEO = SETTINGS.getSetting('video')

        log("ARGV", repr(sys.argv))

        # Parse parameters...
        self.file = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['file'][0]

        log("self.file",self.file)

        #
        # Play video...
        #
        self.playVideo()
LIB_DIR = xbmc.translatePath(
    os.path.join(xbmcaddon.Addon(id="plugin.video.dumpert").getAddonInfo('path'), 'resources', 'lib'))
sys.path.append(LIB_DIR)

from dumpert_const import ADDON, DATE, VERSION, SETTINGS

# Parse parameters...
if len(sys.argv[2]) == 0:
    #
    # Main menu
    #
    xbmc.log("[ADDON] %s, Python Version %s" % (ADDON, str(sys.version)), xbmc.LOGDEBUG)
    xbmc.log("[ADDON] %s v%s (%s) is starting, ARGV = %s" % (ADDON, VERSION, DATE, repr(sys.argv)),
                 xbmc.LOGDEBUG)

    if SETTINGS.getSetting('onlyshownewvideocategory') == 'true':
        import dumpert_list as plugin
    else:
        import dumpert_main as plugin
else:
    action = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['action'][0]
    #
    # Themas
    #
    if action == 'list-themas':
        import dumpert_list_themas as plugin
    #
    # List
    #
    elif action == 'list':
        import dumpert_list as plugin
예제 #11
0
    def getVideos(self):
        #
        # Init
        #
        shownsfw = (SETTINGS.getSetting('nsfw') == 'true')
        listing = []

        #
        # Get data
        #
        json_source = requests.get(self.video_list_page_url).text
        data = json.loads(json_source)
        if not data['success']:
            xbmcplugin.endOfDirectory(self.plugin_handle)
            return

        for item in data['items']:
            title = item['title']
            description = item['description']
            thumbnail_url = item['thumbnail']
            nsfw = item['nsfw']
            if not nsfw or shownsfw:
                # grab first item (tablet)
                # skip embedded (youtube links) for now {"version":"embed","uri":"youtube:wOeZB7bnoxw"}
                if item['media'][0]['mediatype'] == 'VIDEO' and item['media'][0]['variants'][0]['version'] != 'embed':
                    url = item['media'][0]['variants'][0]['uri']
                    list_item = xbmcgui.ListItem(label=title, thumbnailImage=thumbnail_url)
                    list_item.setInfo("video", {"title": title, "studio": ADDON, "plot": description})
                    list_item.setArt({'thumb': thumbnail_url, 'icon': thumbnail_url,'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
                    list_item.setProperty('IsPlayable', 'true')
                    is_folder = False
                    # Add refresh option to context menu
                    list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
                    # Add our item to the listing as a 3-element tuple.
                    listing.append((url, list_item, is_folder))

        # Next page entry
        if self.next_page_possible == 'True':
            next_page = self.current_page + 1
            list_item = xbmcgui.ListItem(LANGUAGE(30503), thumbnailImage=os.path.join(IMAGES_PATH, 'next-page.png'))
            list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            parameters = {"action": "json", "plugin_category": self.plugin_category,
                          "url": str(self.base_url) + str(next_page) + '/',
                          "next_page_possible": self.next_page_possible}
            url = self.plugin_url + '?' + urllib.urlencode(parameters)
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))



        # Add our listing to Kodi.
        # Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
        # instead of adding one by ove via addDirectoryItem.
        xbmcplugin.addDirectoryItems(self.plugin_handle, listing, len(listing))
        # Disable sorting
        xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_NONE)
        # Finish creating a virtual folder.
        xbmcplugin.endOfDirectory(self.plugin_handle)
    def __init__(self):
        # Get the command line arguments
        # Get the plugin url in plugin:// notation
        self.plugin_url = sys.argv[0]
        # Get the plugin handle as an integer number
        self.plugin_handle = int(sys.argv[1])

        # Get plugin settings
        self.DEBUG = SETTINGS.getSetting('debug')

        if self.DEBUG == 'true':
            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s, %s = %s" %
                (ADDON, VERSION, DATE, "ARGV", repr(
                    sys.argv), "File", str(__file__)), xbmc.LOGNOTICE)

        date = xbmcgui.Dialog().numeric(1, LANGUAGE(30509))
        if not date is None:
            date = date.replace(' ', '')
            try:
                try:
                    date = datetime.strptime(date, '%d/%m/%Y')
                except TypeError:
                    date = datetime(*(time.strptime(date, '%d/%m/%Y')[0:6]))
            except ValueError:
                date = datetime.now()
        else:
            date = datetime.now()

        if date > datetime.now() or date < datetime(2006, 1, 1):
            date = datetime.now()

        daytop = 'http://dumpert.nl/mobile_api/json/top5/%s/%s/0/' % (
            'dag', date.strftime('%Y-%m-%d'))
        weektop = 'http://dumpert.nl/mobile_api/json/top5/%s/%s%s/0/' % (
            'week', date.strftime('%Y'), date.isocalendar()[1])
        monthtop = 'http://dumpert.nl/mobile_api/json/top5/%s/%s/0/' % (
            'maand', date.strftime('%Y%m'))

        title = LANGUAGE(30510) % date.strftime('%d %b %Y')
        # Next page is not available for top5
        parameters = {
            "action": "json",
            "plugin_category": title,
            "url": daytop,
            "next_page_possible": "False"
        }
        url = self.plugin_url + '?' + urllib.urlencode(parameters)
        list_item = xbmcgui.ListItem(title, iconImage="DefaultFolder.png")
        is_folder = True
        list_item.setArt(
            {'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
        list_item.setProperty('IsPlayable', 'false')
        xbmcplugin.addDirectoryItem(handle=self.plugin_handle,
                                    url=url,
                                    listitem=list_item,
                                    isFolder=is_folder)

        title = LANGUAGE(30511) % date.strftime('%d %b %Y')
        # Next page is not available for top5
        parameters = {
            "action": "json",
            "plugin_category": title,
            "url": weektop,
            "next_page_possible": "False"
        }
        url = self.plugin_url + '?' + urllib.urlencode(parameters)
        list_item = xbmcgui.ListItem(title, iconImage="DefaultFolder.png")
        is_folder = True
        list_item.setArt(
            {'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
        list_item.setProperty('IsPlayable', 'false')
        xbmcplugin.addDirectoryItem(handle=self.plugin_handle,
                                    url=url,
                                    listitem=list_item,
                                    isFolder=is_folder)

        title = LANGUAGE(30512) % date.strftime('%d %b %Y')
        # Next page is not available for top5
        parameters = {
            "action": "json",
            "plugin_category": title,
            "url": monthtop,
            "next_page_possible": "False"
        }
        url = self.plugin_url + '?' + urllib.urlencode(parameters)
        list_item = xbmcgui.ListItem(title, iconImage="DefaultFolder.png")
        is_folder = True
        list_item.setArt(
            {'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
        list_item.setProperty('IsPlayable', 'false')
        xbmcplugin.addDirectoryItem(handle=self.plugin_handle,
                                    url=url,
                                    listitem=list_item,
                                    isFolder=is_folder)

        # Disable sorting
        xbmcplugin.addSortMethod(handle=self.plugin_handle,
                                 sortMethod=xbmcplugin.SORT_METHOD_NONE)
        # Finish creating a virtual folder.
        xbmcplugin.endOfDirectory(self.plugin_handle)
예제 #13
0
    def getVideos(self):
        #
        # Init
        #
        titles_and_thumbnail_urls_index = 0
        list_item = ''
        # Create a list for our items.
        listing = []

        #
        # Get HTML page
        #

        # Make a session
        sess = requests.session()

        # Set cookies for cookie-firewall and nsfw-switch
        if SETTINGS.getSetting('nsfw') == 'true':
            cookies = {"Cookie": "cpc=10", "nsfw": "1"}
        else:
            cookies = {"Cookie": "cpc=10"}

        # Determine if cloudflare protection is active or not
        html_source = sess.get(self.video_list_page_url, cookies=cookies).text
        if str(html_source).find("cloudflare") >= 0:
            cloudflare_active = True
        else:
            cloudflare_active = False

        # Get the page
        if cloudflare_active == True:
            try:
                import cfscrape
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30513))
                sys.exit(1)
            try:
                # returns a CloudflareScraper instance
                scraper = cfscrape.create_scraper(sess)
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30514))
                sys.exit(1)
            try:
                html_source = scraper.get(self.video_list_page_url).content
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30515))
                sys.exit(1)

        # Parse response
        soup = BeautifulSoup(html_source)

        # Find titles and thumnail-urls
        # img src="http://static.dumpert.nl/sq_thumbs/2245331_272bd4c3.jpg" alt="Turnlulz" title="Turnlulz" width="100" height="100" />
        # titles_and_thumbnail_urls = soup.findAll('img', attrs={'src': re.compile("^http://static.dumpert.nl/")} )
        titles_and_thumbnail_urls = soup.findAll(
            'img', attrs={'src': re.compile("thumb")})

        xbmc.log(
            "[ADDON] %s v%s (%s) debug mode, %s = %s" %
            (ADDON, VERSION, DATE, "len(titles_and_thumbnail_urlszzzzzz)",
             str(len(titles_and_thumbnail_urls))), xbmc.LOGDEBUG)

        # Find video page urls
        # <a href="http://www.dumpert.nl/mediabase/2245331/272bd4c3/turnlulz.html" class="dumpthumb" title="Turnlulz">
        video_page_urls = soup.findAll(
            'a', attrs={'class': re.compile("dumpthumb")})

        xbmc.log(
            "[ADDON] %s v%s (%s) debug mode, %s = %s" %
            (ADDON, VERSION, DATE, "len(video_page_urls)",
             str(len(video_page_urls))), xbmc.LOGDEBUG)

        # in thema pages the first thumbnail is a thumbnail of the thema itself and not of a video
        # if that's the case: skip the first thumbnail
        if len(titles_and_thumbnail_urls) == len(video_page_urls) + 1:
            titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1

        for video_page_url in video_page_urls:
            pos_of_video_tag = str(video_page_url).find('class="video"')
            if pos_of_video_tag >= 0:
                pass
            else:
                # skip video page url without a video
                xbmc.log(
                    "[ADDON] %s v%s (%s) debug mode, %s = %s" %
                    (ADDON, VERSION,
                     DATE, "skipped video_page_url without video",
                     str(video_page_url)), xbmc.LOGDEBUG)
                titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1
                continue

            video_page_url = video_page_url['href']

            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s" %
                (ADDON, VERSION, DATE, "video_page_url", str(video_page_url)),
                xbmc.LOGDEBUG)

            # if link doesn't contain 'html': skip the link ('continue')
            if video_page_url.find('html') >= 0:
                pass
            else:
                xbmc.log(
                    "[ADDON] %s v%s (%s) debug mode, %s = %s" %
                    (ADDON, VERSION,
                     DATE, "skipped video_page_url without html",
                     str(video_page_url)), xbmc.LOGDEBUG)
                titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1
                continue

            description = '...'
            # <a href="http://www.dumpert.nl/mediabase/6721593/46f416fa/stukje_snowboarden.html?thema=bikini" class="dumpthumb" title="Stukje snowboarden">
            #	<img src="http://media.dumpert.nl/sq_thumbs/6721593_46f416fa.jpg" alt="Stukje snowboarden" title="Stukje snowboarden" width="100" height="100" />
            #	<span class="video"></span>
            #	<div class="details">
            #		<h1>Stukje snowboarden</h1>
            #		<date>5 februari 2016 10:32</date>
            #		<p class="stats">views: 63687 kudos: 313</p>
            #		<p class="description">F**k winterkleding </p>
            #	</div>
            # </a>
            try:
                description = titles_and_thumbnail_urls[
                    titles_and_thumbnail_urls_index].parent.find(
                        "p", "description").string
                description = description.encode('utf-8')
            except:
                pass

            # Make title
            title = ''
            try:
                title = titles_and_thumbnail_urls[
                    titles_and_thumbnail_urls_index]['title']
                # convert from unicode to encoded text (don't use str() to do this)
                title = title.encode('utf-8')
            # <a href="http://www.dumpert.nl/mediabase/1958831/21e6267f/pixar_s_up_inspreken.html?thema=animatie" class="dumpthumb" title="Pixar's &quot;Up&quot; inspreken ">
            except KeyError:
                # http://www.dumpert.nl/mediabase/6532392/82471b66/dumpert_heeft_talent.html
                title = str(video_page_url)
                pos_last_slash = title.rfind('/')
                pos_last_dot = title.rfind('.')
                title = title[pos_last_slash + 1:pos_last_dot]
                title = title.capitalize()
            except UnicodeDecodeError:
                pass

            title = title.replace('-', ' ')
            title = title.replace('/', ' ')
            title = title.replace('_', ' ')

            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s" %
                (ADDON, VERSION, DATE, "title", str(title)), xbmc.LOGDEBUG)

            if titles_and_thumbnail_urls_index >= len(
                    titles_and_thumbnail_urls):
                thumbnail_url = ''
            else:
                thumbnail_url = titles_and_thumbnail_urls[
                    titles_and_thumbnail_urls_index]['src']

            list_item = xbmcgui.ListItem(label=title,
                                         thumbnailImage=thumbnail_url)
            list_item.setInfo("video", {
                "title": title,
                "studio": ADDON,
                "plot": description
            })
            list_item.setArt({
                'thumb':
                thumbnail_url,
                'icon':
                thumbnail_url,
                'fanart':
                os.path.join(IMAGES_PATH, 'fanart-blur.jpg')
            })
            list_item.setProperty('IsPlayable', 'true')
            parameters = {
                "action": "play",
                "video_page_url": video_page_url,
                "title": title
            }
            url = self.plugin_url + '?' + urllib.urlencode(parameters)
            is_folder = False
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))

            titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1

        # Next page entry
        if self.next_page_possible == 'True':
            next_page = self.current_page + 1
            list_item = xbmcgui.ListItem(LANGUAGE(30503),
                                         thumbnailImage=os.path.join(
                                             IMAGES_PATH, 'next-page.png'))
            list_item.setArt(
                {'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            parameters = {
                "action": "list",
                "plugin_category": self.plugin_category,
                "url": str(self.base_url) + str(next_page) + '/',
                "next_page_possible": self.next_page_possible
            }
            url = self.plugin_url + '?' + urllib.urlencode(parameters)
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))

        # Add our listing to Kodi.
        # Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
        # instead of adding one by ove via addDirectoryItem.
        xbmcplugin.addDirectoryItems(self.plugin_handle, listing, len(listing))
        # Disable sorting
        xbmcplugin.addSortMethod(handle=self.plugin_handle,
                                 sortMethod=xbmcplugin.SORT_METHOD_NONE)
        # Finish creating a virtual folder.
        xbmcplugin.endOfDirectory(self.plugin_handle)
    def getVideos(self):
        #
        # Init
        #
        shownsfw = (SETTINGS.getSetting('nsfw') == 'true')
        listing = []

        #
        # Get HTML page
        #
        response = requests.get(self.video_list_page_url)
        # response.status
        json_source = response.text
        json_source = convertToUnicodeString(json_source)
        data = json.loads(json_source)
        if not data['success']:
            xbmcplugin.endOfDirectory(self.plugin_handle)
            return

        for item in data['items']:
            title = item['title']
            description = item['description']
            thumbnail_url = item['stills']['still-large']
            for i in item['media']:
                duration = i.get('duration', False)

            nsfw = item['nsfw']
            if not nsfw or shownsfw:
                # {"id":"6737324_36df9881","title":"Hardcore brei-oma","thumbnail":"http:\/\/media.dumpert.nl\/sq_thumbs\/6737324_36df9881.jpg",
                # "still":"http:\/\/media.dumpert.nl\/stills\/6737324_36df9881.jpg","description":"Heeft vroeger wat uitgevroten... WTF?","date":"2016-03-18T19:35:56+01:00",
                # "tags":"dwdd oma wtf breien oud","nsfw":false,"nopreroll":false,"stats":{"views_total":466917,"views_today":32706,"kudos_total":4916,"kudos_today":343},
                # "stills":{"thumb":"http:\/\/media.dumpert.nl\/sq_thumbs\/6737324_36df9881.jpg","thumb-medium":"http:\/\/media.dumpert.nl\/sq_thumbs\/medium\/6737324_36df9881.jpg",
                # "still":"http:\/\/media.dumpert.nl\/stills\/6737324_36df9881.jpg","still-medium":"http:\/\/media.dumpert.nl\/stills\/medium\/6737324_36df9881.jpg",
                # "still-large":"http:\/\/media.dumpert.nl\/stills\/large\/6737324_36df9881.jpg"},"media":[{"description":"","mediatype":"VIDEO","duration":55,
                # "variants":[{"version":"tablet","uri":"http:\/\/media.dumpert.nl\/tablet\/36df9881_VID_20160318_WA0000.mp4.mp4.mp4"},{"version":"mobile",
                # "uri":"http:\/\/media.dumpert.nl\/mobile\/36df9881_VID_20160318_WA0000.mp4.mp4.mp4"}]}]}
                #
                # grab first item (tablet)
                # skip embedded (youtube links) for now {"version":"embed","uri":"youtube:wOeZB7bnoxw"}
                if item['media'][0]['mediatype'] == 'VIDEO' and item['media'][
                        0]['variants'][0]['version'] != 'embed':
                    file = item['media'][0]['variants'][0]['uri']

                    log("json file", file)

                    list_item = xbmcgui.ListItem(label=title,
                                                 thumbnailImage=thumbnail_url)
                    list_item.setInfo(
                        "video", {
                            "title": title,
                            "studio": "Dumpert",
                            "mediatype": "video",
                            "plot": description
                        })
                    list_item.setArt({
                        'thumb':
                        thumbnail_url,
                        'icon':
                        thumbnail_url,
                        'fanart':
                        os.path.join(IMAGES_PATH, 'fanart-blur.jpg')
                    })
                    list_item.setProperty('IsPlayable', 'true')
                    parameters = {"action": "play-file", "file": file}
                    url = self.plugin_url + '?' + urllib.parse.urlencode(
                        parameters)
                    is_folder = False
                    # Add refresh option to context menu
                    list_item.addContextMenuItems([('Refresh',
                                                    'Container.Refresh')])
                    # Add our item to the listing as a 3-element tuple.
                    listing.append((url, list_item, is_folder))

        # Next page entry
        if self.next_page_possible == 'True':
            next_page = self.current_page + 1
            list_item = xbmcgui.ListItem(LANGUAGE(30503),
                                         thumbnailImage=os.path.join(
                                             IMAGES_PATH, 'next-page.png'))
            list_item.setArt(
                {'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            parameters = {
                "action": "json",
                "plugin_category": self.plugin_category,
                "url": str(self.base_url) + str(next_page) + '/',
                "next_page_possible": self.next_page_possible
            }
            url = self.plugin_url + '?' + urllib.parse.urlencode(parameters)
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))

        # Add our listing to Kodi.
        # Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
        # instead of adding one by one via addDirectoryItem.
        xbmcplugin.addDirectoryItems(self.plugin_handle, listing, len(listing))
        # Disable sorting
        xbmcplugin.addSortMethod(handle=self.plugin_handle,
                                 sortMethod=xbmcplugin.SORT_METHOD_NONE)
        # Finish creating a virtual folder.
        xbmcplugin.endOfDirectory(self.plugin_handle)
예제 #15
0
    def getVideos(self):
        #
        # Init
        #
        shownsfw = (SETTINGS.getSetting('nsfw') == 'true')
        listing = []

        #
        # Get data
        #

        # Set cookies for cookie-firewall and nsfw-switch
        if SETTINGS.getSetting('nsfw') == 'true':
            cookies = {"Cookie": "cpc=10", "nsfw": "1"}
        else:
            cookies = {"Cookie": "cpc=10"}

        # Determine if cloudflare protection is active or not
        html_source = requests.get(self.video_list_page_url,
                                   cookies=cookies).text
        if str(html_source).find("cloudflare") >= 0:
            cloudflare_active = True
        else:
            cloudflare_active = False

        # Make a session
        sess = requests.session()

        # Get the page
        if cloudflare_active == True:
            try:
                import cfscrape
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30513))
                sys.exit(1)
            try:
                # returns a CloudflareScraper instance
                scraper = cfscrape.create_scraper(sess)
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30514))
                sys.exit(1)
            try:
                html_source = scraper.get(self.video_list_page_url).content
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30515))
                sys.exit(1)
        else:
            html_source = sess.get(self.video_list_page_url,
                                   cookies=cookies).text

        json_source = html_source
        data = json.loads(json_source)
        if not data['success']:
            xbmcplugin.endOfDirectory(self.plugin_handle)
            return

        for item in data['items']:
            title = item['title']
            description = item['description']
            thumbnail_url = item['thumbnail']
            nsfw = item['nsfw']
            if not nsfw or shownsfw:
                # {"id":"6737324_36df9881","title":"Hardcore brei-oma","thumbnail":"http:\/\/media.dumpert.nl\/sq_thumbs\/6737324_36df9881.jpg",
                # "still":"http:\/\/media.dumpert.nl\/stills\/6737324_36df9881.jpg","description":"Heeft vroeger wat uitgevroten... WTF?","date":"2016-03-18T19:35:56+01:00",
                # "tags":"dwdd oma wtf breien oud","nsfw":false,"nopreroll":false,"stats":{"views_total":466917,"views_today":32706,"kudos_total":4916,"kudos_today":343},
                # "stills":{"thumb":"http:\/\/media.dumpert.nl\/sq_thumbs\/6737324_36df9881.jpg","thumb-medium":"http:\/\/media.dumpert.nl\/sq_thumbs\/medium\/6737324_36df9881.jpg",
                # "still":"http:\/\/media.dumpert.nl\/stills\/6737324_36df9881.jpg","still-medium":"http:\/\/media.dumpert.nl\/stills\/medium\/6737324_36df9881.jpg",
                # "still-large":"http:\/\/media.dumpert.nl\/stills\/large\/6737324_36df9881.jpg"},"media":[{"description":"","mediatype":"VIDEO","duration":55,
                # "variants":[{"version":"tablet","uri":"http:\/\/media.dumpert.nl\/tablet\/36df9881_VID_20160318_WA0000.mp4.mp4.mp4"},{"version":"mobile",
                # "uri":"http:\/\/media.dumpert.nl\/mobile\/36df9881_VID_20160318_WA0000.mp4.mp4.mp4"}]}]}
                #
                # grab first item (tablet)
                # skip embedded (youtube links) for now {"version":"embed","uri":"youtube:wOeZB7bnoxw"}
                if item['media'][0]['mediatype'] == 'VIDEO' and item['media'][
                        0]['variants'][0]['version'] != 'embed':
                    url = item['media'][0]['variants'][0]['uri']
                    list_item = xbmcgui.ListItem(label=title,
                                                 thumbnailImage=thumbnail_url)
                    list_item.setInfo("video", {
                        "title": title,
                        "studio": ADDON,
                        "plot": description
                    })
                    list_item.setArt({
                        'thumb':
                        thumbnail_url,
                        'icon':
                        thumbnail_url,
                        'fanart':
                        os.path.join(IMAGES_PATH, 'fanart-blur.jpg')
                    })
                    list_item.setProperty('IsPlayable', 'true')
                    is_folder = False
                    # Add refresh option to context menu
                    list_item.addContextMenuItems([('Refresh',
                                                    'Container.Refresh')])
                    # Add our item to the listing as a 3-element tuple.
                    listing.append((url, list_item, is_folder))

        # Next page entry
        if self.next_page_possible == 'True':
            next_page = self.current_page + 1
            list_item = xbmcgui.ListItem(LANGUAGE(30503),
                                         thumbnailImage=os.path.join(
                                             IMAGES_PATH, 'next-page.png'))
            list_item.setArt(
                {'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            parameters = {
                "action": "json",
                "plugin_category": self.plugin_category,
                "url": str(self.base_url) + str(next_page) + '/',
                "next_page_possible": self.next_page_possible
            }
            url = self.plugin_url + '?' + urllib.urlencode(parameters)
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))

        # Add our listing to Kodi.
        # Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
        # instead of adding one by ove via addDirectoryItem.
        xbmcplugin.addDirectoryItems(self.plugin_handle, listing, len(listing))
        # Disable sorting
        xbmcplugin.addSortMethod(handle=self.plugin_handle,
                                 sortMethod=xbmcplugin.SORT_METHOD_NONE)
        # Finish creating a virtual folder.
        xbmcplugin.endOfDirectory(self.plugin_handle)
예제 #16
0
    def getVideos(self):
        #
        # Init
        #
        shownsfw = (SETTINGS.getSetting('nsfw') == 'true')
        listing = []

        #
        # Get data
        #
        json_source = requests.get(self.video_list_page_url).text
        data = json.loads(json_source)
        if not data['success']:
            xbmcplugin.endOfDirectory(self.plugin_handle)
            return

        for item in data['items']:
            title = item['title']
            description = item['description']
            thumbnail_url = item['stills']['still-large']
            for i in item['media']:
                duration = i.get('duration',False)

            nsfw = item['nsfw']
            if not nsfw or shownsfw:
                # {"id":"6737324_36df9881","title":"Hardcore brei-oma","thumbnail":"http:\/\/media.dumpert.nl\/sq_thumbs\/6737324_36df9881.jpg",
                # "still":"http:\/\/media.dumpert.nl\/stills\/6737324_36df9881.jpg","description":"Heeft vroeger wat uitgevroten... WTF?","date":"2016-03-18T19:35:56+01:00",
                # "tags":"dwdd oma wtf breien oud","nsfw":false,"nopreroll":false,"stats":{"views_total":466917,"views_today":32706,"kudos_total":4916,"kudos_today":343},
                # "stills":{"thumb":"http:\/\/media.dumpert.nl\/sq_thumbs\/6737324_36df9881.jpg","thumb-medium":"http:\/\/media.dumpert.nl\/sq_thumbs\/medium\/6737324_36df9881.jpg",
                # "still":"http:\/\/media.dumpert.nl\/stills\/6737324_36df9881.jpg","still-medium":"http:\/\/media.dumpert.nl\/stills\/medium\/6737324_36df9881.jpg",
                # "still-large":"http:\/\/media.dumpert.nl\/stills\/large\/6737324_36df9881.jpg"},"media":[{"description":"","mediatype":"VIDEO","duration":55,
                # "variants":[{"version":"tablet","uri":"http:\/\/media.dumpert.nl\/tablet\/36df9881_VID_20160318_WA0000.mp4.mp4.mp4"},{"version":"mobile",
                # "uri":"http:\/\/media.dumpert.nl\/mobile\/36df9881_VID_20160318_WA0000.mp4.mp4.mp4"}]}]}
                #
                # grab first item (tablet)
                # skip embedded (youtube links) for now {"version":"embed","uri":"youtube:wOeZB7bnoxw"}
                if item['media'][0]['mediatype'] == 'VIDEO' and item['media'][0]['variants'][0]['version'] != 'embed':
                    url = item['media'][0]['variants'][0]['uri']
                    list_item = xbmcgui.ListItem(label=title, thumbnailImage=thumbnail_url)
                    list_item.setInfo("video", {"title": title, "studio": "Dumpert", "mediatype": "video", "plot": description, "duration": duration})
                    list_item.setArt({'thumb': thumbnail_url, 'icon': thumbnail_url,
                                      'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
                    list_item.setProperty('IsPlayable', 'true')
                    is_folder = False
                    # Add refresh option to context menu
                    list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
                    # Add our item to the listing as a 3-element tuple.
                    listing.append((url, list_item, is_folder))

        # Next page entry
        if self.next_page_possible == 'True':
            next_page = self.current_page + 1
            list_item = xbmcgui.ListItem(LANGUAGE(30503), thumbnailImage=os.path.join(IMAGES_PATH, 'next-page.png'))
            list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            parameters = {"action": "json", "plugin_category": self.plugin_category,
                          "url": str(self.base_url) + str(next_page) + '/',
                          "next_page_possible": self.next_page_possible}
            url = self.plugin_url + '?' + urllib.urlencode(parameters)
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))

        # Add our listing to Kodi.
        # Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
        # instead of adding one by one via addDirectoryItem.
        xbmcplugin.addDirectoryItems(self.plugin_handle, listing, len(listing))
        # Disable sorting
        xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_NONE)
        # Finish creating a virtual folder.
        xbmcplugin.endOfDirectory(self.plugin_handle)
    def getVideos(self):
        #
        # Init
        #
        thumbnail_urls_index = 0
        current_page = ''
        theme_base_url = ''
        list_item = ''

        #
        # Get HTML page...
        #
        # Make a session
        sess = requests.session()

        # Set cookies for cookie-firewall and nsfw-switch
        if SETTINGS.getSetting('nsfw') == 'true':
            cookies = {"Cookie": "cpc=10", "nsfw": "1"}
        else:
            cookies = {"Cookie": "cpc=10"}

        # Determine if cloudflare protection is active or not
        html_source = sess.get(self.video_list_page_url, cookies=cookies).text
        if str(html_source).find("cloudflare") >= 0:
            cloudflare_active = True
        else:
            cloudflare_active = False

        # Get the page
        if cloudflare_active == True:
            try:
                import cfscrape
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30513))
                sys.exit(1)
            try:
                # returns a CloudflareScraper instance
                scraper = cfscrape.create_scraper(sess)
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30514))
                sys.exit(1)
            try:
                html_source = scraper.get(self.video_list_page_url).content
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30515))
                sys.exit(1)

        # Parse response...
        soup = BeautifulSoup(html_source)

        # <img src="http://static.dumpert.nl/s/trailerts_gr.jpg" alt="" />
        thumbnail_urls = soup.findAll(
            'img', attrs={'src': re.compile("^http://static.dumpert.nl/")})

        xbmc.log(
            "[ADDON] %s v%s (%s) debug mode, %s = %s" %
            (ADDON, VERSION, DATE, "len(thumbnail_urls)",
             str(len(thumbnail_urls))), xbmc.LOGDEBUG)

        # <a href="/themas/uit_het_archief/" class="themalink big">
        # <a href="/themas/liev/" class="themalink">
        video_page_urls = soup.findAll(
            'a', attrs={'class': re.compile("^themalink")})

        xbmc.log(
            "[ADDON] %s v%s (%s) debug mode, %s = %s" %
            (ADDON, VERSION, DATE, "len(video_page_urls)",
             str(len(video_page_urls))), xbmc.LOGDEBUG)

        for video_page_url in video_page_urls:
            video_page_url = video_page_url['href']
            # remove '/themas/'
            video_page_url = video_page_url.replace('/themas/', '')
            # http://www.dumpert.nl/<thema>/
            theme_base_url = str(self.base_url) + str(video_page_url)
            current_page = 1

            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s" %
                (ADDON, VERSION, DATE, "self.theme_base_url",
                 str(theme_base_url)), xbmc.LOGDEBUG)

            # Make title
            # http://static.dumpert.nl/themas/politiek_kl.jpg
            title = str(video_page_url)
            pos_of_last_slash = title.rfind('/')
            # remove last slash
            title = title[0:pos_of_last_slash]
            pos_of_last_slash = title.rfind('/')
            title = title[pos_of_last_slash + 1:]
            title = title.capitalize()
            title = title.replace('-', ' ')
            title = title.replace('/', ' ')
            title = title.replace('_kl', '')
            title = title.replace('_', ' ')

            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s" %
                (ADDON, VERSION, DATE, "title", str(title)), xbmc.LOGDEBUG)

            if thumbnail_urls_index >= len(thumbnail_urls):
                thumbnail_url = ''
            else:
                thumbnail_url = thumbnail_urls[thumbnail_urls_index]['src']

            # Add to list...
            parameters = {
                "action": "list",
                "plugin_category": self.plugin_category,
                "url": str(theme_base_url) + str(current_page) + '/',
                "next_page_possible": "True",
                "title": title
            }
            url = sys.argv[0] + '?' + urllib.urlencode(parameters)
            list_item = xbmcgui.ListItem(title, thumbnailImage=thumbnail_url)
            list_item.setInfo("video", {"Title": title, "Studio": "Dumpert"})
            list_item.setArt({
                'thumb':
                thumbnail_url,
                'icon':
                thumbnail_url,
                'fanart':
                os.path.join(IMAGES_PATH, 'fanart-blur.jpg')
            })
            list_item.setProperty('IsPlayable', 'false')
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                        url=url,
                                        listitem=list_item,
                                        isFolder=is_folder)

            thumbnail_urls_index = thumbnail_urls_index + 1

        # Next page entry...
        if self.next_page_possible == 'True':
            next_page = current_page + 1
            parameters = {
                "action": "list",
                "plugin_category": self.plugin_category,
                "url": str(theme_base_url) + str(next_page) + '/',
                "next_page_possible": self.next_page_possible
            }
            url = sys.argv[0] + '?' + urllib.urlencode(parameters)
            list_item = xbmcgui.ListItem(LANGUAGE(30503),
                                         thumbnailImage=os.path.join(
                                             IMAGES_PATH, 'next-page.png'))
            list_item.setArt(
                {'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                        url=url,
                                        listitem=list_item,
                                        isFolder=is_folder)

            xbmc.log(
                "[ADDON] %s v%s (%s) debug mode, %s = %s" %
                (ADDON, VERSION, DATE, "next url", str(url)), xbmc.LOGDEBUG)

        # Sort on labels...
        xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                                 sortMethod=xbmcplugin.SORT_METHOD_LABEL)

        # End of directory...
        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True)
예제 #18
0
    def playVideo(self):
        #
        # Init
        #
        no_url_found = False
        unplayable_media_file = False
        have_valid_url = False

        #
        # Get current list item details...
        #
        # title = unicode(xbmc.getInfoLabel("listitem.Title"), "utf-8")
        thumbnail_url = xbmc.getInfoImage("list_item.Thumb")
        # studio = unicode(xbmc.getInfoLabel("list_item.Studio"), "utf-8")
        plot = unicode(xbmc.getInfoLabel("list_item.Plot"), "utf-8")
        genre = unicode(xbmc.getInfoLabel("list_item.Genre"), "utf-8")

        #
        # Show wait dialog while parsing data...
        #
        dialog_wait = xbmcgui.DialogProgress()
        dialog_wait.create(LANGUAGE(30504), self.title)
        # wait 1 second
        xbmc.sleep(1000)

        # Set cookies for cookie-firewall and nsfw-switch
        if SETTINGS.getSetting('nsfw') == 'true':
            cookies = {"Cookie": "cpc=10", "nsfw": "1"}
        else:
            cookies = {"Cookie": "cpc=10"}

            # Make a session
            sess = requests.session()

            # Set cookies for cookie-firewall and nsfw-switch
            if SETTINGS.getSetting('nsfw') == 'true':
                cookies = {"Cookie": "cpc=10", "nsfw": "1"}
            else:
                cookies = {"Cookie": "cpc=10"}

            # Determine if cloudflare protection is active or not
            html_source = sess.get(self.video_page_url, cookies=cookies).text
            if str(html_source).find("cloudflare") >= 0:
                cloudflare_active = True
            else:
                cloudflare_active = False

            # Get the page
            if cloudflare_active == True:
                try:
                    import cfscrape
                except:
                    xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30513))
                    sys.exit(1)
                try:
                    # returns a CloudflareScraper instance
                    scraper = cfscrape.create_scraper(sess)
                except:
                    xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30514))
                    sys.exit(1)
                try:
                    html_source = scraper.get(self.video_page_url).content
                except:
                    xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30515))
                    sys.exit(1)

        soup = BeautifulSoup(html_source)

        video_url = ''
        # <div class="videoplayer" id="video1" data-files="eyJmbHYiOiJodHRwOlwvXC9tZWRpYS5kdW1wZXJ0Lm5sXC9mbHZcLzI4OTE2NWRhXzEwMjU1NzUyXzYzODMxODA4OTU1NDc2MV84MTk0MzU3MDVfbi5tcDQuZmx2IiwidGFibGV0IjoiaHR0cDpcL1wvbWVkaWEuZHVtcGVydC5ubFwvdGFibGV0XC8yODkxNjVkYV8xMDI1NTc1Ml82MzgzMTgwODk1NTQ3NjFfODE5NDM1NzA1X24ubXA0Lm1wNCIsIm1vYmlsZSI6Imh0dHA6XC9cL21lZGlhLmR1bXBlcnQubmxcL21vYmlsZVwvMjg5MTY1ZGFfMTAyNTU3NTJfNjM4MzE4MDg5NTU0NzYxXzgxOTQzNTcwNV9uLm1wNC5tcDQiLCJzdGlsbCI6Imh0dHA6XC9cL3N0YXRpYy5kdW1wZXJ0Lm5sXC9zdGlsbHNcLzY1OTM1MjRfMjg5MTY1ZGEuanBnIn0="></div></div>
        video_urls = soup.findAll('div', attrs={'class': re.compile("video")}, limit=1)
        if len(video_urls) == 0:
            no_url_found = True
        else:
            video_url_enc = video_urls[0]['data-files']
            # base64 decode
            video_url_dec = str(base64.b64decode(video_url_enc))
            # {"flv":"http:\/\/media.dumpert.nl\/flv\/5770e490_Jumbo_KOOP_DAN__Remix.avi.flv","tablet":"http:\/\/media.dumpert.nl\/tablet\/5770e490_Jumbo_KOOP_DAN__Remix.avi.mp4","mobile":"http:\/\/media.dumpert.nl\/mobile\/5770e490_Jumbo_KOOP_DAN__Remix.avi.mp4","720p":"http:\/\/media.dumpert.nl\/720p\/5770e490_Jumbo_KOOP_DAN__Remix.avi.mp4","still":"http:\/\/static.dumpert.nl\/stills\/6593503_5770e490.jpg"}
            # or
            # {"embed":"youtube:U89fl5fZETE","still":"http:\/\/static.dumpert.nl\/stills\/6650228_24eed546.jpg"}

            xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                    ADDON, VERSION, DATE, "video_url_dec", str(video_url_dec)), xbmc.LOGDEBUG)

            # convert string to dictionary
            video_url_dec_dict = ast.literal_eval(video_url_dec)

            video_url_embed = ''
            try:
                video_url_embed = str(video_url_dec_dict['embed'])
                embed_found = True
            except KeyError:
                embed_found = False

            video_url = ''
            if embed_found:
                # make youtube plugin url
                youtube_id = video_url_embed.replace("youtube:", "")
                youtube_url = 'plugin://plugin.video.youtube/play/?video_id=%s' % youtube_id
                video_url = youtube_url
                have_valid_url = True
                xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                        ADDON, VERSION, DATE, "video_url1", str(video_url)), xbmc.LOGDEBUG)
            else:
                # matching the desired and available quality
                if self.VIDEO == '0':
                    try:
                        video_url = str(video_url_dec_dict['mobile'])
                    except KeyError:
                        no_url_found = True
                elif self.VIDEO == '1':
                    try:
                        video_url = str(video_url_dec_dict['tablet'])
                    except KeyError:
                        try:
                            video_url = str(video_url_dec_dict['mobile'])
                        except KeyError:
                            no_url_found = True
                elif self.VIDEO == '2':
                    try:
                        video_url = str(video_url_dec_dict['720p'])
                    except KeyError:
                        try:
                            video_url = str(video_url_dec_dict['tablet'])
                        except KeyError:
                            try:
                                video_url = str(video_url_dec_dict['mobile'])
                            except KeyError:
                                no_url_found = True

                if no_url_found:
                    pass
                else:
                    video_url = video_url.replace('\/', '/')
                    xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                            ADDON, VERSION, DATE, "video_url2", str(video_url)), xbmc.LOGDEBUG)

                    # The need for speed: let's guess that the video-url exists
                    have_valid_url = True

        # Play video...
        if have_valid_url:
            list_item = xbmcgui.ListItem(path=video_url)
            xbmcplugin.setResolvedUrl(self.plugin_handle, True, list_item)
        #
        # Alert user
        #
        elif no_url_found:
            xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30505))
        elif unplayable_media_file:
            xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30506))
    def getVideos(self):
        #
        # Init
        #
        thumbnail_urls_index = 0
        current_page = ''
        theme_base_url = ''
        list_item = ''

        #
        # Get HTML page...
        #
        # Make a session
        sess = requests.session()

        # Set cookies for cookie-firewall and nsfw-switch
        if SETTINGS.getSetting('nsfw') == 'true':
            cookies = {"Cookie": "cpc=10", "nsfw": "1"}
        else:
            cookies = {"Cookie": "cpc=10"}

        # Determine if cloudflare protection is active or not
        html_source = sess.get(self.video_list_page_url, cookies=cookies).text
        if str(html_source).find("cloudflare") >= 0:
            cloudflare_active = True
        else:
            cloudflare_active = False

        # Get the page
        if cloudflare_active == True:
            try:
                import cfscrape
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30513))
                sys.exit(1)
            try:
                # returns a CloudflareScraper instance
                scraper = cfscrape.create_scraper(sess)
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30514))
                sys.exit(1)
            try:
                html_source = scraper.get(self.video_list_page_url).content
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30515))
                sys.exit(1)

        # Parse response...
        soup = BeautifulSoup(html_source)

        # <img src="http://static.dumpert.nl/s/trailerts_gr.jpg" alt="" />
        thumbnail_urls = soup.findAll('img', attrs={'src': re.compile("^http://static.dumpert.nl/")})

        xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                ADDON, VERSION, DATE, "len(thumbnail_urls)", str(len(thumbnail_urls))), xbmc.LOGDEBUG)

        # <a href="/themas/uit_het_archief/" class="themalink big">
        # <a href="/themas/liev/" class="themalink">
        video_page_urls = soup.findAll('a', attrs={'class': re.compile("^themalink")})

        xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                ADDON, VERSION, DATE, "len(video_page_urls)", str(len(video_page_urls))), xbmc.LOGDEBUG)

        for video_page_url in video_page_urls:
            video_page_url = video_page_url['href']
            # remove '/themas/'
            video_page_url = video_page_url.replace('/themas/', '')
            # http://www.dumpert.nl/<thema>/
            theme_base_url = str(self.base_url) + str(video_page_url)
            current_page = 1

            xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                    ADDON, VERSION, DATE, "self.theme_base_url", str(theme_base_url)), xbmc.LOGDEBUG)

            # Make title
            # http://static.dumpert.nl/themas/politiek_kl.jpg
            title = str(video_page_url)
            pos_of_last_slash = title.rfind('/')
            # remove last slash
            title = title[0: pos_of_last_slash]
            pos_of_last_slash = title.rfind('/')
            title = title[pos_of_last_slash + 1:]
            title = title.capitalize()
            title = title.replace('-', ' ')
            title = title.replace('/', ' ')
            title = title.replace('_kl', '')
            title = title.replace('_', ' ')

            xbmc.log(
                    "[ADDON] %s v%s (%s) debug mode, %s = %s" % (ADDON, VERSION, DATE, "title", str(title)),
                    xbmc.LOGDEBUG)

            if thumbnail_urls_index >= len(thumbnail_urls):
                thumbnail_url = ''
            else:
                thumbnail_url = thumbnail_urls[thumbnail_urls_index]['src']

            # Add to list...
            parameters = {"action": "list", "plugin_category": self.plugin_category,
                          "url": str(theme_base_url) + str(current_page) + '/', "next_page_possible": "True",
                          "title": title}
            url = sys.argv[0] + '?' + urllib.urlencode(parameters)
            list_item = xbmcgui.ListItem(title, thumbnailImage=thumbnail_url)
            list_item.setInfo("video", {"Title": title, "Studio": "Dumpert"})
            list_item.setArt({'thumb': thumbnail_url, 'icon': thumbnail_url,
                              'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=list_item, isFolder=is_folder)

            thumbnail_urls_index = thumbnail_urls_index + 1

        # Next page entry...
        if self.next_page_possible == 'True':
            next_page = current_page + 1
            parameters = {"action": "list", "plugin_category": self.plugin_category,
                          "url": str(theme_base_url) + str(next_page) + '/',
                          "next_page_possible": self.next_page_possible}
            url = sys.argv[0] + '?' + urllib.urlencode(parameters)
            list_item = xbmcgui.ListItem(LANGUAGE(30503), thumbnailImage=os.path.join(IMAGES_PATH, 'next-page.png'))
            list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=list_item, isFolder=is_folder)

            xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                    ADDON, VERSION, DATE, "next url", str(url)), xbmc.LOGDEBUG)

        # Sort on labels...
        xbmcplugin.addSortMethod(handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_LABEL)

        # End of directory...
        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True)
    def getVideos(self):
        #
        # Init
        #
        titles_and_thumbnail_urls_index = 0
        list_item = ''
        # Create a list for our items.
        listing = []

        #
        # Get HTML page
        #

        # Make a session
        sess = requests.session()

        # Set cookies for cookie-firewall and nsfw-switch
        if SETTINGS.getSetting('nsfw') == 'true':
            cookies = {"Cookie": "cpc=10", "nsfw": "1"}
        else:
            cookies = {"Cookie": "cpc=10"}

        # Determine if cloudflare protection is active or not
        html_source = sess.get(self.video_list_page_url, cookies=cookies).text
        if str(html_source).find("cloudflare") >= 0:
            cloudflare_active = True
        else:
            cloudflare_active = False

        # Get the page
        if cloudflare_active == True:
            try:
                import cfscrape
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30513))
                sys.exit(1)
            try:
                # returns a CloudflareScraper instance
                scraper = cfscrape.create_scraper(sess)
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30514))
                sys.exit(1)
            try:
                html_source = scraper.get(self.video_list_page_url).content
            except:
                xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30515))
                sys.exit(1)

        # Parse response
        soup = BeautifulSoup(html_source)

        # Find titles and thumnail-urls
        # img src="http://static.dumpert.nl/sq_thumbs/2245331_272bd4c3.jpg" alt="Turnlulz" title="Turnlulz" width="100" height="100" />
        # titles_and_thumbnail_urls = soup.findAll('img', attrs={'src': re.compile("^http://static.dumpert.nl/")} )
        titles_and_thumbnail_urls = soup.findAll('img', attrs={'src': re.compile("thumb")})

        xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                ADDON, VERSION, DATE, "len(titles_and_thumbnail_urlszzzzzz)",
                str(len(titles_and_thumbnail_urls))),
                     xbmc.LOGDEBUG)

        # Find video page urls
        # <a href="http://www.dumpert.nl/mediabase/2245331/272bd4c3/turnlulz.html" class="dumpthumb" title="Turnlulz">
        video_page_urls = soup.findAll('a', attrs={'class': re.compile("dumpthumb")})

        xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                ADDON, VERSION, DATE, "len(video_page_urls)", str(len(video_page_urls))), xbmc.LOGDEBUG)

        # in thema pages the first thumbnail is a thumbnail of the thema itself and not of a video
        # if that's the case: skip the first thumbnail
        if len(titles_and_thumbnail_urls) == len(video_page_urls) + 1:
            titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1

        for video_page_url in video_page_urls:
            pos_of_video_tag = str(video_page_url).find('class="video"')
            if pos_of_video_tag >= 0:
                pass
            else:
                # skip video page url without a video
                xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                        ADDON, VERSION, DATE, "skipped video_page_url without video", str(video_page_url)),
                             xbmc.LOGDEBUG)
                titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1
                continue

            video_page_url = video_page_url['href']

            xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                    ADDON, VERSION, DATE, "video_page_url", str(video_page_url)), xbmc.LOGDEBUG)

            # if link doesn't contain 'html': skip the link ('continue')
            if video_page_url.find('html') >= 0:
                pass
            else:
                xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (
                        ADDON, VERSION, DATE, "skipped video_page_url without html", str(video_page_url)),
                             xbmc.LOGDEBUG)
                titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1
                continue

            description = '...'
            # <a href="http://www.dumpert.nl/mediabase/6721593/46f416fa/stukje_snowboarden.html?thema=bikini" class="dumpthumb" title="Stukje snowboarden">
            #	<img src="http://media.dumpert.nl/sq_thumbs/6721593_46f416fa.jpg" alt="Stukje snowboarden" title="Stukje snowboarden" width="100" height="100" />
            #	<span class="video"></span>
            #	<div class="details">
            #		<h1>Stukje snowboarden</h1>
            #		<date>5 februari 2016 10:32</date>
            #		<p class="stats">views: 63687 kudos: 313</p>
            #		<p class="description">F**k winterkleding </p>
            #	</div>
            # </a>
            try:
                description = titles_and_thumbnail_urls[titles_and_thumbnail_urls_index].parent.find("p",
                                                                                                     "description").string
                description = description.encode('utf-8')
            except:
                pass

            # Make title
            title = ''
            try:
                title = titles_and_thumbnail_urls[titles_and_thumbnail_urls_index]['title']
                # convert from unicode to encoded text (don't use str() to do this)
                title = title.encode('utf-8')
            # <a href="http://www.dumpert.nl/mediabase/1958831/21e6267f/pixar_s_up_inspreken.html?thema=animatie" class="dumpthumb" title="Pixar's &quot;Up&quot; inspreken ">
            except KeyError:
                # http://www.dumpert.nl/mediabase/6532392/82471b66/dumpert_heeft_talent.html
                title = str(video_page_url)
                pos_last_slash = title.rfind('/')
                pos_last_dot = title.rfind('.')
                title = title[pos_last_slash + 1:pos_last_dot]
                title = title.capitalize()
            except UnicodeDecodeError:
                pass

            title = title.replace('-', ' ')
            title = title.replace('/', ' ')
            title = title.replace('_', ' ')

            xbmc.log(
                    "[ADDON] %s v%s (%s) debug mode, %s = %s" % (ADDON, VERSION, DATE, "title", str(title)),
                    xbmc.LOGDEBUG)

            if titles_and_thumbnail_urls_index >= len(titles_and_thumbnail_urls):
                thumbnail_url = ''
            else:
                thumbnail_url = titles_and_thumbnail_urls[titles_and_thumbnail_urls_index]['src']

            list_item = xbmcgui.ListItem(label=title, thumbnailImage=thumbnail_url)
            list_item.setInfo("video", {"title": title, "studio": ADDON, "plot": description})
            list_item.setArt({'thumb': thumbnail_url, 'icon': thumbnail_url,
                              'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'true')
            parameters = {"action": "play", "video_page_url": video_page_url, "title": title}
            url = self.plugin_url + '?' + urllib.urlencode(parameters)
            is_folder = False
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))

            titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1

        # Next page entry
        if self.next_page_possible == 'True':
            next_page = self.current_page + 1
            list_item = xbmcgui.ListItem(LANGUAGE(30503), thumbnailImage=os.path.join(IMAGES_PATH, 'next-page.png'))
            list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            parameters = {"action": "list", "plugin_category": self.plugin_category,
                          "url": str(self.base_url) + str(next_page) + '/',
                          "next_page_possible": self.next_page_possible}
            url = self.plugin_url + '?' + urllib.urlencode(parameters)
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))

        # Add our listing to Kodi.
        # Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
        # instead of adding one by ove via addDirectoryItem.
        xbmcplugin.addDirectoryItems(self.plugin_handle, listing, len(listing))
        # Disable sorting
        xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_NONE)
        # Finish creating a virtual folder.
        xbmcplugin.endOfDirectory(self.plugin_handle)
    def getVideos(self):
        #
        # Init
        #
        thumbnail_urls_index = 0

        #
        # Get HTML page...
        #
        if SETTINGS.getSetting('nsfw') == 'true':
            response = requests.get(self.video_list_page_url,
                                    cookies={'nsfw': '1'})
        else:
            response = requests.get(self.video_list_page_url)

        html_source = response.text
        html_source = convertToUnicodeString(html_source)

        # Parse response
        soup = getSoup(html_source)

        # <img src="http://static.dumpert.nl/s/trailerts_gr.jpg" alt="" />
        thumbnail_urls = soup.findAll(
            'img', attrs={'src': re.compile("^http://static.dumpert.nl/")})

        log("len(thumbnail_urls)", len(thumbnail_urls))

        # <a href="/themas/uit_het_archief/" class="themalink big">
        # <a href="/themas/liev/" class="themalink">
        video_page_urls = soup.findAll(
            'a', attrs={'class': re.compile("^themalink")})

        log("len(video_page_urls)", len(video_page_urls))

        for video_page_url in video_page_urls:
            video_page_url = video_page_url['href']
            # remove '/themas/'
            video_page_url = video_page_url.replace('/themas/', '')
            # http://legacy.dumpert.nl/<thema>/
            theme_base_url = str(self.base_url) + str(video_page_url)
            current_page = 1

            log("theme_base_url", theme_base_url)

            # Make title
            # http://static.dumpert.nl/themas/politiek_kl.jpg
            title = str(video_page_url)
            pos_of_last_slash = title.rfind('/')
            # remove last slash
            title = title[0:pos_of_last_slash]
            pos_of_last_slash = title.rfind('/')
            title = title[pos_of_last_slash + 1:]
            title = title.capitalize()
            title = title.replace('-', ' ')
            title = title.replace('/', ' ')
            title = title.replace('_kl', '')
            title = title.replace('_', ' ')

            log("title", title)

            if thumbnail_urls_index >= len(thumbnail_urls):
                thumbnail_url = ''
            else:
                thumbnail_url = thumbnail_urls[thumbnail_urls_index]['src']

            # let's remove any non-ascii characters from the title, to prevent errors with urllib.parse.parse_qs of the parameters
            title = title.encode('ascii', 'ignore')

            # Add to list...
            parameters = {
                "action": "list",
                "plugin_category": self.plugin_category,
                "url": str(theme_base_url) + str(current_page) + '/',
                "next_page_possible": "True",
                "title": title
            }
            url = sys.argv[0] + '?' + urllib.parse.urlencode(parameters)
            list_item = xbmcgui.ListItem(title, thumbnailImage=thumbnail_url)
            list_item.setInfo("video", {"Title": title, "Studio": "Dumpert"})
            list_item.setArt({
                'thumb':
                thumbnail_url,
                'icon':
                thumbnail_url,
                'fanart':
                os.path.join(IMAGES_PATH, 'fanart-blur.jpg')
            })
            list_item.setProperty('IsPlayable', 'false')
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                        url=url,
                                        listitem=list_item,
                                        isFolder=is_folder)

            thumbnail_urls_index = thumbnail_urls_index + 1

        # Next page entry...
        if self.next_page_possible == 'True':
            next_page = current_page + 1
            parameters = {
                "action": "list",
                "plugin_category": self.plugin_category,
                "url": str(theme_base_url) + str(next_page) + '/',
                "next_page_possible": self.next_page_possible
            }
            url = sys.argv[0] + '?' + urllib.parse.urlencode(parameters)
            list_item = xbmcgui.ListItem(LANGUAGE(30503),
                                         thumbnailImage=os.path.join(
                                             IMAGES_PATH, 'next-page.png'))
            list_item.setArt(
                {'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                        url=url,
                                        listitem=list_item,
                                        isFolder=is_folder)

            log("next url", url)

        # Sort on labels...
        xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                                 sortMethod=xbmcplugin.SORT_METHOD_LABEL)

        # End of directory...
        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True)
예제 #22
0
    def getVideos(self):
        #
        # Init
        #
        titles_and_thumbnail_urls_index = 0
        # Create a list for our items.
        listing = []

        #
        # Get HTML page
        #
        if SETTINGS.getSetting('nsfw') == 'true':
            response = requests.get(self.video_list_page_url,
                                    cookies={'nsfw': '1'})
        else:
            response = requests.get(self.video_list_page_url)

        html_source = response.text
        html_source = convertToUnicodeString(html_source)

        # Parse response
        soup = getSoup(html_source)

        # Find titles and thumnail-urls
        # img src="http://static.dumpert.nl/sq_thumbs/2245331_272bd4c3.jpg" alt="Turnlulz" title="Turnlulz" width="100" height="100" />
        # titles_and_thumbnail_urls = soup.findAll('img', attrs={'src': re.compile("^http://static.dumpert.nl/")} )
        titles_and_thumbnail_urls = soup.findAll(
            'img', attrs={'src': re.compile("thumb")})

        log("titles_and_thumbnail_urls", titles_and_thumbnail_urls)

        # Find video page urls
        # <a href="http://legacy.dumpert.nl/mediabase/2245331/272bd4c3/turnlulz.html" class="dumpthumb" title="Turnlulz">
        video_page_urls = soup.findAll(
            'a', attrs={'class': re.compile("dumpthumb")})

        log("len(video_page_urls)", len(video_page_urls))

        # in thema pages the first thumbnail is a thumbnail of the thema itself and not of a video
        # if that's the case: skip the first thumbnail
        if len(titles_and_thumbnail_urls) == len(video_page_urls) + 1:
            titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1

        for video_page_url in video_page_urls:
            pos_of_video_tag = str(video_page_url).find('class="video"')
            if pos_of_video_tag >= 0:
                pass
            else:
                # skip video page url without a video

                log("skipped video_page_url without video", video_page_url)

                titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1
                continue

            video_page_url = video_page_url['href']

            log("video_page_url", video_page_url)

            # if link doesn't contain 'html': skip the link ('continue')
            if video_page_url.find('html') >= 0:
                pass
            else:
                log("skipped video_page_url without html", video_page_url)
                titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1
                continue

            description = '...'
            #<a href="http://legacy.dumpert.nl/mediabase/6721593/46f416fa/stukje_snowboarden.html?thema=bikini" class="dumpthumb" title="Stukje snowboarden">
            #	<img src="http://media.dumpert.nl/sq_thumbs/6721593_46f416fa.jpg" alt="Stukje snowboarden" title="Stukje snowboarden" width="100" height="100" />
            #	<span class="video"></span>
            #	<div class="details">
            #		<h1>Stukje snowboarden</h1>
            #		<date>5 februari 2016 10:32</date>
            #		<p class="stats">views: 63687 kudos: 313</p>
            #		<p class="description">F**k winterkleding </p>
            #	</div>
            #</a>
            try:
                description = titles_and_thumbnail_urls[
                    titles_and_thumbnail_urls_index].parent.find(
                        "p", "description").string
            except:
                pass

            # Make title
            try:
                title = titles_and_thumbnail_urls[
                    titles_and_thumbnail_urls_index]['title']
            # <a href="http://legacy.dumpert.nl/mediabase/1958831/21e6267f/pixar_s_up_inspreken.html?thema=animatie" class="dumpthumb" title="Pixar's &quot;Up&quot; inspreken ">
            except KeyError:
                # http://legacy.dumpert.nl/mediabase/6532392/82471b66/dumpert_heeft_talent.html
                title = str(video_page_url)
                pos_last_slash = title.rfind('/')
                pos_last_dot = title.rfind('.')
                title = title[pos_last_slash + 1:pos_last_dot]
                title = title.capitalize()
            except UnicodeDecodeError:
                pass

            title = title.replace('-', ' ')
            title = title.replace('/', ' ')
            title = title.replace('_', ' ')

            log("title", title)

            if titles_and_thumbnail_urls_index >= len(
                    titles_and_thumbnail_urls):
                thumbnail_url = ''
            else:
                thumbnail_url = titles_and_thumbnail_urls[
                    titles_and_thumbnail_urls_index]['src'].replace(
                        "sq_thumbs", "stills/large")

            list_item = xbmcgui.ListItem(label=title,
                                         thumbnailImage=thumbnail_url)
            list_item.setInfo(
                "video", {
                    "title": title,
                    "studio": "Dumpert",
                    "mediatype": "video",
                    "plot": description
                })
            list_item.setArt({
                'thumb':
                thumbnail_url,
                'icon':
                thumbnail_url,
                'fanart':
                os.path.join(IMAGES_PATH, 'fanart-blur.jpg')
            })
            list_item.setProperty('IsPlayable', 'true')

            # let's remove any non-ascii characters from the title, to prevent errors with urllib.parse.parse_qs of the parameters
            title = title.encode('ascii', 'ignore')

            parameters = {
                "action": "play",
                "video_page_url": video_page_url,
                "title": title
            }
            url = self.plugin_url + '?' + urllib.parse.urlencode(parameters)

            is_folder = False
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))

            titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1

        # Next page entry
        if self.next_page_possible == 'True':
            next_page = self.current_page + 1
            list_item = xbmcgui.ListItem(LANGUAGE(30503),
                                         thumbnailImage=os.path.join(
                                             IMAGES_PATH, 'next-page.png'))
            list_item.setArt(
                {'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            parameters = {
                "action": "list",
                "plugin_category": self.plugin_category,
                "url": str(self.base_url) + str(next_page) + '/',
                "next_page_possible": self.next_page_possible
            }
            url = self.plugin_url + '?' + urllib.parse.urlencode(parameters)
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))

        # Add our listing to Kodi.
        # Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
        # instead of adding one by ove via addDirectoryItem.
        xbmcplugin.addDirectoryItems(self.plugin_handle, listing, len(listing))
        # Disable sorting
        xbmcplugin.addSortMethod(handle=self.plugin_handle,
                                 sortMethod=xbmcplugin.SORT_METHOD_NONE)
        # Finish creating a virtual folder.
        xbmcplugin.endOfDirectory(self.plugin_handle)
    def playVideo(self):
        #
        # Init
        #
        no_url_found = False
        unplayable_media_file = False
        have_valid_url = False

        #
        # Get current list item details...
        #
        # title = convertToUnicodeString(xbmc.getInfoLabel("list_item.Title"))
        thumbnail_url = convertToUnicodeString(xbmc.getInfoImage("list_item.Thumb"))
        # studio = convertToUnicodeString(xbmc.getInfoLabel("list_item.Studio"))
        # plot = convertToUnicodeString(xbmc.getInfoLabel("list_item.Plot"))
        # genre = convertToUnicodeString(xbmc.getInfoLabel("list_item.Genre"))

        #
        # Show wait dialog while parsing data...
        #
        dialog_wait = xbmcgui.DialogProgress()
        dialog_wait.create(LANGUAGE(30504), self.title)
        # wait 1 second
        xbmc.sleep(1000)

        try:
            if SETTINGS.getSetting('nsfw') == 'true':
                response = requests.get(self.video_page_url, cookies={'nsfw': '1'})
            else:
                response = requests.get(self.video_page_url)

            html_source = response.text
            html_source = convertToUnicodeString(html_source)
        except urllib.error.HTTPError as error:

            log('HTTPError', error)

            dialog_wait.close()
            del dialog_wait
            xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30507) % (str(error)))
            exit(1)

        # Parse response
        soup = getSoup(html_source)

        video_url = ''
        # <div class="videoplayer" id="video1" data-files="eyJmbHYiOiJodHRwOlwvXC9tZWRpYS5kdW1wZXJ0Lm5sXC9mbHZcLzI4OTE2NWRhXzEwMjU1NzUyXzYzODMxODA4OTU1NDc2MV84MTk0MzU3MDVfbi5tcDQuZmx2IiwidGFibGV0IjoiaHR0cDpcL1wvbWVkaWEuZHVtcGVydC5ubFwvdGFibGV0XC8yODkxNjVkYV8xMDI1NTc1Ml82MzgzMTgwODk1NTQ3NjFfODE5NDM1NzA1X24ubXA0Lm1wNCIsIm1vYmlsZSI6Imh0dHA6XC9cL21lZGlhLmR1bXBlcnQubmxcL21vYmlsZVwvMjg5MTY1ZGFfMTAyNTU3NTJfNjM4MzE4MDg5NTU0NzYxXzgxOTQzNTcwNV9uLm1wNC5tcDQiLCJzdGlsbCI6Imh0dHA6XC9cL3N0YXRpYy5kdW1wZXJ0Lm5sXC9zdGlsbHNcLzY1OTM1MjRfMjg5MTY1ZGEuanBnIn0="></div></div>
        video_urls = soup.findAll('div', attrs={'class': re.compile("video")}, limit=1)
        if len(video_urls) == 0:
            # maybe it's a youtube url
            # <iframe class='yt-iframe' style='width: 100%' src='https://www.youtube.com/embed/9L0iOZmdS6s?showInfo=0&rel=0' frameborder='0' allow='autoplay; encrypted-media' allowfullscreen></iframe>
            video_urls = soup.findAll('iframe', attrs={'src': re.compile("^http")}, limit=1)
            if len(video_urls) == 0:
                no_url_found = True
            else:
                url = video_urls[0]['src']
                start_pos_youtube_id = str(url).rfind("/") + len("/")
                end_pos_youtube_id = str(url).find("?", start_pos_youtube_id)
                youtube_id = url[start_pos_youtube_id:end_pos_youtube_id]
                youtube_url = 'plugin://plugin.video.youtube/play/?video_id=%s' % youtube_id
                video_url = youtube_url
                have_valid_url = True

                log("video_url1", video_url)
        else:
            video_url_enc = video_urls[0]['data-files']
            # base64 decode
            video_url_dec = convertToUnicodeString(base64.b64decode(video_url_enc))
            # {"flv":"http:\/\/media.dumpert.nl\/flv\/5770e490_Jumbo_KOOP_DAN__Remix.avi.flv","tablet":"http:\/\/media.dumpert.nl\/tablet\/5770e490_Jumbo_KOOP_DAN__Remix.avi.mp4","mobile":"http:\/\/media.dumpert.nl\/mobile\/5770e490_Jumbo_KOOP_DAN__Remix.avi.mp4","720p":"http:\/\/media.dumpert.nl\/720p\/5770e490_Jumbo_KOOP_DAN__Remix.avi.mp4","still":"http:\/\/static.dumpert.nl\/stills\/6593503_5770e490.jpg"}
            # or
            # {"embed":"youtube:U89fl5fZETE","still":"http:\/\/static.dumpert.nl\/stills\/6650228_24eed546.jpg"}

            log("video_url_dec", video_url_dec)

            # convert string to dictionary
            video_url_dec_dict = ast.literal_eval(video_url_dec)

            try:
                video_url_stream = convertToUnicodeString(video_url_dec_dict['stream'])
                stream_found = True
            except KeyError:
                stream_found = False

            if stream_found:
                video_url = video_url_stream
                video_url = video_url.replace('\/', '/')
                have_valid_url = True

                log("video_url2", video_url)
            else:

                try:
                    video_url_embed = convertToUnicodeString(video_url_dec_dict['embed'])
                    embed_found = True
                except KeyError:
                    embed_found = False

                if embed_found:
                    # make youtube plugin url
                    youtube_id = video_url_embed.replace("youtube:", "")
                    youtube_url = 'plugin://plugin.video.youtube/play/?video_id=%s' % youtube_id
                    video_url = youtube_url
                    have_valid_url = True

                    log("video_url3", video_url)

                else:
                    # matching the desired and available quality
                    if self.VIDEO == '0':
                        try:
                            video_url = str(video_url_dec_dict['mobile'])
                        except KeyError:
                            no_url_found = True
                    elif self.VIDEO == '1':
                        try:
                            video_url = str(video_url_dec_dict['tablet'])
                        except KeyError:
                            try:
                                video_url = str(video_url_dec_dict['mobile'])
                            except KeyError:
                                no_url_found = True
                    elif self.VIDEO == '2':
                        try:
                            video_url = str(video_url_dec_dict['720p'])
                        except KeyError:
                            try:
                                video_url = str(video_url_dec_dict['tablet'])
                            except KeyError:
                                try:
                                    video_url = str(video_url_dec_dict['mobile'])
                                except KeyError:
                                    no_url_found = True

                    if no_url_found:
                        pass
                    else:
                        video_url = video_url.replace('\/', '/')

                        log("video_url4", video_url)

                        # The need for speed: let's guess that the video-url exists
                        have_valid_url = True

        # Play video...
        if have_valid_url:
            list_item = xbmcgui.ListItem(path=video_url)
            xbmcplugin.setResolvedUrl(self.plugin_handle, True, list_item)
        #
        # Alert user
        #
        elif no_url_found:
            xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30505))
        elif unplayable_media_file:
            xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30506))
    def getVideos(self):
        #
        # Init
        #
        titles_and_thumbnail_urls_index = 0
        # Create a list for our items.
        listing = []

        #
        # Get HTML page
        #
        if SETTINGS.getSetting('nsfw') == 'true':
            response = requests.get(self.video_list_page_url, cookies={'nsfw': '1'})
        else:
            response = requests.get(self.video_list_page_url)

        html_source = response.text
        html_source = convertToUnicodeString(html_source)

        # Parse response
        soup = getSoup(html_source)

        # Find titles and thumnail-urls
        # img src="http://static.dumpert.nl/sq_thumbs/2245331_272bd4c3.jpg" alt="Turnlulz" title="Turnlulz" width="100" height="100" />
        # titles_and_thumbnail_urls = soup.findAll('img', attrs={'src': re.compile("^http://static.dumpert.nl/")} )
        titles_and_thumbnail_urls = soup.findAll('img', attrs={'src': re.compile("thumb")})

        log("titles_and_thumbnail_urls", titles_and_thumbnail_urls)

        # Find video page urls
        # <a href="http://www.dumpert.nl/mediabase/2245331/272bd4c3/turnlulz.html" class="dumpthumb" title="Turnlulz">
        video_page_urls = soup.findAll('a', attrs={'class': re.compile("dumpthumb")})

        log("len(video_page_urls)", len(video_page_urls))

        # in thema pages the first thumbnail is a thumbnail of the thema itself and not of a video
        # if that's the case: skip the first thumbnail
        if len(titles_and_thumbnail_urls) == len(video_page_urls) + 1:
            titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1

        for video_page_url in video_page_urls:
            pos_of_video_tag = str(video_page_url).find('class="video"')
            if pos_of_video_tag >= 0:
                pass
            else:
                # skip video page url without a video

                log("skipped video_page_url without video", video_page_url)

                titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1
                continue

            video_page_url = video_page_url['href']

            log("video_page_url", video_page_url)

            # if link doesn't contain 'html': skip the link ('continue')
            if video_page_url.find('html') >= 0:
                pass
            else:
                log("skipped video_page_url without html", video_page_url)
                titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1
                continue

            description = '...'
            #<a href="http://www.dumpert.nl/mediabase/6721593/46f416fa/stukje_snowboarden.html?thema=bikini" class="dumpthumb" title="Stukje snowboarden">
            #	<img src="http://media.dumpert.nl/sq_thumbs/6721593_46f416fa.jpg" alt="Stukje snowboarden" title="Stukje snowboarden" width="100" height="100" />
            #	<span class="video"></span>
            #	<div class="details">
            #		<h1>Stukje snowboarden</h1>
            #		<date>5 februari 2016 10:32</date>
            #		<p class="stats">views: 63687 kudos: 313</p>
            #		<p class="description">F**k winterkleding </p>
            #	</div>
            #</a>
            try:
                description = titles_and_thumbnail_urls[titles_and_thumbnail_urls_index].parent.find("p","description").string
            except:
                pass

            # Make title
            try:
                title = titles_and_thumbnail_urls[titles_and_thumbnail_urls_index]['title']
            # <a href="http://www.dumpert.nl/mediabase/1958831/21e6267f/pixar_s_up_inspreken.html?thema=animatie" class="dumpthumb" title="Pixar's &quot;Up&quot; inspreken ">
            except KeyError:
                # http://www.dumpert.nl/mediabase/6532392/82471b66/dumpert_heeft_talent.html
                title = str(video_page_url)
                pos_last_slash = title.rfind('/')
                pos_last_dot = title.rfind('.')
                title = title[pos_last_slash + 1:pos_last_dot]
                title = title.capitalize()
            except UnicodeDecodeError:
                pass

            title = title.replace('-', ' ')
            title = title.replace('/', ' ')
            title = title.replace('_', ' ')

            log("title", title)

            if titles_and_thumbnail_urls_index >= len(titles_and_thumbnail_urls):
                thumbnail_url = ''
            else:
                thumbnail_url = titles_and_thumbnail_urls[titles_and_thumbnail_urls_index]['src'].replace("sq_thumbs","stills/large")

            list_item = xbmcgui.ListItem(label=title, thumbnailImage=thumbnail_url)
            list_item.setInfo("video", {"title": title, "studio": "Dumpert", "mediatype": "video", "plot": description})
            list_item.setArt({'thumb': thumbnail_url, 'icon': thumbnail_url,
                              'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'true')

            # let's remove any non-ascii characters from the title, to prevent errors with urllib.parse.parse_qs of the parameters
            title = title.encode('ascii', 'ignore')

            parameters = {"action": "play", "video_page_url": video_page_url, "title": title}
            url = self.plugin_url + '?' + urllib.parse.urlencode(parameters)

            is_folder = False
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))

            titles_and_thumbnail_urls_index = titles_and_thumbnail_urls_index + 1

        # Next page entry
        if self.next_page_possible == 'True':
            next_page = self.current_page + 1
            list_item = xbmcgui.ListItem(LANGUAGE(30503), thumbnailImage=os.path.join(IMAGES_PATH, 'next-page.png'))
            list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            parameters = {"action": "list", "plugin_category": self.plugin_category,
                          "url": str(self.base_url) + str(next_page) + '/',
                          "next_page_possible": self.next_page_possible}
            url = self.plugin_url + '?' + urllib.parse.urlencode(parameters)
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            # Add our item to the listing as a 3-element tuple.
            listing.append((url, list_item, is_folder))

        # Add our listing to Kodi.
        # Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
        # instead of adding one by ove via addDirectoryItem.
        xbmcplugin.addDirectoryItems(self.plugin_handle, listing, len(listing))
        # Disable sorting
        xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_NONE)
        # Finish creating a virtual folder.
        xbmcplugin.endOfDirectory(self.plugin_handle)
    def playVideo(self):
        #
        # Init
        #
        no_url_found = False
        unplayable_media_file = False
        have_valid_url = False

        #
        # Get current list item details...
        #
        # title = convertToUnicodeString(xbmc.getInfoLabel("list_item.Title"))
        thumbnail_url = convertToUnicodeString(xbmc.getInfoImage("list_item.Thumb"))
        # studio = convertToUnicodeString(xbmc.getInfoLabel("list_item.Studio"))
        # plot = convertToUnicodeString(xbmc.getInfoLabel("list_item.Plot"))
        # genre = convertToUnicodeString(xbmc.getInfoLabel("list_item.Genre"))

        #
        # Show wait dialog while parsing data...
        #
        dialog_wait = xbmcgui.DialogProgress()
        dialog_wait.create(LANGUAGE(30504), self.title)
        # wait 1 second
        xbmc.sleep(1000)

        try:
            if SETTINGS.getSetting('nsfw') == 'true':
                response = requests.get(self.video_page_url, cookies={'nsfw': '1'})
            else:
                response = requests.get(self.video_page_url)

            html_source = response.text
            html_source = convertToUnicodeString(html_source)
        except urllib.error.HTTPError as error:

            log('HTTPError', error)

            dialog_wait.close()
            del dialog_wait
            xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30507) % (str(error)))
            exit(1)

        # Parse response
        soup = getSoup(html_source)

        video_url = ''
        # <div class="videoplayer" id="video1" data-files="eyJmbHYiOiJodHRwOlwvXC9tZWRpYS5kdW1wZXJ0Lm5sXC9mbHZcLzI4OTE2NWRhXzEwMjU1NzUyXzYzODMxODA4OTU1NDc2MV84MTk0MzU3MDVfbi5tcDQuZmx2IiwidGFibGV0IjoiaHR0cDpcL1wvbWVkaWEuZHVtcGVydC5ubFwvdGFibGV0XC8yODkxNjVkYV8xMDI1NTc1Ml82MzgzMTgwODk1NTQ3NjFfODE5NDM1NzA1X24ubXA0Lm1wNCIsIm1vYmlsZSI6Imh0dHA6XC9cL21lZGlhLmR1bXBlcnQubmxcL21vYmlsZVwvMjg5MTY1ZGFfMTAyNTU3NTJfNjM4MzE4MDg5NTU0NzYxXzgxOTQzNTcwNV9uLm1wNC5tcDQiLCJzdGlsbCI6Imh0dHA6XC9cL3N0YXRpYy5kdW1wZXJ0Lm5sXC9zdGlsbHNcLzY1OTM1MjRfMjg5MTY1ZGEuanBnIn0="></div></div>
        video_urls = soup.findAll('div', attrs={'class': re.compile("video")}, limit=1)
        if len(video_urls) == 0:
            # maybe it's a youtube url
            # <iframe class='yt-iframe' style='width: 100%' src='https://www.youtube.com/embed/9L0iOZmdS6s?showInfo=0&rel=0' frameborder='0' allow='autoplay; encrypted-media' allowfullscreen></iframe>
            video_urls = soup.findAll('iframe', attrs={'src': re.compile("^http")}, limit=1)
            if len(video_urls) == 0:
                no_url_found = True
            else:
                url = video_urls[0]['src']
                start_pos_youtube_id = str(url).rfind("/") + len("/")
                end_pos_youtube_id = str(url).find("?", start_pos_youtube_id)
                youtube_id = url[start_pos_youtube_id:end_pos_youtube_id]
                youtube_url = 'plugin://plugin.video.youtube/play/?video_id=%s' % youtube_id
                video_url = youtube_url
                have_valid_url = True

                log("video_url1", video_url)
        else:
            video_url_enc = video_urls[0]['data-files']
            # base64 decode
            video_url_dec = convertToUnicodeString(base64.b64decode(video_url_enc))
            # {"flv":"http:\/\/media.dumpert.nl\/flv\/5770e490_Jumbo_KOOP_DAN__Remix.avi.flv","tablet":"http:\/\/media.dumpert.nl\/tablet\/5770e490_Jumbo_KOOP_DAN__Remix.avi.mp4","mobile":"http:\/\/media.dumpert.nl\/mobile\/5770e490_Jumbo_KOOP_DAN__Remix.avi.mp4","720p":"http:\/\/media.dumpert.nl\/720p\/5770e490_Jumbo_KOOP_DAN__Remix.avi.mp4","still":"http:\/\/static.dumpert.nl\/stills\/6593503_5770e490.jpg"}
            # or
            # {"embed":"youtube:U89fl5fZETE","still":"http:\/\/static.dumpert.nl\/stills\/6650228_24eed546.jpg"}

            log("video_url_dec", video_url_dec)

            # convert string to dictionary
            video_url_dec_dict = ast.literal_eval(video_url_dec)

            try:
                video_url_stream = convertToUnicodeString(video_url_dec_dict['stream'])
                stream_found = True
            except KeyError:
                stream_found = False

            if stream_found:
                video_url = video_url_stream
                video_url = video_url.replace('\/', '/')
                have_valid_url = True

                log("video_url2", video_url)
            else:

                try:
                    video_url_embed = convertToUnicodeString(video_url_dec_dict['embed'])
                    embed_found = True
                except KeyError:
                    embed_found = False

                if embed_found:
                    # make youtube plugin url
                    youtube_id = video_url_embed.replace("youtube:", "")
                    youtube_url = 'plugin://plugin.video.youtube/play/?video_id=%s' % youtube_id
                    video_url = youtube_url
                    have_valid_url = True

                    log("video_url3", video_url)

                else:
                    # matching the desired and available quality
                    if self.VIDEO == '0':
                        try:
                            video_url = str(video_url_dec_dict['mobile'])
                        except KeyError:
                            no_url_found = True
                    elif self.VIDEO == '1':
                        try:
                            video_url = str(video_url_dec_dict['tablet'])
                        except KeyError:
                            try:
                                video_url = str(video_url_dec_dict['mobile'])
                            except KeyError:
                                no_url_found = True
                    elif self.VIDEO == '2':
                        try:
                            video_url = str(video_url_dec_dict['720p'])
                        except KeyError:
                            try:
                                video_url = str(video_url_dec_dict['tablet'])
                            except KeyError:
                                try:
                                    video_url = str(video_url_dec_dict['mobile'])
                                except KeyError:
                                    no_url_found = True

                    if no_url_found:
                        pass
                    else:
                        video_url = video_url.replace('\/', '/')

                        log("video_url4", video_url)

                        # The need for speed: let's guess that the video-url exists
                        have_valid_url = True

        # Play video...
        if have_valid_url:
            list_item = xbmcgui.ListItem(path=video_url)
            xbmcplugin.setResolvedUrl(self.plugin_handle, True, list_item)
        #
        # Alert user
        #
        elif no_url_found:
            xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30505))
        elif unplayable_media_file:
            xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30506))
    def getVideos(self):
        #
        # Init
        #
        thumbnail_urls_index = 0

        #
        # Get HTML page...
        #
        if SETTINGS.getSetting('nsfw') == 'true':
            response = requests.get(self.video_list_page_url, cookies={'nsfw': '1'})
        else:
            response = requests.get(self.video_list_page_url)

        html_source = response.text
        html_source = convertToUnicodeString(html_source)

        # Parse response
        soup = getSoup(html_source)

        # <img src="http://static.dumpert.nl/s/trailerts_gr.jpg" alt="" />
        thumbnail_urls = soup.findAll('img', attrs={'src': re.compile("^http://static.dumpert.nl/")})

        log("len(thumbnail_urls)", len(thumbnail_urls))

        # <a href="/themas/uit_het_archief/" class="themalink big">
        # <a href="/themas/liev/" class="themalink">
        video_page_urls = soup.findAll('a', attrs={'class': re.compile("^themalink")})

        log("len(video_page_urls)", len(video_page_urls))

        for video_page_url in video_page_urls:
            video_page_url = video_page_url['href']
            # remove '/themas/'
            video_page_url = video_page_url.replace('/themas/', '')
            # http://www.dumpert.nl/<thema>/
            theme_base_url = str(self.base_url) + str(video_page_url)
            current_page = 1

            log("theme_base_url", theme_base_url)

            # Make title
            # http://static.dumpert.nl/themas/politiek_kl.jpg
            title = str(video_page_url)
            pos_of_last_slash = title.rfind('/')
            # remove last slash
            title = title[0: pos_of_last_slash]
            pos_of_last_slash = title.rfind('/')
            title = title[pos_of_last_slash + 1:]
            title = title.capitalize()
            title = title.replace('-', ' ')
            title = title.replace('/', ' ')
            title = title.replace('_kl', '')
            title = title.replace('_', ' ')

            log("title", title)

            if thumbnail_urls_index >= len(thumbnail_urls):
                thumbnail_url = ''
            else:
                thumbnail_url = thumbnail_urls[thumbnail_urls_index]['src']

            # let's remove any non-ascii characters from the title, to prevent errors with urllib.parse.parse_qs of the parameters
            title = title.encode('ascii', 'ignore')

            # Add to list...
            parameters = {"action": "list", "plugin_category": self.plugin_category,
                          "url": str(theme_base_url) + str(current_page) + '/', "next_page_possible": "True",
                          "title": title}
            url = sys.argv[0] + '?' + urllib.parse.urlencode(parameters)
            list_item = xbmcgui.ListItem(title, thumbnailImage=thumbnail_url)
            list_item.setInfo("video", {"Title": title, "Studio": "Dumpert"})
            list_item.setArt({'thumb': thumbnail_url, 'icon': thumbnail_url,
                              'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=list_item, isFolder=is_folder)

            thumbnail_urls_index = thumbnail_urls_index + 1

        # Next page entry...
        if self.next_page_possible == 'True':
            next_page = current_page + 1
            parameters = {"action": "list", "plugin_category": self.plugin_category,
                          "url": str(theme_base_url) + str(next_page) + '/',
                          "next_page_possible": self.next_page_possible}
            url = sys.argv[0] + '?' + urllib.parse.urlencode(parameters)
            list_item = xbmcgui.ListItem(LANGUAGE(30503), thumbnailImage=os.path.join(IMAGES_PATH, 'next-page.png'))
            list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')})
            list_item.setProperty('IsPlayable', 'false')
            is_folder = True
            # Add refresh option to context menu
            list_item.addContextMenuItems([('Refresh', 'Container.Refresh')])
            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=list_item, isFolder=is_folder)

            log("next url", url)

        # Sort on labels...
        xbmcplugin.addSortMethod(handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_LABEL)

        # End of directory...
        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True)