def main(args=sys.argv[1:]):
    usage_string = """
    Usage:
        second_hand_songs_api_cmdline.py --getShsArtistById <id> [-a|--allFields] [<dereferece_attr>...] 
        second_hand_songs_api_cmdline.py --getShsPerformanceById <id> [<dereferece_attr>...] 
        second_hand_songs_api_cmdline.py --getShsWorkById <id> [<dereferece_attr>...] 
        second_hand_songs_api_cmdline.py --getShsReleaseById <id> [<dereferece_attr>...] 
        second_hand_songs_api_cmdline.py --getShsLabelById <id> [<dereferece_attr>...] 
        second_hand_songs_api_cmdline.py --searchWork <title> [ --credits <credits_> ] [ --page <page> ] [ --pageSize <pageSize>] [<dereferece_attr>...] 
        second_hand_songs_api_cmdline.py --searchPerformance <title> [ --performer <performer> ] [ --date <date> ] [<dereferece_attr>...] 
        second_hand_songs_api_cmdline.py -h | --help
        second_hand_songs_api_cmdline.py --version
    
    Options:
        -a, --allFields            Fetch extra data for uri fields, currently applies only to getShsArtistById
        <dereferece_attr>...       Access a field/key, works across multiple fields
    """
    d_args_dict = docopt(usage_string, argv=args, version=s.__version__)
    schema = voluptuous.Schema({}, extra=True)
    try:
        d_args_dict = schema(d_args_dict)
    except voluptuous.SchemaError as e:
        exit(e)

    performer = d_args_dict["--performer"]
    date = d_args_dict["--date"]
    page = d_args_dict["--page"]
    pageSize = d_args_dict["--pageSize"]
    if d_args_dict["--getShsArtistById"]:
        o = s.ShsArtist.get_from_resource_id(d_args_dict["<id>"])
        if d_args_dict["--allFields"]:
            o.performances_data
            o.creditedWorks_data
            o.releases_data
    elif d_args_dict["--getShsPerformanceById"]:
        o = s.ShsPerformance.get_from_resource_id(d_args_dict["<id>"])
    elif d_args_dict["--getShsWorkById"]:
        o = s.ShsWork.get_from_resource_id(d_args_dict["<id>"])
    elif d_args_dict["--getShsReleaseById"]:
        o = s.ShsRelease.get_from_resource_id(d_args_dict["<id>"])
    elif d_args_dict["--getShsLabelById"]:
        o = s.ShsLabel.get_from_resource_id(d_args_dict["<id>"])
    elif d_args_dict["--searchWork"]:
        credits_ = d_args_dict["--credits_"]
        o = s.second_hand_search(d_args_dict["title"], type_=s.work, credits_=credits_, page=page, pageSize=pageSize)
    elif d_args_dict["--searchPerformance"]:
        o = s.second_hand_search(
            d_args_dict["title"], type_=s.performance, performer=performer, date=date, page=page, pageSize=pageSize
        )
    else:
        raise Exception("Need to pick a way to search for data.")

    if d_args_dict["<dereferece_attr>"]:
        new_object = o
        for attr_deref in d_args_dict["<dereferece_attr>"]:
            new_object = getattr(new_object, attr_deref)
        print(new_object)
    else:
        print(o)
