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 = universalscrapers.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,
                            resolver=resolveurl,
                        )
                        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,
                    resolver=resolveurl,
                )
        links_scraper = universalscrapers.scrape_song(
            title, artist, timeout=timeout, exclude=exclude, enable_debrid=allow_debrid
        )

        sd_links = []
        num_scrapers = len(universalscrapers.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,
                            resolver=resolveurl,
                        )
                        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,
                    resolver=resolveurl,
                )
                if result:
                    return result
        except:
            pass
        return False
Exemple #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 = universalscrapers.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,
                            resolver=resolveurl)
                        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,
                    resolver=resolveurl)
        links_scraper = universalscrapers.scrape_song(
            title,
            artist,
            timeout=timeout,
            exclude=exclude,
            enable_debrid=allow_debrid)

        sd_links = []
        num_scrapers = len(universalscrapers.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,
                            resolver=resolveurl)
                        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,
                    resolver=resolveurl)
                if result:
                    return result
        except:
            pass
        return False