Ejemplo n.º 1
0
def Scrape_Sites(list_type):
    """
This is just a very rough example showing how simple it is to make use of the NaN Scrapers module.
We send through details of what we want to find and NaN Scrapers will search multiple websites for this content.
    """
    content = ''
    if list_type == 'movie_dialog':
        content = nanscrapers.scrape_movie_with_dialog(title='Trainspotting', year='1996', imdb='tt0117951', host=None, include_disabled=False, timeout=30)
    elif list_type == 'episode_dialog':
        content = nanscrapers.scrape_episode_with_dialog(title='Fraggle Rock', show_year='1983', year='1985', season='3', episode='4', imdb='tt0085017', tvdb=None, host=None, include_disabled=False, timeout=30)
    elif list_type == 'song_dialog':
        content = nanscrapers.scrape_song_with_dialog(title='Fools Gold', artist='Stone Roses', host=None, include_disabled=False, timeout=30)

# If the item returned is a dictionary that's great we know we have a list to work with
    if koding.Data_Type(content) == 'dict':
        xbmc.log(repr(content),2)
        playback = koding.Play_Video(video=content["url"], showbusy=True)
 
# It may be a plugin or direct url has been sent through, if so lets use the list_type variable
    elif not list_type.endswith('_dialog'):
        playback = koding.Play_Video(video=list_type, showbusy=True)

# Nothing useful has been found, lets exit back to the list
    else:
        return

# If the playback returned as True then it was successful but if it was False we know we need to try again for another source
    if not playback:
        if dialog.yesno('PLAYBACK FAILED','The video may have been removed, the web host may have altered their code or this video may not be available in your region. [COLOR=dodgerblue]Would you like to try another source?[/COLOR]'):
            Scrape_Sites(list_type)
Ejemplo n.º 2
0
    def get_music_sources(title,
                          artist,
                          timeout=30,
                          preset="search",
                          dialog=None,
                          exclude=None,
                          listitem=None,
                          output_function=koding.Play_Video,
                          skip_selector=False,
                          player=None):
        """
        scrapes for music sources using NaN scraper library
        Args:
            title: song title
            artist: song artist
            timeout: timeout for scraping link
            preset: preferred quality of stream
            dialog: dialog to use for displaying messages
            exclude: list of scrapers to exclude
        Returns:
            Boolean indicating playback success
        """
        title = title
        allow_debrid = ADDON.getSetting('allow_debrid') == "true"
        if ADDON.getSetting('use_link_dialog') == 'true' and not skip_selector:
            link, rest = nanscrapers.scrape_song_with_dialog(
                title,
                artist,
                timeout=timeout,
                exclude=exclude,
                enable_debrid=allow_debrid,
                extended=True)
            if type(link) == dict and "path" in link:
                link = link["path"]
                if link is None:
                    return False
                url = link['url']
                if ADDON.getSetting('link_fallthrough') == 'true':
                    played = False
                    index = 0
                    links = []
                    for item in rest:
                        if type(item) == dict and "path" in item:
                            links.extend(item["path"][1])
                        else:
                            links.extend(item[1])
                    index = links.index(link)
                    links = links[index + 1:]
                    num_results = len(rest) + 1
                    while not played:
                        try:
                            if dialog is not None and dialog.iscanceled():
                                return
                            if dialog is not None:
                                index = index + 1
                                percent = int((index * 100) / num_results)
                                line = "%s - %s (%s)" % (link['scraper'],
                                                         link['source'],
                                                         link['quality'])
                                dialog.update(percent, line)
                        except:
                            pass
                        try:
                            played = output_function(
                                url,
                                showbusy=False,
                                ignore_dp=True,
                                item=listitem,
                                player=player)
                            link = links[0]
                            links = links[1:]
                        except:
                            return False
                    return played
                else:
                    return output_function(
                        url,
                        showbusy=False,
                        ignore_dp=True,
                        item=listitem,
                        player=player)
        links_scraper = nanscrapers.scrape_song(
            title,
            artist,
            timeout=timeout,
            exclude=exclude,
            enable_debrid=allow_debrid)

        sd_links = []
        num_scrapers = len(nanscrapers.relevant_scrapers())
        index = 0
        try:
            for scraper_links in links_scraper():
                if dialog is not None and dialog.iscanceled():
                    return
                if dialog is not None:
                    index = index + 1
                    percent = int((index * 100) / num_scrapers)
                    dialog.update(percent)
                if scraper_links is not None:
                    random.shuffle(scraper_links)
                    for scraper_link in scraper_links:
                        if dialog is not None and dialog.iscanceled():
                            return

                        if Sources().__check_skip_pairing(scraper_link):
                            continue

                        quality = Sources.__determine_quality(
                            scraper_link["quality"])
                        preset = preset.lower()
                        if preset == 'searchsd':
                            if quality == "HD":
                                continue
                        elif preset == "search":
                            if quality == "SD":
                                sd_links.append(scraper_link)

                        result = output_function(
                            scraper_link["url"],
                            showbusy=False,
                            ignore_dp=True,
                            item=listitem,
                            player=player)
                        if result:
                            return result

            for scraper_link in sd_links:
                if dialog is not None and dialog.iscanceled():
                    return
                result = output_function(
                    scraper_link["url"],
                    showbusy=False,
                    ignore_dp=True,
                    item=listitem,
                    player=player)
                if result:
                    return result
        except:
            pass
        return False
