Beispiel #1
0
def request(query, params):
    params['url'] = search_url.format(query=quote_plus(query),
                                      page=params['pageno'])
    if params['time_range'] in time_range_dict:
        params['url'] += time_range_url.format(time_range=time_range_dict[params['time_range']])

    return params
Beispiel #2
0
def request(query, params):
    offset = (params['pageno'] - 1) * 10
    params['url'] = search_url.format(position=offset,
                                      query=quote_plus(query))
    params['cookies']['frontend.auid'] = ''.join(random.choice(
        digg_cookie_chars) for _ in range(22))
    return params
Beispiel #3
0
def response(resp):
    results = []

    search_res = loads(resp.text)

    # parse results
    for result in search_res.get('collection', []):
        if result['kind'] in ('track', 'playlist'):
            title = result['title']
            content = result['description']
            publishedDate = parser.parse(result['last_modified'])
            uri = quote_plus(result['uri'])
            embedded = embedded_url.format(uri=uri)

            # append result
            results.append({
                'url': result['permalink_url'],
                'title': title,
                'publishedDate': publishedDate,
                'embedded': embedded,
                'content': content
            })

    # return results
    return results
Beispiel #4
0
def request(query, params):
    params['url'] = search_url.format(query=quote_plus(query),
                                      page=params['pageno'])
    if params['time_range'] in time_range_dict:
        params['url'] += time_range_url.format(
            time_range=time_range_dict[params['time_range']])

    return params
Beispiel #5
0
def request(query, params):
    pageno = params['pageno']
    start_index = (int(pageno) - 1) * 10
    params['url'] = search_url.format(query=quote_plus(query),
                                      start_index=start_index)
    # if params['time_range'] in time_range_dict:
    #     params['url'] += time_range_url.format(time_range=time_range_dict[params['time_range']])

    return params
Beispiel #6
0
def request(query, params):
    time_range_dict = {
        "day": "today",
        "week": "week",
        "month": "month",
        "year": "year",
    }
    search_url = base_url + "api/v1/search?q={query}"
    params["url"] = search_url.format(
        query=quote_plus(query)) + "&page={pageno}".format(
            pageno=params["pageno"])

    if params["time_range"] in time_range_dict:
        params["url"] += "&date={timerange}".format(
            timerange=time_range_dict[params["time_range"]])

    if params["language"] != "all":
        lang = params["language"].split("-")
        if len(lang) == 2:
            params["url"] += "&range={lrange}".format(lrange=lang[1])

    return params
Beispiel #7
0
def request(query, params):
    offset = (params['pageno'] - 1) * 10
    params['url'] = search_url.format(position=offset, query=quote_plus(query))
    return params
Beispiel #8
0
def request(query, params):
    params['url'] = search_url.format(query=quote_plus(query),
                                      pageno=params['pageno'])
    return params
Beispiel #9
0
def request(query, params):
    offset = (params['pageno'] - 1) * 10
    params['url'] = search_url.format(position=offset, query=quote_plus(query))
    params['cookies']['frontend.auid'] = ''.join(
        random.choice(digg_cookie_chars) for _ in range(22))
    return params
