예제 #1
0
파일: youtube.py 프로젝트: Csstform/Code
def create_response(data, url=False):
    reply = []
    # Should surely have a title, but just in case :P
    if 'title' in data:
        reply.append('{fuchsia}{b}%s{b}{c}' % data['title'])
    # Some length data ;)
    if 'duration' in data:
        length = data['duration']
        lenout = ''
        if length / 3600:  # > 1 hour
            lenout += '%dh ' % (length / 3600)
        if length / 60:
            lenout += '%dm ' % (length / 60 % 60)
            lenout += "%ds" % (length % 60)
        reply.append('{b}length{b} %s' % lenout)
    # Shitty video? FIND OUT!
    if 'rating' in data and 'ratingCount' in data:
        reply.append('{b}rated{b} %.2f/5.00 (%s)' % (
            data['rating'], add_commas(data['ratingCount'])
        ))
    # Number of views. Yuck.
    if 'viewCount' in data:
        reply.append('%s {b}views{b}' % add_commas(data['viewCount']))
    upload_time = parse_date(data['uploaded'])
    reply.append('by {fuchsia}{b}%s{b}{c} on {b}%s{b}' %
                 (data['uploader'], upload_time))
    # Dis shit not be child appr0ved
    if 'contentRating' in data:
        reply.append('{red}{b}NSFW{b}{red}')
    if url and data['player']['default']:
        url = data['player']['default'].split('&', 1)[0].strip()
        reply.append(url)
    return reply
예제 #2
0
파일: youtube.py 프로젝트: HeyMan7/Code
def create_response(data, url=False):
    reply = []
    reply.append('{fuchsia}{b}%s{b}{c}' % data['snippet']['title'])
    _len = data['contentDetails']['duration'].lstrip('PT').lower()
    reply.append(re.sub(r'(?P<n>[0-9])', '{b}\g<n>{b}', _len))
    reply.append('{b}+%s{b}/{b}-%s{b} likes' % (add_commas(data['statistics']['likeCount']), add_commas(data['statistics']['dislikeCount'])))
    reply.append('{b}%s{b} views' % add_commas(data['statistics']['viewCount']))
    upload_time = parse_date(data['snippet']['publishedAt'])
    reply.append('by {fuchsia}{b}%s{b}{c} on {b}%s{b}' % (data['snippet']['channelTitle'], upload_time))

    if 'contentRating' in data['contentDetails']:
        reply.append('{red}{b}NSFW{b}{red}')
    if url:
        reply.append('https://www.youtube.com/watch?v=' + data['id'])
    return reply
예제 #3
0
파일: youtube.py 프로젝트: kamaal44/Code
def create_response(data, url=False):
    reply = []
    reply.append('{fuchsia}{b}%s{b}{c}' % data['snippet']['title'])
    _len = data['contentDetails']['duration'].lstrip('PT').lower()
    reply.append(re.sub(r'(?P<n>[0-9])', '{b}\g<n>{b}', _len))
    reply.append('{b}+%s{b}/{b}-%s{b} likes' %
                 (add_commas(data['statistics']['likeCount']),
                  add_commas(data['statistics']['dislikeCount'])))
    reply.append('{b}%s{b} views' %
                 add_commas(data['statistics']['viewCount']))
    upload_time = parse_date(data['snippet']['publishedAt'])
    reply.append('by {fuchsia}{b}%s{b}{c} on {b}%s{b}' %
                 (data['snippet']['channelTitle'], upload_time))

    if 'contentRating' in data['contentDetails']:
        reply.append('{red}{b}NSFW{b}{red}')
    if url:
        reply.append('https://www.youtube.com/watch?v=' + data['id'])
    return reply