Ejemplo n.º 3
0
    def get_music_sources(title,
                          artist,
                          timeout=30,
                          preset="search",
                          dialog=None,
                          exclude=None,
                          listitem=None,
                          output_function=koding.Play_Video,
                          skip_selector=False,
                          player=None):
        """
        scrapes for music sources using NaN scraper library
        Args:
            title: song title
            artist: song artist
            timeout: timeout for scraping link
            preset: preferred quality of stream
            dialog: dialog to use for displaying messages
            exclude: list of scrapers to exclude
        Returns:
            Boolean indicating playback success
        """
        title = title
        allow_debrid = ADDON.getSetting('allow_debrid') == "true"
        if ADDON.getSetting(
                'use_link_dialog') == 'Link Selector' and not skip_selector:
            link, rest = nanscrapers.scrape_song_with_dialog(
                title,
                artist,
                timeout=timeout,
                exclude=exclude,
                enable_debrid=allow_debrid,
                extended=True)
            if type(link) == dict and "path" in link:
                link = link["path"]
            if link is None:
                return False
            url = link['url']
            if ADDON.getSetting('link_fallthrough') == 'true':
                played = False
                index = 0
                links = []
                for item in rest:
                    if type(item) == dict and "path" in item:
                        links.extend(item["path"][1])
                    else:
                        links.extend(item[1])
                index = links.index(link)
                links = links[index + 1:]
                num_results = len(rest) + 1
                while not played:
                    try:
                        if dialog is not None and dialog.iscanceled():
                            return
                        if dialog is not None:
                            index = index + 1
                            percent = int((index * 100) / num_results)
                            line = "%s - %s (%s)" % (link['scraper'],
                                                     link['source'],
                                                     link['quality'])
                            dialog.update(percent, line)
                    except:
                        pass
                    try:
                        played = output_function(url,
                                                 showbusy=False,
                                                 ignore_dp=True,
                                                 item=listitem,
                                                 player=player)
                        link = links[0]
                        links = links[1:]
                    except:
                        return False
                return played
            else:
                return output_function(url,
                                       showbusy=False,
                                       ignore_dp=True,
                                       item=listitem,
                                       player=player)
        links_scraper = nanscrapers.scrape_song(title,
                                                artist,
                                                timeout=timeout,
                                                exclude=exclude,
                                                enable_debrid=allow_debrid)

        sd_links = []
        num_scrapers = len(nanscrapers.relevant_scrapers())
        index = 0
        try:
            for scraper_links in links_scraper():
                if dialog is not None and dialog.iscanceled():
                    return
                if dialog is not None:
                    index = index + 1
                    percent = int((index * 100) / num_scrapers)
                    dialog.update(percent)
                if scraper_links is not None:
                    random.shuffle(scraper_links)
                    for scraper_link in scraper_links:
                        if dialog is not None and dialog.iscanceled():
                            return

                        if Sources().__check_skip_pairing(scraper_link):
                            continue

                        quality = Sources.__determine_quality(
                            scraper_link["quality"])
                        preset = preset.lower()
                        if preset == 'searchsd':
                            if quality == "HD":
                                continue
                        elif preset == "search":
                            if quality == "SD":
                                sd_links.append(scraper_link)

                        result = output_function(scraper_link["url"],
                                                 showbusy=False,
                                                 ignore_dp=True,
                                                 item=listitem,
                                                 player=player)
                        if result:
                            return result

            for scraper_link in sd_links:
                if dialog is not None and dialog.iscanceled():
                    return
                result = output_function(scraper_link["url"],
                                         showbusy=False,
                                         ignore_dp=True,
                                         item=listitem,
                                         player=player)
                if result:
                    return result
        except:
            pass
        return False
Ejemplo n.º 4
0
                url = link['url']
                try:
                    resolved_url = urlresolver.resolve(url)
                except:
                    xbmcgui.Dialog().notification("Scraper test",
                                                  "unplayable stream")
                    sys.exit()
                if resolved_url:
                    url = resolved_url
                xbmc.Player().play(url, xbmcgui.ListItem(name))

if type == 2:
    artist = xbmcgui.Dialog().input("Artist")
    title = xbmcgui.Dialog().input("Title")
    if title is not "" and artist is not "":
        link = nanscrapers.scrape_song_with_dialog(title, artist)
        if link is False:
            xbmcgui.Dialog().ok("Song not found",
                                "No Links Found for " + artist + " - " + title)
        else:
            if link:
                url = link['url']
                try:
                    resolved_url = urlresolver.resolve(url)
                except:
                    xbmcgui.Dialog().notification("Scraper test",
                                                  "unplayable stream")
                    sys.exit()
                if resolved_url:
                    url = resolved_url
                xbmc.Player().play(url,