Beispiel #10
0
    def test_response(self):
        self.assertRaises(AttributeError, soundcloud.response, None)
        self.assertRaises(AttributeError, soundcloud.response, [])
        self.assertRaises(AttributeError, soundcloud.response, '')
        self.assertRaises(AttributeError, soundcloud.response, '[]')

        response = mock.Mock(text='{}')
        self.assertEqual(soundcloud.response(response), [])

        response = mock.Mock(text='{"data": []}')
        self.assertEqual(soundcloud.response(response), [])

        json = """
        {
        "collection": [
            {
            "kind": "track",
            "id": 159723640,
            "created_at": "2014/07/22 00:51:21 +0000",
            "user_id": 2976616,
            "duration": 303780,
            "commentable": true,
            "state": "finished",
            "original_content_size": 13236349,
            "last_modified": "2015/01/31 15:14:50 +0000",
            "sharing": "public",
            "tag_list": "seekae flume",
            "permalink": "seekae-test-recognise-flume-re-work",
            "streamable": true,
            "embeddable_by": "all",
            "downloadable": true,
            "purchase_url": "http://www.facebook.com/seekaemusic",
            "label_id": null,
            "purchase_title": "Seekae",
            "genre": "freedownload",
            "title": "This is the title",
            "description": "This is the content",
            "label_name": "Future Classic",
            "release": "",
            "track_type": "remix",
            "key_signature": "",
            "isrc": "",
            "video_url": null,
            "bpm": null,
            "release_year": 2014,
            "release_month": 7,
            "release_day": 22,
            "original_format": "mp3",
            "license": "all-rights-reserved",
            "uri": "https://api.soundcloud.com/tracks/159723640",
            "user": {
                "id": 2976616,
                "kind": "user",
                "permalink": "flume",
                "username": "******",
                "last_modified": "2014/11/24 19:21:29 +0000",
                "uri": "https://api.soundcloud.com/users/2976616",
                "permalink_url": "http://soundcloud.com/flume",
                "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg"
            },
            "permalink_url": "http://soundcloud.com/this.is.the.url",
            "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg",
            "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png",
            "stream_url": "https://api.soundcloud.com/tracks/159723640/stream",
            "download_url": "https://api.soundcloud.com/tracks/159723640/download",
            "playback_count": 2190687,
            "download_count": 54856,
            "favoritings_count": 49061,
            "comment_count": 826,
            "likes_count": 49061,
            "reposts_count": 15910,
            "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments",
            "policy": "ALLOW"
            }
        ],
        "total_results": 375750,
        "next_href": "https://api.soundcloud.com/search?&q=test",
        "tx_id": ""
        }
        """
        response = mock.Mock(text=json)
        results = soundcloud.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['title'], 'This is the title')
        self.assertEqual(results[0]['url'], 'http://soundcloud.com/this.is.the.url')
        self.assertEqual(results[0]['content'], 'This is the content')
        self.assertIn(quote_plus('https://api.soundcloud.com/tracks/159723640'), results[0]['embedded'])

        json = """
        {
        "collection": [
            {
            "kind": "user",
            "id": 159723640,
            "created_at": "2014/07/22 00:51:21 +0000",
            "user_id": 2976616,
            "duration": 303780,
            "commentable": true,
            "state": "finished",
            "original_content_size": 13236349,
            "last_modified": "2015/01/31 15:14:50 +0000",
            "sharing": "public",
            "tag_list": "seekae flume",
            "permalink": "seekae-test-recognise-flume-re-work",
            "streamable": true,
            "embeddable_by": "all",
            "downloadable": true,
            "purchase_url": "http://www.facebook.com/seekaemusic",
            "label_id": null,
            "purchase_title": "Seekae",
            "genre": "freedownload",
            "title": "This is the title",
            "description": "This is the content",
            "label_name": "Future Classic",
            "release": "",
            "track_type": "remix",
            "key_signature": "",
            "isrc": "",
            "video_url": null,
            "bpm": null,
            "release_year": 2014,
            "release_month": 7,
            "release_day": 22,
            "original_format": "mp3",
            "license": "all-rights-reserved",
            "uri": "https://api.soundcloud.com/tracks/159723640",
            "user": {
                "id": 2976616,
                "kind": "user",
                "permalink": "flume",
                "username": "******",
                "last_modified": "2014/11/24 19:21:29 +0000",
                "uri": "https://api.soundcloud.com/users/2976616",
                "permalink_url": "http://soundcloud.com/flume",
                "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg"
            },
            "permalink_url": "http://soundcloud.com/this.is.the.url",
            "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg",
            "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png",
            "stream_url": "https://api.soundcloud.com/tracks/159723640/stream",
            "download_url": "https://api.soundcloud.com/tracks/159723640/download",
            "playback_count": 2190687,
            "download_count": 54856,
            "favoritings_count": 49061,
            "comment_count": 826,
            "likes_count": 49061,
            "reposts_count": 15910,
            "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments",
            "policy": "ALLOW"
            }
        ],
        "total_results": 375750,
        "next_href": "https://api.soundcloud.com/search?&q=test",
        "tx_id": ""
        }
        """
        response = mock.Mock(text=json)
        results = soundcloud.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 0)

        json = """
        {
        "collection": [],
        "total_results": 375750,
        "next_href": "https://api.soundcloud.com/search?&q=test",
        "tx_id": ""
        }
        """
        response = mock.Mock(text=json)
        results = soundcloud.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 0)
Beispiel #11
0
def request(query, params):
    params['url'] = search_url.format(query=quote_plus(query),
                                      pageno=params['pageno'])
    return params
Beispiel #12
0
    def test_response(self):
        self.assertRaises(AttributeError, soundcloud.response, None)
        self.assertRaises(AttributeError, soundcloud.response, [])
        self.assertRaises(AttributeError, soundcloud.response, '')
        self.assertRaises(AttributeError, soundcloud.response, '[]')

        response = mock.Mock(text='{}')
        self.assertEqual(soundcloud.response(response), [])

        response = mock.Mock(text='{"data": []}')
        self.assertEqual(soundcloud.response(response), [])

        json = """
        {
        "collection": [
            {
            "kind": "track",
            "id": 159723640,
            "created_at": "2014/07/22 00:51:21 +0000",
            "user_id": 2976616,
            "duration": 303780,
            "commentable": true,
            "state": "finished",
            "original_content_size": 13236349,
            "last_modified": "2015/01/31 15:14:50 +0000",
            "sharing": "public",
            "tag_list": "seekae flume",
            "permalink": "seekae-test-recognise-flume-re-work",
            "streamable": true,
            "embeddable_by": "all",
            "downloadable": true,
            "purchase_url": "http://www.facebook.com/seekaemusic",
            "label_id": null,
            "purchase_title": "Seekae",
            "genre": "freedownload",
            "title": "This is the title",
            "description": "This is the content",
            "label_name": "Future Classic",
            "release": "",
            "track_type": "remix",
            "key_signature": "",
            "isrc": "",
            "video_url": null,
            "bpm": null,
            "release_year": 2014,
            "release_month": 7,
            "release_day": 22,
            "original_format": "mp3",
            "license": "all-rights-reserved",
            "uri": "https://api.soundcloud.com/tracks/159723640",
            "user": {
                "id": 2976616,
                "kind": "user",
                "permalink": "flume",
                "username": "******",
                "last_modified": "2014/11/24 19:21:29 +0000",
                "uri": "https://api.soundcloud.com/users/2976616",
                "permalink_url": "http://soundcloud.com/flume",
                "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg"
            },
            "permalink_url": "http://soundcloud.com/this.is.the.url",
            "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg",
            "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png",
            "stream_url": "https://api.soundcloud.com/tracks/159723640/stream",
            "download_url": "https://api.soundcloud.com/tracks/159723640/download",
            "playback_count": 2190687,
            "download_count": 54856,
            "favoritings_count": 49061,
            "comment_count": 826,
            "likes_count": 49061,
            "reposts_count": 15910,
            "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments",
            "policy": "ALLOW"
            }
        ],
        "total_results": 375750,
        "next_href": "https://api.soundcloud.com/search?&q=test",
        "tx_id": ""
        }
        """
        response = mock.Mock(text=json)
        results = soundcloud.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['title'], 'This is the title')
        self.assertEqual(results[0]['url'],
                         'http://soundcloud.com/this.is.the.url')
        self.assertEqual(results[0]['content'], 'This is the content')
        self.assertIn(
            quote_plus('https://api.soundcloud.com/tracks/159723640'),
            results[0]['embedded'])

        json = """
        {
        "collection": [
            {
            "kind": "user",
            "id": 159723640,
            "created_at": "2014/07/22 00:51:21 +0000",
            "user_id": 2976616,
            "duration": 303780,
            "commentable": true,
            "state": "finished",
            "original_content_size": 13236349,
            "last_modified": "2015/01/31 15:14:50 +0000",
            "sharing": "public",
            "tag_list": "seekae flume",
            "permalink": "seekae-test-recognise-flume-re-work",
            "streamable": true,
            "embeddable_by": "all",
            "downloadable": true,
            "purchase_url": "http://www.facebook.com/seekaemusic",
            "label_id": null,
            "purchase_title": "Seekae",
            "genre": "freedownload",
            "title": "This is the title",
            "description": "This is the content",
            "label_name": "Future Classic",
            "release": "",
            "track_type": "remix",
            "key_signature": "",
            "isrc": "",
            "video_url": null,
            "bpm": null,
            "release_year": 2014,
            "release_month": 7,
            "release_day": 22,
            "original_format": "mp3",
            "license": "all-rights-reserved",
            "uri": "https://api.soundcloud.com/tracks/159723640",
            "user": {
                "id": 2976616,
                "kind": "user",
                "permalink": "flume",
                "username": "******",
                "last_modified": "2014/11/24 19:21:29 +0000",
                "uri": "https://api.soundcloud.com/users/2976616",
                "permalink_url": "http://soundcloud.com/flume",
                "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg"
            },
            "permalink_url": "http://soundcloud.com/this.is.the.url",
            "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg",
            "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png",
            "stream_url": "https://api.soundcloud.com/tracks/159723640/stream",
            "download_url": "https://api.soundcloud.com/tracks/159723640/download",
            "playback_count": 2190687,
            "download_count": 54856,
            "favoritings_count": 49061,
            "comment_count": 826,
            "likes_count": 49061,
            "reposts_count": 15910,
            "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments",
            "policy": "ALLOW"
            }
        ],
        "total_results": 375750,
        "next_href": "https://api.soundcloud.com/search?&q=test",
        "tx_id": ""
        }
        """
        response = mock.Mock(text=json)
        results = soundcloud.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 0)

        json = """
        {
        "collection": [],
        "total_results": 375750,
        "next_href": "https://api.soundcloud.com/search?&q=test",
        "tx_id": ""
        }
        """
        response = mock.Mock(text=json)
        results = soundcloud.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 0)