Browse Source

leave out placeholder alt text from instagram

pull/87/head
Aaron Parecki 6 years ago
parent
commit
c5d417e87e
No known key found for this signature in database GPG Key ID: 276C2817346D6056
4 changed files with 335 additions and 3 deletions
  1. +6
    -2
      lib/XRay/Formats/Instagram.php
  2. +16
    -1
      tests/InstagramTest.php
  3. +312
    -0
      tests/data/www.instagram.com/p_Bq8U12UAcdq_
  4. +1
    -0
      tests/download-instagram-data.sh

+ 6
- 2
lib/XRay/Formats/Instagram.php View File

@ -72,6 +72,10 @@ class Instagram extends Format {
return self::parsePhotoFromData($http, $photoData, $url, $profile);
}
private static function altTextIsPlaceholder($text) {
return $text == 'No photo description available.';
}
private static function parsePhotoFromData($http, $photoData, $url, $profile=false) {
if(!$photoData)
@ -141,7 +145,7 @@ class Instagram extends Format {
foreach($photoData['edge_sidecar_to_children']['edges'] as $edge) {
$entry['photo'][] = $edge['node']['display_url'];
// Don't need to pull person-tags from here because the main parent object already has them.
if(isset($edge['node']['accessibility_caption'])) {
if(isset($edge['node']['accessibility_caption']) && $edge['node']['accessibility_caption'] && !self::altTextIsPlaceholder($edge['node']['accessibility_caption'])) {
$meta[$edge['node']['display_url']] = [
'alt' => $edge['node']['accessibility_caption']
];
@ -156,7 +160,7 @@ class Instagram extends Format {
elseif(array_key_exists('display_url', $photoData))
$entry['photo'] = [$photoData['display_url']];
if(isset($photoData['accessibility_caption']) && $photoData['accessibility_caption']) {
if(isset($photoData['accessibility_caption']) && $photoData['accessibility_caption'] && !self::altTextIsPlaceholder($photoData['accessibility_caption'])) {
$meta[$entry['photo'][0]] = [
'alt' => $photoData['accessibility_caption']
];

+ 16
- 1
tests/InstagramTest.php View File

@ -40,6 +40,7 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
$this->assertEquals('Aaron Parecki', $data['data']['author']['name']);
$this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/45aee453740a714bf408f8947f89da8e/5CCB4B8E/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['author']['photo']);
$this->assertArrayNotHasKey('meta', $data['data']); // make sure this does not include alt text (autogenerated placeholder from instagram)
}
public function testBGDpqNoiMJ0() {
@ -167,6 +168,7 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/8b1b2e6efa86a4856ec37a60f0fa77f5/5CC2D34D/t51.2885-15/e35/21909774_347707439021016_5237540582556958720_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['photo'][1]);
$this->assertArrayNotHasKey('video', $data['data']);
$this->assertEquals(2, count($data['data']['category']));
$this->assertArrayNotHasKey('meta', $data['data']);
}
public function testMixPhotosAndVideos() {
@ -264,7 +266,6 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
public function testInstagramMultiPhotoWithAltText() {
$url = 'https://www.instagram.com/p/BsdlOmLh_IX/';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
@ -278,4 +279,18 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('A large green "2" in a circle with a small pink "1" behind it', $data['data']['meta']['https://instagram.fsjc1-3.fna.fbcdn.net/vp/a6c93d8fcd5ad0e3b60f2ac0695eb34e/5CC3898E/t51.2885-15/e35/49663055_349750985612151_2949260446582336214_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net']['alt']);
}
public function testInstagramPhotoAutogeneratedAltText() {
$url = 'https://www.instagram.com/p/Bq8U12UAcdq/';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('instagram', $data['source-format']);
$this->assertEquals('Image may contain: one or more people and hat', $data['data']['meta']['https://instagram.fsjc1-3.fna.fbcdn.net/vp/7f8954f33de897c0c57656b798637f4c/5CC3DF9F/t51.2885-15/e35/45605085_1989380037822519_4707213851165118070_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net']['alt']);
}
}

+ 312
- 0
tests/data/www.instagram.com/p_Bq8U12UAcdq_
File diff suppressed because it is too large
View File


+ 1
- 0
tests/download-instagram-data.sh View File

@ -17,6 +17,7 @@ urls=(
'https://www.instagram.com/explore/locations/359000003/'
'https://www.instagram.com/p/BsdjKytBZyx/'
'https://www.instagram.com/p/BsdlOmLh_IX/'
'https://www.instagram.com/p/Bq8U12UAcdq/'
)
for url in ${urls[@]}; do

Loading…
Cancel
Save