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

Invalid historical link and UnhandledPromiseRejectionWarning: Error: Error: Request failed with status code 403 #9

Open
YIN-Renlong opened this issue Dec 25, 2021 · 4 comments

Comments

@YIN-Renlong
Copy link

This request is a continuation of the last question #8

Hi, I would like to let you know that even if the format is used correctly, it will still show the same error.

The command I used is potd -N -d 2020-09-04.

Besides, in the history file used last year, I saw that NG has changed the URL of the image file, and the link used before seems to be no longer valid more, such as:

https://www.nationalgeographic.com/content/dam/photography/photos/000/936/93627.jpg
https://www.nationalgeographic.com/content/dam/photography/photos/000/936/93626.jpg
https://www.nationalgeographic.com/content/dam/photography/photos/000/936/93625.jpg
https://www.nationalgeographic.com/content/dam/photography/photos/000/936/93621.jpg
...

Any idea to fix it? Thanks

@berkerol
Copy link
Owner

Thanks for your interest. It seems that National Geographic removed URL https://www.nationalgeographic.com/photography/photo-of-the-day/_jcr_content/.gallery.json

I couldn't find an easy fix that restores full functionality for now.
Easiest thing to do is download page https://www.nationalgeographic.com/photo-of-the-day/ and do some search in there but that would prevent usage of date and random parameters because we can only access today's photo.

I will leave this issue open until I find something.

@YIN-Renlong
Copy link
Author

Hi, thank you for your quick reply.

In fact, when accessing the link https://www.nationalgeographic.com/photo-of-the-day/, NG currently requires mandatory login. Will this affect the acquisition of pictures?

Here is the screenshot:

image

Thanks for your interest. It seems that National Geographic removed URL https://www.nationalgeographic.com/photography/photo-of-the-day/_jcr_content/.gallery.json

I couldn't find an easy fix that restores full functionality for now. Easiest thing to do is download page https://www.nationalgeographic.com/photo-of-the-day/ and do some search in there but that would prevent usage of date and random parameters because we can only access today's photo.

I will leave this issue open until I find something.

@YIN-Renlong
Copy link
Author

Hi there, how are you? I hope you are doing well.

Here I would like to mention an update of NG's Photo of the Day, which has opened up non-registered access. And the link follows the following format. Is there a possible update to the script to accommodate the new format? thanks

https://i.natgeofe.com/n/306026f1-f2d0-431e-9c48-a3e50eafdd03/NationalGeographic_516473.jpg
https://i.natgeofe.com/n/fa090a9c-2b30-45e5-800e-df09c8a5eb7b/NationalGeographic_1560599.jpg

@andrescirulo
Copy link

Hi, I think i figured it out... it's not pretty and I don't know how long will it work.
These are the steps i had to take:

  1. Convert the date to epoch time in milliseconds (To take into account all the day I set the time to 23:59:59). I think the minimum date is 2009-02-01
    Example: 2022-01-01 23:59 -> 1641081599000
  2. That value goes at the end of the string "DYNA_0#ID:DRN|drn:src:natgeo:unison::prod:692291a0-0712-4edd-800c-084789a64c4c#SORT:originalPublishedDate|"
    Example: "DYNA_0#ID:DRN|drn:src:natgeo:unison::prod:692291a0-0712-4edd-800c-084789a64c4c#SORT:originalPublishedDate|1641081599000"
  3. Convert that to Base64
    Example: RFlOQV8wI0lEOkRSTnxkcm46c3JjOm5hdGdlbzp1bmlzb246OnByb2Q6NjkyMjkxYTAtMDcxMi00ZWRkLTgwMGMtMDg0Nzg5YTY0YzRjI1NPUlQ6b3JpZ2luYWxQdWJsaXNoZWREYXRlfDE2NDEwODE1OTkwMDA=
  4. Encode it as URL
    Example: RFlOQV8wI0lEOkRSTnxkcm46c3JjOm5hdGdlbzp1bmlzb246OnByb2Q6NjkyMjkxYTAtMDcxMi00ZWRkLTgwMGMtMDg0Nzg5YTY0YzRjI1NPUlQ6b3JpZ2luYWxQdWJsaXNoZWREYXRlfDE2NDEwODE1OTkwMDA%3D
  5. Do a GET request to "https://www.nationalgeographic.com/proxy/mediaspotlight?id=drn%3Asrc%3Anatgeo%3Aunison%3A%3Aprod%3A7671ccb9-e964-4c97-99dd-576901e74ed0&_xhr=pageContent&cursor=[CURSOR]" replacing [CURSOR] with the calculated value
    Example: https://www.nationalgeographic.com/proxy/mediaspotlight?id=drn%3Asrc%3Anatgeo%3Aunison%3A%3Aprod%3A7671ccb9-e964-4c97-99dd-576901e74ed0&_xhr=pageContent&cursor=RFlOQV8wI0lEOkRSTnxkcm46c3JjOm5hdGdlbzp1bmlzb246OnByb2Q6NjkyMjkxYTAtMDcxMi00ZWRkLTgwMGMtMDg0Nzg5YTY0YzRjI1NPUlQ6b3JpZ2luYWxQdWJsaXNoZWREYXRlfDE2NDEwODE1OTkwMDA%3D
  6. That gives you a json that has an array "media". Each element is an image, the first one is the closest to the date we picked in step 1.
  7. From that element you can get many things. Mainly, the url of the image is in the "src" property of the "img" object. Also you can get versions of the image in differents aspect ratios if you use the values in the array "crps" of "img".
    Example:
    {
    ......
    "media": [
    {
    "img": {
    "crps": [
    {
    "nm": "raw",
    "aspRto": 1.499267935578331,
    "url": "https://i.natgeofe.com/n/b0c8fcf8-2288-40f9-a4af-7404d74d7b38/NationalGeographic_2754468.jpg"
    },
    ......
    ],
    "src": "https://i.natgeofe.com/n/b0c8fcf8-2288-40f9-a4af-7404d74d7b38/NationalGeographic_2754468.jpg",
    .......
    },
    .......
    },
    ........
    ],
    .......
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants