Giter Club home page Giter Club logo

pyopenload's Introduction

PyOpenload StarButton

python wrapper for Openload.co API.

travis pypi format CodacyBadge license

Install

$ pip install pyopenload

Usage

All API features are implemented.

Retrieve account info

from openload import OpenLoad

ol = OpenLoad('login', 'key')

account_info = ol.account_info()
print(account_info)

Upload file

from openload import OpenLoad

ol = OpenLoad('login', 'key')

uploaded_file_info = ol.upload_file('/home/username/file.txt')
print(uploaded_file_info)

Retrieve file info

from openload import OpenLoad

ol = OpenLoad('login', 'key')

# Random file id.
file_id = 'YMTqhQAuzVX'

file_info = ol.file_info(file_id)
print(file_info)

Documentation

documentation is available at https://pyopenload.readthedocs.io/.

pyopenload's People

Contributors

codacy-badger avatar mohan3d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pyopenload's Issues

Cannot import name OpenLoad.

Hi,

I've Just moved my script onto my Linux debian Jessie server installed pyopenload via pip install pyopenload but I keep getting the error Cannot import name OpenLoad. Looking online they say this is a circular dependent import issue but I don't believe that is the case as the script works on my windows pc.

I've tested on another windows pc and a Ubuntu desktop, to rule out my script I use the console typed from openload import OpenLoad and I still get the error.

Using help("modules") I can see that the module is installed and I can also find the files in the python install.

Any ideas?

Upload large files issue, references missing

Hello i've copy pasted your code from the documentation but encoder and requests are unresolved references.

this is the code:

class MyOpenLoad(OpenLoad):
def upload_large_file(self, file_path, **kwargs):
    response = self.upload_link(**kwargs)
    upload_url = response['url']

    _, file_name = os.path.split(file_path)

    with open(file_path, 'rb') as upload_file:
        data = encoder.MultipartEncoder({
            "files": (file_name, upload_file, "application/octet-stream"),
        })

        headers = {"Prefer": "respond-async", "Content-Type": data.content_type}
        response_json = requests.post(upload_url, headers=headers, data=data).json()

    self._check_status(response_json)
    return return response_json['result']


ol = MyOpenLoad('login', 'key')
uploaded_file_info = ol.upload_large_file('FILE_PATH')

print(uploaded_file_info)

Re-attempt upload if taking too long

Sometimes, it takes very long to get a response and my application gets stuck in limbo. Need to be able to re-attempt upload in case the server doesn't send a response.

Also, consider adding upload_large_file() to the main source?

using Streaming upload

Hi, me again.

I have an issue whereby I'm unable to upload large files from my server as your script uses chucked uploading (as I'm sure you know this loads the file into ram) I would rather use streaming upload (that does not load into ram)

I tried to edit your code but have had no luck I get no errors but the file also does not upload any ideas?

   def upload_file(self, file_path, **kwargs):
        
        response = self.upload_link(**kwargs)
        upload_url = response['url']

        m = MultipartEncoder(fields={'field0':('filename', open(file_path, 'rb'))})

        requests.post(upload_url, data=m)

I've also added stream=True to the get request.

I'm using requests_toolbelt to-do this

update:

I believe the server is giving a response 500 error.

update2:

I've found the 500 error " upload failed: no boundary defined in Content-Type " I thought requests handled the header?

I've tried adding headers = {'content-type': 'video/mp4'} to the post request to manually add it but no success

not working json.decoder.JSONDecodeError

openload = OpenLoad('...', '...')
uploaded_file_info = openload.upload_file(mp4newname_path)

Note: mp4newname_path is a string with full path like "/home/user/myfile.mp4"

will give this:
File "./migrar-openload.py", line 94, in MigrarOpenload
uploaded_file_info = openload.upload_file(mp4newname_path)
File "/usr/local/lib/python3.5/dist-packages/openload/openload.py", line 258, in upload_file
files={'upload_file': open(file_path, 'rb')}).json()
File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 892, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.5/json/init.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

ImportError: cannot import name 'OpenLoad'

My file:
`#!/usr/bin/env python

from openload import OpenLoad

def openLoader(file):

login="login"
key="pass"

ol = OpenLoad(login, key)

uploaded_file_info = ol.upload_file(file)
print(uploaded_file_info)

openLoader("cover.jpg")`

Error:
Traceback (most recent call last): File "/home/pi/Desktop/openloadAPI/openload.py", line 3, in <module> from openload import OpenLoad File "/home/pi/Desktop/openloadAPI/openload.py", line 3, in <module> from openload import OpenLoad ImportError: cannot import name 'OpenLoad'

upload big file in low memory environment

