nayrk / Blink

Amazon Blink Video Downloader
60 stars 23 forks source link

Thumbnail not downloading - Fix for "Invoke-RestMethod : The remote name could not be resolved...." error #31

Open MrKnowItSum opened 1 year ago

MrKnowItSum commented 1 year ago

Greetings All, For those who are getting the subject error message while attempting to download thumbnails, I was able to sniff out the new file path for Blink thumbnails (at least for my Blink account). Fixed Blinkvideodownloader.ps1 errors by replacing line 159:

$thumbURL = 'https://rest-'+ $region +'.immedia-semi.com' + $cameraThumbnail + ".jpg"

with

$thumbURL = 'https://rest-' + $region + '.immedia-semi.com' + '/api/v3/media/accounts/' + $accountID + '/networks/' + $network_id + '/xt2/' + $cameraID + '/thumbnail/thumbnail.jpg'

Let me know if it worked for you.

Modela29 commented 1 year ago

Tried using new data line 159. No luck. Here are error messages.


Downloading thumbnail for Living Room camera in Home. Invoke-RestMethod : The remote server returned an error: (404) Not Found. At D:\Dell Windows 10\Blink\Blinkupd.ps1:165 char:5

Downloading thumbnail for Garage camera in Home. Invoke-RestMethod : The remote server returned an error: (404) Not Found. At D:\Dell Windows 10\Blink\Blinkupd.ps1:165 char:5

Downloading thumbnail for Front Door camera in Home. Invoke-RestMethod : The remote server returned an error: (404) Not Found. At D:\Dell Windows 10\Blink\Blinkupd.ps1:165 char:5

Downloading thumbnail for Sunroom camera in Home. Invoke-RestMethod : The remote server returned an error: (404) Not Found. At D:\Dell Windows 10\Blink\Blinkupd.ps1:165 char:5

All new videos and thumbnails downloaded to D:\Dell Windows 10\Blink\Blink\ Sleeping for 30 minutes before next run...


Not an expert in Powershell. Any clues?

MrKnowItSum commented 1 year ago

Hmm, wonder if it has something to do with the camera type, XT (older model) or XT2 (newer model). Try changing '/xt2' to '/xt' and see if that works.

Modela29 commented 1 year ago

You are correct, the cameras type are older XT models. Changed from XT2 to XT in line 159. I get the same error.

Maybe I am out of luck using the older XT models.

MrKnowItSum commented 1 year ago

Try inserting the following code at line 129:

$uri = 'https://rest-'+ $region + '.immedia-semi.com' + '/api/v3/accounts/' + $accountID + '/homescreen' $homescreen = Invoke-RestMethod -UseBasicParsing $uri -Method Get -Headers $headers echo 'My thumbnail file paths:' $homescreen.cameras.thumbnail

If it works on your Blink account like it did on mine, it should return a list of all your camera thumbnail file paths. Then you can use that information to modify the line 159 that I initially posted, to get your thumbnails.

Modela29 commented 1 year ago

MrKnowItSum - thank you for all your help. I place the above code at line 129, This was the results:


/api/v3/media/accounts/00000/networks/00000/white/267700/thumbnail/thumbnail.jpg?ts=1665346493&ext= /api/v3/media/accounts/00000/networks/00000/white/272574/thumbnail/thumbnail.jpg?ts=1665321705&ext= /api/v3/media/accounts/00000/networks/00000/catalina/608493/thumbnail/thumbnail.jpg?ts=1665321742&ext= /api/v3/media/accounts/00000/networks/00000/xt/1073578/thumbnail/thumbnail.jpg?ts=1691676535&ext=


Again, I am no PowerShell expert. (Visual Basic is the best I can do!) Not sure want I am seeing and what not sure what to do with line 159.

Thanks for all your effort.

MrKnowItSum commented 1 year ago

Hmm, looks like your thumbnails are stored in different file paths, so it will take a bit more than a few code mods to make it work for you (and everyone else in general).

BTW, edit your previous post and replace the numbers after "/account/" and "/networks/ with "00000" from the output you posted, for security reasons.

Modela29 commented 1 year ago

Updated: Thanks

Modela29 commented 1 year ago

MrKnowItSum - I would like to thank you for your effort. I looked closer at the data that your line 129 produced and I did see how my 4 thumbnails are located in 3 different directories for the same account number. Not sure why Blink software designers would do this? I agree that this would quite a programming problem effort if other users have the same problems.

sutty550e commented 1 year ago

Bear in mind each different type of camera has different feature sets enabled, and configuration requirements. Separate folders for each type of camera could well make perfect sense for managing whether a given feature is supported/enabled or not. Note, the thumbnail folder is after the camera type folder, which means there may well be several subfolders of, for example, the XT2 folder, such as, "\configuation or \features, etc, or who knows what else, specific only to an XT2. Maybe it makes it easier to deal with permissions, and so on, because I'm pretty sure all cameras are dumb-ish, and all features could have been enabled on all cameras, being handled at the server. This was certainly the case, in the past, at around the time when the outdoor was first released, because at the time, I gave it a lot of thought.

One could argue that the thumbnails would always be treated the same, so could be in the same folder, but if they have to separate and isolate the camera types for other reasons, I suppose the thumbnail folder just went with the rest of the camera type sub folders.

MrKnowItSum commented 1 year ago

This issue in the current code is that the data in "$sync-unit.cameras" doesn't include (at least not that I could find) the camera type (e.g., xt, white, catalina, etc. ). In other words, there's no "$sync-unit.cameras.type". So the full thumbnail file path cannot be reconstructed using just that data. However, as seen from my previous code snipet, the home screen contains the full file paths to all the camera thumbnails, no need to reconstruct. Also, Blink may change the thumbnail file paths again in the future, like they have already done. So modified the code (see below) to extract the full thumbnail file paths from the home screen instead.
Caveot is that this code only captures thumbnails from those setups that only have one Blink sync module (which is likely the case for most users). Since I don't have a second sync module, don't have any insight into what that data looks like and therefore don't know what code additions/mods would need to be made in order to capture camera thumbnails from additional sync modules. Perhaps someone who has more than one sync module can update the code for that. Also note that I appended the timestamp to the end of the captured thumbnail's file name. Hey, I write the code, I can add whatever I like. ;-) Let me know how it works for you.

In the original code, delete lines 130 through 168, and replace with the following code:

    ###### Begin mrknowitsum code mods 8/15/2023 #######

#Get Blink homescreen display data
$uri = 'https://rest-'+ $region + '.immedia-semi.com' + '/api/v3/accounts/' + $accountID + '/homescreen'
$homescreen = Invoke-RestMethod -UseBasicParsing $uri -Method Get -Headers $headers

$networkName = $homescreen.networks.name    

foreach($camera_entry in $homescreen.cameras)
{
        $cameraName = $camera_entry.name

        # Create Blink Directory to store videos if it doesn't exist
        $path = $saveDirectory + "\Blink\" + $networkName + "\" + $cameraName.replace('/','-')
        if (-not (Test-Path $path)){
            $folder = New-Item  -ItemType Directory -Path $path
        }

        # Prepare to download camera thumbnail.
        $thumbURL = 'https://rest-'+ $region +'.immedia-semi.com' + $camera_entry.thumbnail.Split("?")[-2]

        $thumbPath = "$path\" + "thumbnail_" + $camera_entry.updated_at.replace(':','').replace('-','').split('+')[-2] + "-GMT" + ".jpg"

        # Download camera thumbnail.  Skip if already downloaded
        if (-not (Test-Path $thumbPath)){
            echo "Downloading thumbnail for $cameraName camera in $networkName."
            Invoke-RestMethod -UseBasicParsing $thumbURL -Method Get -Headers $headers -OutFile $thumbPath
        }
}

###### End mrknowitsum code mods 8/15/2023 #######
Modela29 commented 1 year ago

MrKnowItSum - It works great with my thumbnails. Everyone got download with a time stamp. Again, thanks again for all your effort.

stevekenney318 commented 1 year ago

In the original code, delete lines 130 through 168, and replace with the following code:

@MrKnowItSum

Hi, it's been a while since I looked at this ... is this to download the thumbnails that are shown on the app main screen ? I think I am using a different version of the program ...

Can you take a look at this version and let me know by code, not line number what I would need to change to get the app main screen thumbnails to download ?

Thanks, Steve

MrKnowItSum commented 1 year ago

Realized that the code mods I posted yesterday was an iteration prior to the one I intended to post, so just updated it. It still works the same as the one I posted earlier. The difference is that I had fixed the code comments and changed some variable names to make it easier for someone viewing the code to understand what was happening. Also, on the timestamp that I appended to the end of the thumbnail file, I also appended the additional characters"-GMT" to clarify how the timestamp is stored by Blink.

MrKnowItSum commented 1 year ago

In response to stevekenney318's questions: Yes, this is to download the thumbnails that are shown on the app main screen. The currenty posted code stopped working for me a while ago. So fixed it for my own use, and shared my code mods here to aid others who have the same issue. Since I have resolved my blinkvideodownloader issue, I'm done working on it (unless it breaks on me again in the future!).

The code changes that I made are to the currently posted code (Author: Nayrk, Date: 12/28/2018, Last Updated: 02/03/2021), which you can find by clicking on the "Code" link on the upper left corner of this web page, then clicking on the link "BlinkVideoDownloader.ps1" (or go there directly at https://github.com/nayrk/Blink/blob/master/BlinkVideoDownloader.ps1). The code lines are displayed along with the code. Besides the aforermentioned posted code, I don't know anything about any other version of code.

stevekenney318 commented 1 year ago

I also appended the additional characters"-GMT"

Can you make this a variable, as I would rather the timestamp be local time ?

MrKnowItSum commented 1 year ago

Did the code mods work for you? Feel free to customize the code however you like.

stevekenney318 commented 1 year ago

Did the code mods work for you?

Yes, I did get it to work. Thank you.

As I went back through some history, I found that there were a couple of versions of the program that were included as zip files in some comments. But I was able to include your update into the version I was using ( the latest from below, and other personal changes I made) and all is working well now !

These are a couple of the comments where there were zip files included ...

Unfortunately , it doesn't seem like this project is being actively maintained.

Thanks again for your help , Steve

petunia101 commented 1 year ago

MrKnowItSum,

re: your original post image

I just wanted to let you know that your line 159 revision fix worked for me (i.e. thumbnails now load). I have XT2 cameras with 2 sync modules.

Thanks for your help :) Janette

MrKnowItSum commented 1 year ago

Wonderful! Thanks for the feedback.

tyuhas commented 1 year ago

I took what @MrKnowItSum discovered/designed and added on to it. Around line 155 is my attempt at generalizing the camera model. I only have the three models (my Outdoor and Indoor use the same FW) but this works for me. I don't see why it couldn't be expanded to cover more camera models.

I attached the entire script here as a text file and it should directly work as long as you have the same models I have :-)

Uncomment line 153 to get a dump of values or echo $cameraFW to see what FW version your camera has

BlinkVideoDownloader.txt

stevekenney318 commented 1 year ago

tyuhas

Thanks !

AeonEternum commented 2 months ago

I have a Blink Mini camera. What changes do I need to do in order to make it work?

Thanks!

Cheers, Aeon