Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Videos do not delete from sync module local storage #970

Open
apach3guy opened this issue Jul 25, 2024 · 4 comments
Open

Videos do not delete from sync module local storage #970

apach3guy opened this issue Jul 25, 2024 · 4 comments
Labels
bug There is an issue causing unexpected results help-wanted Assistance required due to lack of resources for testing or complexity

Comments

@apach3guy
Copy link

I recently posted about a script to delete old videos from the local storage on the sync module and I updated my blinkpy to the latest development version. The script appeared to be working (i.e., no errors were generated) but the local storage continued to fill up. Looking in the blink app, I confirmed that old videos (currently defined in my script as older than 5 days) are still showing up, demonstrating that they have not been deleted.

Below is my code and the output.

#!/usr/bin/env python3.9

import asyncio
from datetime import datetime, timedelta
from sortedcontainers import SortedSet
from blinkpy.helpers.util import json_load
from blinkpy.blinkpy import Blink, BlinkSyncModule
from blinkpy.auth import Auth
from aiohttp import ClientSession

async def start(session: ClientSession):
    """Startup blink app."""
    blink = Blink(session=session)
    blink.auth = Auth(await json_load("/home/pi/utils/blink.auth"), session=session)
    await blink.start()
    return blink

async def main():
    session = ClientSession()
    try:
        blink = await start(session)
        await blink.refresh()
        my_sync: BlinkSyncModule = blink.sync["Laguna"]
        await my_sync.refresh()
        if my_sync.local_storage and my_sync.local_storage_manifest_ready:
            manifest = my_sync._local_storage["manifest"]
            # print(f"Manifest {manifest}")
            for item in reversed(manifest):
                current_date = datetime.now(item.created_at.tzinfo)
                time_difference = current_date - item.created_at

                if time_difference > timedelta(days=5):
                    try:
                        await item.delete_video(blink)
                        await asyncio.sleep(2)
                        print(f"Success deleting video {item.id}")
                    except Exception as e:
                        print(f"Error deleting video {item.id}: {e}")
        else:
            print("Manifest not ready")
    finally:
        await session.close()

asyncio.run(main())
Success deleting video 1165876146
Success deleting video 2357212475
Success deleting video 3389086544
Success deleting video 4061158032
Success deleting video 4198518603
Success deleting video 3066931222
Success deleting video 2397370008

Note that output is truncated for brevity.

@fronzbot
Copy link
Owner

Thanks for reporting!

Seems like there's at least two problems here:

  1. Videos not being deleted (might be the wrong endpoint)
  2. A log message stating that the deletion was successful without actually checking that it's gone

The second one is an easy fix but doesn't address the issue. The first one is more difficult as I do not have local storage in my setup so have no way to test so will need to rely on other to contribute here. I'll pin this issue though

@fronzbot fronzbot added bug There is an issue causing unexpected results help-wanted Assistance required due to lack of resources for testing or complexity labels Jul 25, 2024
@fronzbot fronzbot pinned this issue Jul 25, 2024
@apach3guy
Copy link
Author

Right, my code assumes that an exception would be thrown if there was a problem deleting the video. However, no exception is thrown so it assumes the video was deleted.

@fronzbot
Copy link
Owner

Gotcha. To check for a success/fail, the delete method will return "True" if the deletion worked and "False" if it failed. However we're only looking at the request response. It's possible a "True" is being returned even if the video is not deleted. If you get a chance, it's worth checking to make sure delete_video returns False

async def delete_video(self, blink, max_retries=4) -> bool:

@mmraz3
Copy link

mmraz3 commented Aug 4, 2024

I am not a Python developer, but I am using your repo and README to figure out what the URLs are for interacting with the sync module. To upload a video from the sync module, I am posting to
/api/v1/accounts/{account-id}/networks/{network-id}/sync_modules/{sync-module-id}/local_storage/manifest/{manifest-id}/clip/request/{clip-id}

To download that video, I do a GET to the same URL. If I followed the Python code correctly, it looks like the URL it is using to delete a video is the same as above except that "request" becomes "delete", so:

/api/v1/accounts/{account-id}/networks/{network-id}/sync_modules/{sync-module-id}/local_storage/manifest/{manifest-id}/clip/delete/{clip-id}

And it is a POST to that URL. Is that correct? The behavior I am seeing is that the call returns 200, with a body that contains a single field, "id". I can repeat the identical call. I continue to get a 200 back each time I call it, and the id is different each time. I still see the video when I go into the Blink app, so the video is not being deleted. In fact, I see that if I change the clip id to any random number, I get the same behavior, so something is definitely wrong with the URL I am using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug There is an issue causing unexpected results help-wanted Assistance required due to lack of resources for testing or complexity
Projects
None yet
Development

No branches or pull requests

3 participants