Example #1
0
def api_streaming_transcode(link):
    transcode_endpoint = "transcode/"
    user_credentials = get_credentials()
    if user_credentials is None:
        print(
            "No credentials were loaded, check if the user has gone through the authentication procedure"
        )
        return None

    endpoint = streaming_url + transcode_endpoint + link

    result = make_get(endpoint, access_token=user_credentials[access_token])

    streaming_json = result.json()
    markdown = "If the links are not working, unrestrict the file again and try to /stream with the new ID\.\n"

    if "apple" in streaming_json:
        markdown += "Apple:\n" + escape_markdown(
            streaming_json["apple"]["full"], version=2) + "\n"
    if "dash" in streaming_json:
        markdown += "dash:\n" + escape_markdown(streaming_json["dash"]["full"],
                                                version=2) + "\n"
    if "liveMP4" in streaming_json:
        markdown += "liveMP4:\n" + escape_markdown(
            streaming_json["liveMP4"]["full"], version=2) + "\n"
    if "h264WebM" in streaming_json:
        markdown += "h264WebM:\n" + escape_markdown(
            streaming_json["h264WebM"]["full"], version=2) + "\n"

    markdown += "\n"

    if len(markdown) > 90:
        return markdown
    else:
        return prettify_json(streaming_json)
def get_verification(device_code, cid=open_source_client_id):
    result = make_get(credential_url,
                      params={
                          client_id: cid,
                          code: device_code
                      },
                      use_headers=False)
    return result
Example #3
0
def api_downloads_list(offset=None, page=1, limit=5):
    endpoint = downloads_url

    data = {}
    if offset is not None:
        if offset:
            data["offset"] = offset
        else:
            data["offset"] = 0
    else:
        data["offset"] = 0

    data["page"] = page
    data["limit"] = limit

    user_credentials = get_credentials()
    if user_credentials is None:
        print(
            "No credentials were loaded, check if the user has gone through the authentication procedure"
        )
        return None
    result = make_get(endpoint,
                      params=data,
                      access_token=user_credentials[access_token])

    download_json = result.json()
    markdown = ""

    for download in download_json:
        if "filename" in download:
            markdown += "*" + escape_markdown(download["filename"],
                                              version=2) + "*\n"
        if "filesize" in download:
            markdown += "Size: " + escape_markdown(str('%.2f' %
                                                       (download["filesize"] /
                                                        (1024 * 1024))),
                                                   version=2) + " MB\n"
        if "download" in download:
            markdown += escape_markdown("Download Link:\n" +
                                        download["download"] + "\n",
                                        version=2)
        if "streamable" in download:
            if download["streamable"] == 1:
                markdown += "Streamable: Yes\n"
                markdown += escape_markdown("Streaming ID: " + download["id"] +
                                            "\n",
                                            version=2)
            else:
                markdown += "Streamable: No\n"

        markdown += "\n"

    if len(markdown) > 5:
        return markdown
    else:
        return prettify_json(download_json)
Example #4
0
def api_user_get():
    # todo: this method is used to check for status so we initialize user_credentials here
    user_credentials = get_credentials()
    if user_credentials is None:
        print(
            "No credentials were loaded, check if the user has gone through the authentication procedure"
        )
        return None
    result = make_get(user_url, access_token=user_credentials[access_token])
    data = result.json()
    return prettify_json(data, _description="Avatar", _link=data["avatar"])
Example #5
0
def api_torrents_list(offset=None, page=1, limit=5, _filter=None):
    endpoint = torrents_url

    params = {"page": page}
    # You can not use both offset and page at the same time, page is prioritized in case it happens.
    if offset is not None:
        params["offset"] = offset

    params["limit"] = limit
    # "active", list active torrents first
    if _filter is not None:
        params["filter"] = _filter

    user_credentials = get_credentials()
    if user_credentials is None:
        print(
            "No credentials were loaded, check if the user has gone through the authentication procedure"
        )
        return None
    result = make_get(endpoint,
                      params,
                      access_token=user_credentials[access_token])

    torrent_json = result.json()

    markdown = ""
    for torrent in torrent_json:
        if "filename" in torrent:
            markdown += "*" + escape_markdown(torrent["filename"],
                                              version=2) + "*\n"
        if "bytes" in torrent:
            markdown += "Size: " + escape_markdown(
                str('%.2f' % (torrent["bytes"] /
                              (1024 * 1024))), version=2) + " MB\n"
        if "progress" in torrent:
            if torrent["progress"] != 100:
                markdown += escape_markdown("Progress: " +
                                            str(torrent["progress"]) + "%\n",
                                            version=2)
        if "links" in torrent:
            if len(torrent["links"]) > 0:
                markdown += escape_markdown(
                    "Download Links (unrestrict these first):\n", version=2)
                for link in torrent["links"]:
                    markdown += escape_markdown(link + "\n", version=2)
        markdown += "\n"

    if len(markdown) > 5:
        return markdown
    else:
        return prettify_json(torrent_json)
Example #6
0
def api_get_hosts():
    endpoint = torrents_url + "/availableHosts"

    user_credentials = get_credentials()
    if user_credentials is None:
        print(
            "No credentials were loaded, check if the user has gone through the authentication procedure"
        )
        return None

    result = make_get(endpoint, access_token=user_credentials[access_token])

    if result.status_code != 200:
        print(result.json())
        return []

    return result.json()
def get_auth(cid=open_source_client_id):
    # Your application makes a direct request to the device endpoint, with the query string parameters client_id and
    # new_credentials=yes, and obtains a JSON object with authentication data that will be used for the rest of the
    # process.

    # link = device_url + "?" + client_id_param.format(temp_client_id) + "&" + new_credentials_param
    # result = requests.get(link)
    result = make_get(device_url,
                      params={
                          client_id: cid,
                          new_credentials: "yes"
                      },
                      use_headers=False)

    if result.status_code != 200:
        print("Error logging in, status code ", result.status_code)
        exit(1)
    else:
        return result
def check_token_call(credentials):
    user_url = base_url + user_endpoint
    result = make_get(user_url, access_token=credentials["access_token"])
    return token_check_and_update(result)