ageof / mydlink-api-python Goto Github PK
View Code? Open in Web Editor NEWMyDlink Cloud Python API
License: GNU General Public License v3.0
MyDlink Cloud Python API
License: GNU General Public License v3.0
Hi,
Thank you for your great code.
This is nice but I wanted to get snapshot.
So I tried to post https://mp-eu-openapi.auto.mydlink.com/v2/device/live/snapshot?access_token=<TOKEN> with this kind payload {data: {mydlink_id: "<MYDLINKID>", uid: 0, idx: 0, size: 2}} but What I got was 400 Error says "Client doesnt have privilege."
Do you know the way to get snapshot? if you know that, Can you add this function?
I'm thinking there is no way to do that. I guess..
Anyway, thank you for your code. I learned a lot :-)
Are you planning to implement more functions such as retrieving live video feed from cameras? This could be a potential Integration in Home Assistant.
Let me know how can I help with it please.
You can close this issue, I did not know how to contact you :)
I'm trying to integrate the program in HomeAssistant but I'm not able to call the API from the configuration.yaml: could you kindly help provinding the code? Thank you
Good afternoon. I tried your library with this code:
from mydlink_api.mydlink import MyDlink
mydlink = MyDlink(email="my_mydlink_mail", password="my_dlink_password")
device_id = "camera_id"
device_list = mydlink_client.get_device_list()
print(device_list)
the following error occurred:>>> %Run dlink.py
Traceback (most recent call last):
File "/home/pi/Desktop/dlink.py", line 1, in
from mydlink_api.mydlink import MyDlink
File "/home/pi/.local/lib/python3.9/site-packages/mydlink_api/mydlink.py", line 163, in
device_details = mydlink_client.get_device_details(mydlink_id, mac_address)
File "/home/pi/.local/lib/python3.9/site-packages/mydlink_api/mydlink.py", line 64, in get_device_details
openapi=self.login_params.get('api_site')[0],
TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'str' object
This error also occurs when using other functions.
Thank you in advance for your reply
Hi!
I see that you used the API on https://api.auto.mydlink.com/. I want to use it for further development. Where did you find the documentation for that API? Can you send the source somehow?
P.S: Sorry for opening an "Issue" for this, I couldn't find any other way to contact you.
The login does not work. It gives an error.
I'm porting your client to PHP but i'm stuck on the /oauth/authorize2
call.
I get the error Wrong username/password combination
from dlink api.
My payload seems ok because dlink api would return Invalid field format.
or Error validating this request
if it wasn't..
I have double checked my login/password, i even changed it twice on the dlink website.
This is the url generated by my script :
https://api.auto.mydlink.com/oauth/authorize2?client_id=mydlinkuapandroid&redirect_uri=https%3A%2F%2Fmydlink.com&user_name=myemail%40gmail.com&password=MydlinkPassword&response_type=token×tamp=1647437120&uc_id=bd36a6c011f1287e&uc_name=Yo&sig=70f951989671a71259928cb1d8ad5e15
define('OAUTH2_CLIENT_ID', 'mydlinkuapandroid');
define('OAUTH2_CLIENT_SECRET', '5259311fa8cab90f09f2dc1e09d2d8ee');
define('OAUTH2_ANDROID_ID', 'bd36a6c011f1287e');
$params = [
'client_id' => OAUTH2_CLIENT_ID,
'redirect_uri' => 'https://mydlink.com',
'user_name' => '[email protected]',
'password' => 'MydlinkPassword',
'response_type' => 'token',
'timestamp' => time(),
'uc_id' => OAUTH2_ANDROID_ID,
'uc_name' => "Yo",
];
$build = http_build_query($params);
$build .= '&sig=' . md5('/oauth/authorize2?' . $build . OAUTH2_CLIENT_SECRET);
$url = 'https://api.auto.mydlink.com/oauth/authorize2?' . $build;
$headers = [];
$headers[] = 'User-Agent: Mozilla/5.0';
$headers[] = 'connection: Keep-Alive';
$headers[] = 'accept: */*';
$headers[] = 'x-md-lang: de';
$headers[] = 'x-md-app-ver: 02.00.01.75';
$headers[] = 'x-md-os-type: android';
$headers[] = 'x-md-os-version: 7.0';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$return = curl_exec($ch);
var_dump($return);
print curl_error($ch);
curl_close($ch);
I have been doing a bit of testing and I'm thinking the "oauth_secret" has changed, or the method for calculating a signature has changed.
Hi, thanks for the repo!
How can I connect to live view http://192.168.0.90:8088/live.m3u8? It asks for a username/password, but I've tried several combinations and nothing!
Hi, i've tried your example for downloading the video's, but i get this output and error message
Request 1 von 33
Request 1 von 33
Request 1 von 33
Request 1 von 33
Request 1 von 33
Request 1 von 33
Request 1 von 33
Request 1 von 33
Request 1 von 33
Traceback (most recent call last):
File "test.py", line 18, in
mydlink.get_mydlink_cloud_recordings(year=2021, month=5, day=3)
File "C:\Users\luc.A-D-E\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mydlink_api\mydlink.py", line 98, in get_mydlink_cloud_recordings
self.__get_mydlink_cloud_recordings_file(all_events_details_json)
File "C:\Users\luc.A-D-E\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mydlink_api\mydlink.py", line 130, in __get_mydlink_cloud_recordings_file
json_object['subs_uid'] = data['act'][0]['subs_uid']
IndexError: list index out of range
Hello,
i used the example code
import argparse
import logging
from mydlink_api.mydlink import MyDlink
if __name__ == "__main__":
logger = logging.getLogger(None)
logger.setLevel(logging.INFO)
parser = argparse.ArgumentParser(
description="API to Connect MyDlink Cloud Devices")
parser.add_argument('-e', '--email', dest='email', help='MyDlink email example [email protected]')
parser.add_argument('-p', '--password', dest='password', help='MyDlink password example Start123')
args = parser.parse_args()
mydlink = MyDlink(password=args.password, email=args.email, disable_unverified_https_warn=True)
device_list_json = mydlink.get_device_list()
device_info_json = mydlink.get_device_details(mac=device_list_json[0]['mac'],
mydlink_id=device_list_json[0]['mydlink_id'])
date_list = [2023, 4, 12]
events_list = mydlink.get_event_list_meta_infos(year=date_list[0], month=date_list[1], day=date_list[2])
print(events_list)
mydlink_event_recordings = mydlink.get_mydlink_cloud_recordings_urls(year=date_list[0], month=date_list[1],
day=date_list[2])
print(mydlink_event_recordings)
I only get the first two Links of Videos from that day... Is there a way to get all the Recordings from that day?
Also the feature to get images in an array does not seem to work.. If i just use your Examplecode i get the following error:
Traceback (most recent call last): File "/home/pi/bin/dlink/runner.py", line 30, in <module> cloud_img_list.append(mydlink.get_mydlink_cloud_img_url(mydlink_id=device_list_json[0]['mydlink_id'], File "/usr/local/lib/python3.9/dist-packages/mydlink_api/mydlink.py", line 154, in get_mydlink_cloud_img_url imagepath = response_content['data']['list'][0]['path'] IndexError: list index out of range
Hello,
I want to install your API for my DCS8300-LH camera, but i don't write pip install on my home assistant (pip command not found on terminal & SSH addon).
Can i have a solution for simply install ? like on HACS ?
Thanks !
Hello, thanks for your great work. Is it possible to change the State of Power Switches (DSP-w118)? Thanks for your reply
Alex
Hello and thanks for this good start for querying/setting data on Dlink cameras
I'm trying to modify the code to fetch the privacy settings and eventually set the PTZ. I was able to see which function was called by F12-ing the mydlink.com website and playing a little with controls.
First of all, I'm able to log in and get my camera standard info (device list and device info) with no problem thanks to the provided example. But when I call the control function I get a privilege error...
{'error': {'message': 'Client doesnt have privilege.', 'code': 31}}
I've found that to control and get the privacy settings and even play with PTZ, the entry point is
POST /v2/device/control?acces_token=ACCESSTOKEN
(note the v2
, if I put me
in place I get another same error {'error': {'message': 'Client doesnt have privilege.', 'code': 31, 'type': 'Device'}}
)
And then embed the JSON to the POST body to query the info
{"data":{"mydlink_id":"1234","uid":0,"idx":0,"ctrl_id":513}}
Or add a value to set the privacy
{"data": {"mydlink_id": "1234", "uid": 0, "idx": 0, "ctrl_id": 513, "value": {"value": 2}}}
Or PTZ
{"data": {"mydlink_id": "1234", "uid": 0, "idx": 0, "ctrl_id": 26, "value": {"p": 165, "t": 12, "z": 0}}}
Unfortuately I'm getting the error above, and not when I query the device list and info...
I'm SOOOO close of finding this, if you find anything that might help me a little thank you in advance!
Example of implementation of the get privacy function
def get_device_privacy(self, mydlink_id:str) -> json:
device_privacy_url = "https://{openapi}/v2/device/control?access_token={access_token}".format(
openapi=self.login_params.get('api_site')[0],
access_token=self.login_params.get('access_token')[0]
)
json_object = {}
json_object['mydlink_id'] = mydlink_id
json_object['uid'] = 0
json_object['idx'] = 0
json_object['ctrl_id'] = 513
json_object_final = {}
json_object_final['data'] = json_object
response = self.url_utils.get_request(url=device_privacy_url, type=self.url_utils.TYPE_POST,
input_json=json_object_final)
device_privacy_json = Url.parse(response.content.decode('utf8'))
print(device_privacy_json)
return device_privacy_json['data']
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.