예제 #4
0
파일: soundcloud.py 프로젝트: Csstform/Code
def soundcloud(code, input):
    """Automatically find the information from a soundcloud url and display it
       to users in a channel"""
    try:
        artist = input.group(1)
        title = input.group(2)
        # Should look like 'artist/song'
        data = web.json(uri % (artist, title, client))
        output = []
        # Get date first so we can add to the title
        year, month, day = data['created_at'].split()[0].split('/')
        # Should always have a title
        output.append('{pink}{b}%s{b}{c} ({pink}{b}%s/%s/%s{b}{c})' % (data['title'], month, day, year))
        # Should always have an artist
        output.append('uploaded by {pink}{b}%s{b}{c}' % data['user']['username'])
        # Genre!
        if data['genre']:
            output.append('{pink}{b}' + data['genre'] + '{b}{c}')
        # Playback count, if none, obviously don't add it
        if int(data['playback_count']) > 0:
            output.append('{pink}{b}%s{b}{c} plays' % add_commas(data['playback_count']))
        # Download count, if none, obviously don't add it
        if int(data['download_count']) > 0:
            output.append('{pink}{b}%s{b}{c} downloads' % add_commas(data['download_count']))
        # And the same thing with the favorites count
        if int(data['favoritings_count']) > 0:
            output.append('{pink}{b}%s{b}{c} favs' % add_commas(data['favoritings_count']))
        # Comments too!
        if int(data['comment_count']) > 0:
            output.append('{pink}{b}%s{b}{c} comments' % add_commas(data['comment_count']))
        # Tags!
        if len(data['tag_list'].split()) > 0:
            # Rap "taylor gang" "Hip Hop" "20 joints" traxxfdr
            quote = '"'
            tags = []
            tag_list = data['tag_list'].split()
            multi_word_tag = ''
            for tmp in tag_list:
                if tmp.startswith(quote):
                    # Start of a multi-word tag
                    multi_word_tag = tmp.strip(quote)
                elif tmp.endswith(quote):
                    # End of multi-word tag
                    multi_word_tag += ' ' + tmp.strip(quote)
                    tags.append(multi_word_tag)
                    multi_word_tag = ''
                elif len(multi_word_tag) > 0:
                    # It's a middle-word
                    multi_word_tag += ' ' + tmp
                else:
                    # It's just it's own tag. \o/
                    tags.append(tmp)

            for i in range(len(tags)):
                if len(tags[i].split()) > 1:
                    tags[i] = '(#{pink}{b}"%s"{b}{c})' % tags[i]
                else:
                    tags[i] = '(#{pink}{b}%s{b}{c})' % tags[i]
            output.append(' '.join(tags))
        return code.say(' - '.join(output))
    except:
        return
예제 #5
0
파일: soundcloud.py 프로젝트: kamaal44/Code
def soundcloud(code, input):
    """Automatically find the information from a soundcloud url and display it
       to users in a channel"""
    try:
        artist = input.group(1)
        title = input.group(2)
        # Should look like 'artist/song'
        data = web.json(uri % (artist, title, client))
        output = []
        # Get date first so we can add to the title
        year, month, day = data['created_at'].split()[0].split('/')
        # Should always have a title
        output.append('{pink}{b}%s{b}{c} ({pink}{b}%s/%s/%s{b}{c})' % (data['title'], month, day, year))
        # Should always have an artist
        output.append('uploaded by {pink}{b}%s{b}{c}' % data['user']['username'])
        # Genre!
        if data['genre']:
            output.append('{pink}{b}' + data['genre'] + '{b}{c}')
        # Playback count, if none, obviously don't add it
        if int(data['playback_count']) > 0:
            output.append('{pink}{b}%s{b}{c} plays' % add_commas(data['playback_count']))
        # Download count, if none, obviously don't add it
        if int(data['download_count']) > 0:
            output.append('{pink}{b}%s{b}{c} downloads' % add_commas(data['download_count']))
        # And the same thing with the favorites count
        if int(data['favoritings_count']) > 0:
            output.append('{pink}{b}%s{b}{c} favs' % add_commas(data['favoritings_count']))
        # Comments too!
        if int(data['comment_count']) > 0:
            output.append('{pink}{b}%s{b}{c} comments' % add_commas(data['comment_count']))
        # Tags!
        if len(data['tag_list'].split()) > 0:
            # Rap "taylor gang" "Hip Hop" "20 joints" traxxfdr
            quote = '"'
            tags = []
            tag_list = data['tag_list'].split()
            multi_word_tag = ''
            for tmp in tag_list:
                if tmp.startswith(quote):
                    # Start of a multi-word tag
                    multi_word_tag = tmp.strip(quote)
                elif tmp.endswith(quote):
                    # End of multi-word tag
                    multi_word_tag += ' ' + tmp.strip(quote)
                    tags.append(multi_word_tag)
                    multi_word_tag = ''
                elif len(multi_word_tag) > 0:
                    # It's a middle-word
                    multi_word_tag += ' ' + tmp
                else:
                    # It's just it's own tag. \o/
                    tags.append(tmp)

            for i in range(len(tags)):
                if len(tags[i].split()) > 1:
                    tags[i] = '(#{pink}{b}"%s"{b}{c})' % tags[i]
                else:
                    tags[i] = '(#{pink}{b}%s{b}{c})' % tags[i]
            output.append(' '.join(tags))
        return code.say(' - '.join(output))
    except:
        return