-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'devel' of https://github.com/Tribler/tribler into proto…
…bufserialization_rc
- Loading branch information
Showing
25 changed files
with
501 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Tribler/Core/Modules/restapi/channels/channels_popular_endpoint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import json | ||
from twisted.web import http | ||
from Tribler.Core.Modules.restapi.channels.base_channels_endpoint import BaseChannelsEndpoint | ||
from Tribler.Core.Modules.restapi.util import convert_db_channel_to_json | ||
|
||
|
||
class ChannelsPopularEndpoint(BaseChannelsEndpoint): | ||
|
||
def render_GET(self, request): | ||
""" | ||
.. http:get:: /channels/popular?limit=(int:max nr of channels) | ||
A GET request to this endpoint will return the most popular discovered channels in Tribler. | ||
You can optionally pass a limit parameter to limit the number of results. | ||
**Example request**: | ||
.. sourcecode:: none | ||
curl -X GET http://localhost:8085/channels/popular?limit=1 | ||
**Example response**: | ||
.. sourcecode:: javascript | ||
{ | ||
"channels": [{ | ||
"id": 3, | ||
"dispersy_cid": "da69aaad39ccf468aba2ab9177d5f8d8160135e6", | ||
"name": "My fancy channel", | ||
"description": "A description of this fancy channel", | ||
"subscribed": False, | ||
"votes": 23, | ||
"torrents": 3, | ||
"spam": 5, | ||
"modified": 14598395, | ||
}] | ||
} | ||
""" | ||
limit_channels = 10 | ||
|
||
if 'limit' in request.args and len(request.args['limit']) > 0: | ||
limit_channels = int(request.args['limit'][0]) | ||
|
||
if limit_channels <= 0: | ||
request.setResponseCode(http.BAD_REQUEST) | ||
return json.dumps({"error": "the limit parameter must be a positive number"}) | ||
|
||
popular_channels = self.channel_db_handler.getMostPopularChannels(max_nr=limit_channels) | ||
results_json = [convert_db_channel_to_json(channel) for channel in popular_channels] | ||
return json.dumps({"channels": results_json}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import json | ||
|
||
from twisted.web import http, resource | ||
|
||
from Tribler.Core.Modules.restapi.util import convert_db_torrent_to_json | ||
from Tribler.Core.simpledefs import NTFY_TORRENTS, NTFY_CHANNELCAST | ||
|
||
|
||
class TorrentsEndpoint(resource.Resource): | ||
|
||
def __init__(self, session): | ||
resource.Resource.__init__(self) | ||
|
||
child_handler_dict = {"random": TorrentsRandomEndpoint} | ||
|
||
for path, child_cls in child_handler_dict.iteritems(): | ||
self.putChild(path, child_cls(session)) | ||
|
||
|
||
class TorrentsRandomEndpoint(resource.Resource): | ||
|
||
def __init__(self, session): | ||
resource.Resource.__init__(self) | ||
self.session = session | ||
self.channel_db_handler = self.session.open_dbhandler(NTFY_CHANNELCAST) | ||
self.torrents_db_handler = self.session.open_dbhandler(NTFY_TORRENTS) | ||
|
||
def render_GET(self, request): | ||
""" | ||
.. http:get:: /torrents/random?limit=(int: max nr of torrents) | ||
A GET request to this endpoint returns random (channel) torrents. | ||
You can optionally specify a limit parameter to limit the maximum number of results. By default, this is 10. | ||
**Example request**: | ||
.. sourcecode:: none | ||
curl -X GET http://localhost:8085/torrents/random?limit=1 | ||
**Example response**: | ||
.. sourcecode:: javascript | ||
{ | ||
"torrents": [{ | ||
"id": 4, | ||
"infohash": "97d2d8f5d37e56cfaeaae151d55f05b077074779", | ||
"name": "Ubuntu-16.04-desktop-amd64", | ||
"size": 8592385, | ||
"category": "other", | ||
"num_seeders": 42, | ||
"num_leechers": 184, | ||
"last_tracker_check": 1463176959 | ||
}] | ||
} | ||
""" | ||
limit_torrents = 10 | ||
|
||
if 'limit' in request.args and len(request.args['limit']) > 0: | ||
limit_torrents = int(request.args['limit'][0]) | ||
|
||
if limit_torrents <= 0: | ||
request.setResponseCode(http.BAD_REQUEST) | ||
return json.dumps({"error": "the limit parameter must be a positive number"}) | ||
|
||
torrent_db_columns = ['Torrent.torrent_id', 'infohash', 'Torrent.name', 'length', 'Torrent.category', | ||
'num_seeders', 'num_leechers', 'last_tracker_check', 'ChannelTorrents.inserted'] | ||
popular_torrents = self.channel_db_handler.get_random_channel_torrents(torrent_db_columns, limit=limit_torrents) | ||
results_json = [convert_db_torrent_to_json(popular_torrent) for popular_torrent in popular_torrents] | ||
return json.dumps({"torrents": results_json}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.