Traceback (most recent call last):
File "upload_to_openload.py", line 11, in
uploaded_file_info = ol.upload_file(os.path.join(root, filename))
File "/usr/local/lib/python2.7/dist-packages/openload/openload.py", line 258, in upload_file
files={'upload_file': open(file_path, 'rb')}).json()
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python2.7/dist-packages/simplejson/init.py", line 516, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 374, in decode
obj, end = self.raw_decode(s)
File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 404, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I am running it via Raspberry pi which is 1GB memory only, it looks like running out of memory when it uploads big files more than 1G, any idea how to fix it?

API alternatives

Hello mohan3d and thank you for the tool.

I just have one question in case someone didn't want to use the API what other alternatives would be available to upload files using python?

Loop upload Error

Hi
When I do this code:

uploaded_file_info = ol.upload_file(c:\video\file.mp4)
print(uploaded_file_info)

It works just fine

But when I try to loop from a CSV file
it give the error below:

_with open('ListTest.1.csv', 'r') as csv_file:
    csv_reader = csv.reader(csv_file)
    next(csv_reader)
    for line in csv_reader:
        print(line)
        
        name = (line[0])
        VidPath = (line[4])
        

        print(name)
        print(VidPath)

        uploaded_file_info = ol.upload_file(VidPath)
        print(uploaded_file_info)_ 

Traceback :

Traceback (most recent call last):
  File "PrintingTest.py", line 19, in <module>
    uploaded_file_info = ol.upload_file(VidPath)
  File "C:\Users\resta\Anaconda3\lib\site-packages\openload\openload.py", line 258, in upload_file
    files={'upload_file': open(file_path, 'rb')}).json()
OSError: [Errno 22] Invalid argument: ' c:\video\file.mp4'

What am I doing wrong?

'solve_captcha' is not defined

It raises this error that 'solve_captcha' is not defined. Also do I have to manually solve the captcha or is the script going to do it?

Error regarding no bandwith for api download

Thre is an error that is not going away even after 7 hours from the initial testing.

Error:
openload.api_exceptions.BandwidthUsageExceeded: bandwidth usage too high (peak hours). out of capacity for non-browser downloads. please use browser download

Just letting you know guys! Thanks for this piece of code

Can't upload file - Memory Error

Hi, i've wrote some code to upload every file in a folder.

I take the files from an output folder (the files are processed beforehand by removing the space in the name), i've double checked that the files are in the correct folder.

This is the code:

mainol = OpenLoad(configacc['main']['login'], configacc['main']['key'])

outfiles = os.listdir(outputdir)

for filename in outfiles:
    print(f"Starting to upload file: {filename}")
    fullpath = outputdir + '\\' + filename
    print(fullpath)
# the path prints correctly.
    uploaded_file_info = mainol.upload_file(fullpath)

The error that the interpreter returns is:

Traceback (most recent call last):
  File "C:/Users/user/Desktop/Python_dev/openloadupper/main.py", line 200, in <module>
    uploaded_file_info = mainol.upload_file(fullpath)
  File "C:\Users\user\Desktop\Python_dev\openloadupper\venv\lib\site-packages\openload\openload.py", line 258, in upload_file
    files={'upload_file': open(file_path, 'rb')}).json()
  File "C:\Users\user\Desktop\Python_dev\openloadupper\venv\lib\site-packages\requests\api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "C:\Users\user\Desktop\Python_dev\openloadupper\venv\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\user\Desktop\Python_dev\openloadupper\venv\lib\site-packages\requests\sessions.py", line 519, in request
    prep = self.prepare_request(req)
  File "C:\Users\user\Desktop\Python_dev\openloadupper\venv\lib\site-packages\requests\sessions.py", line 462, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "C:\Users\user\Desktop\Python_dev\openloadupper\venv\lib\site-packages\requests\models.py", line 316, in prepare
    self.prepare_body(data, files, json)
  File "C:\Users\user\Desktop\Python_dev\openloadupper\venv\lib\site-packages\requests\models.py", line 504, in prepare_body
    (body, content_type) = self._encode_files(files, data)
  File "C:\Users\user\Desktop\Python_dev\openloadupper\venv\lib\site-packages\requests\models.py", line 169, in _encode_files
    body, content_type = encode_multipart_formdata(new_fields)
  File "C:\Users\user\Desktop\Python_dev\openloadupper\venv\lib\site-packages\urllib3\filepost.py", line 92, in encode_multipart_formdata
    body.write(b'\r\n')
MemoryError

Any help is appreciated.

getting File ID from upload.

Hi,

code works brilliantly... I'm just suck on how to get the file ID when I upload a file can you point me in the right direction.

Thanks.

Not working with the file which has non-Ascii filename.

Traceback (most recent call last):
File "/root/py/vsmanu.py", line 15, in
uploaded_file_info = vs.upload_file(fullpath)
File "/usr/local/lib/python3.6/dist-packages/verystream/verystream.py", line 266, in upload_file
response_json = requests.post(upload_url, data=data, headers=headers).json()
File "/usr/local/lib/python3.6/dist-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.6/json/init.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 340, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/json/decoder.py", line 358, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The problem only occurs when file has non-Ascii filename.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.