예제 #2
0
def check_no_comments_for_song_and_post_covers(submission, action_on_find=lambda: None):
    performance = None

    if s.is_youtube_url(submission.url):
        youtube_title = get_youtube_title(submission.url)
        if youtube_title:
            banned_symbols = ".;//\!"
            youtube_title = youtube_title.strip(banned_symbols)

            parts = split_title(youtube_title)
            for (i, part) in enumerate(parts):
                band_name = None
                for combo in no_skip_in_order_combinations_words(part):
                    if is_artist_or_band_name_in_local_db(combo):
                        band_name = combo
                        break
                if band_name:
                    break

            if band_name:
                bands = s.second_hand_search("", common_name=band_name)
                if bands:
                    band = bands[0]
                    performances = band.performances
                    for part in parts[i + 1 :] + parts[: i - 1]:
                        for combo in no_skip_in_order_combinations_words(part):

                            matches = [combo == perf.title for perf in performances]
                            if matches:
                                performance = matches[0]
                                action_on_find({"matchedSong": performance, "submission": submission})

    submission_title = submission.title
    banned_symbols = ".;//\!"
    submission_title = submission_title.strip(banned_symbols)

    parts = split_title(submission_title)
    for (i, part) in enumerate(parts):
        band_name = None
        for combo in no_skip_in_order_combinations_words(part):
            if is_artist_or_band_name_in_local_db(combo):
                band_name = combo
                break
        if band_name:
            break

    if band_name:
        bands = s.second_hand_search("", common_name=band_name)
        if bands:
            band = bands[0]
            performances = band.performances
            for part in parts[i + 1 :] + parts[: i - 1]:
                for combo in no_skip_in_order_combinations_words(part):
                    matches = [combo == perf.title for perf in performances]
                    if matches:
                        performance = matches[0]
                        action_on_find({"matchedSong": performance, "submission": submission})
예제 #3
0
def parseForArtistAndSongTitleB(string):
    res_attempt = None
    common_symbols = [chr(x) for x in range(ord("A"), ord("Z") + 1) + range(ord("a"), ord("z") + 1)] + [
        str(x) for x in range(0, 9 + 1)
    ]
    banned_symbols = ".;//\!"
    banned_symbols.strip(banned_symbols)

    def split_string_by_chars_not_provided(string, provided):
        ans = []
        while string:
            for i in range(len(string)):
                if string[i] not in provided:
                    ans.append(string[0:i])
                    string = string[i + 1 :]
                    break
            if i == len(string) - 1:
                ans.append(string)
                break
        return ans

    def remove_other_symbols(s):
        return " ".join(x for x in split_string_by_chars_not_provided(s, common_symbols) if x)

    part_one, part_two = (None, None)
    match = re.match("\s*([^-]+?)\s*-\s*([^-]+?)\s*-\s*\[\d+:\d+\]", string, flags=re.UNICODE)
    if match:
        part_one, part_two = match.groups()
    else:
        match = re.match("\s*([^-]+?)\s*-\s*([^-]+)\s*", string, flags=re.UNICODE)
        if match:
            part_one, part_two = match.groups()
        else:
            match = re.match("\s*([^-]+?)\s*-\s*\[\d+:\d+\]", string, flags=re.UNICODE)
            if match:
                part_one = match.groups()[0]
            else:
                match = re.match("\s*([^-]+?)\s*\[\d+:\d+\]", string, flags=re.UNICODE)
                if match:
                    part_one = match.groups()[0]
                else:
                    match = re.match("\s*([^-]+?)\s*-\s*([^-]+)", string, flags=re.UNICODE)
                    if match:
                        part_one = match.groups()[0]
                        part_two = match.groups()[1]
                    else:
                        match = re.match("\s*(.*)\s*", string, flags=re.UNICODE)
                        return None
                        if match:
                            part_one = match.groups()[0]
                        else:
                            return None
    try:
        part_one = remove_other_symbols(part_one)
        logging.debug("part_one:" + part_one)
        if part_two:
            part_two = remove_other_symbols(part_two)
            logging.debug("part_two:" + part_two)
            if is_artist_or_band_name_in_local_db(part_two):
                res_attempt = s.second_hand_search(part_one, type_=s.performance, performer=part_two)
            if not res_attempt and is_artist_or_band_name_in_local_db(part_one):
                res_attempt = s.second_hand_search(part_two, type_=s.performance, performer=part_one)
        else:
            res_attempt = s.second_hand_search(part_one, type_=s.performance)
    except Exception, e:
        logging.debug(e)