@@ -50,6 +50,7 @@ public Media[] newArray(int i) {
50
50
protected int width ;
51
51
protected int height ;
52
52
protected String license ;
53
+ protected String licenseUrl ;
53
54
protected String creator ;
54
55
protected ArrayList <String > categories ; // as loaded at runtime?
55
56
protected boolean requestedDeletion ;
@@ -332,12 +333,70 @@ public String getLicense() {
332
333
return license ;
333
334
}
334
335
336
+ /**
337
+ * Creating Media object from MWQueryPage.
338
+ * Earlier only basic details were set for the media object but going forward,
339
+ * a full media object(with categories, descriptions, coordinates etc) can be constructed using this method
340
+ *
341
+ * @param page response from the API
342
+ * @return Media object
343
+ */
344
+ @ Nullable
345
+ public static Media from (MwQueryPage page ) {
346
+ ImageInfo imageInfo = page .imageInfo ();
347
+ if (imageInfo == null ) {
348
+ return null ;
349
+ }
350
+ ExtMetadata metadata = imageInfo .getMetadata ();
351
+ if (metadata == null ) {
352
+ return new Media (null , imageInfo .getOriginalUrl (),
353
+ page .title (), "" , 0 , null , null , null );
354
+ }
355
+
356
+ Media media = new Media (null ,
357
+ imageInfo .getOriginalUrl (),
358
+ page .title (),
359
+ "" ,
360
+ 0 ,
361
+ DateUtils .getDateFromString (metadata .dateTimeOriginal ().value ()),
362
+ DateUtils .getDateFromString (metadata .dateTime ().value ()),
363
+ StringUtils .getParsedStringFromHtml (metadata .artist ().value ())
364
+ );
365
+
366
+ String language = Locale .getDefault ().getLanguage ();
367
+ if (StringUtils .isNullOrWhiteSpace (language )) {
368
+ language = "default" ;
369
+ }
370
+
371
+ media .setDescriptions (Collections .singletonMap (language , metadata .imageDescription ().value ()));
372
+ media .setCategories (MediaDataExtractorUtil .extractCategoriesFromList (metadata .categories ().value ()));
373
+ String latitude = metadata .gpsLatitude ().value ();
374
+ String longitude = metadata .gpsLongitude ().value ();
375
+
376
+ if (!StringUtils .isNullOrWhiteSpace (latitude ) && !StringUtils .isNullOrWhiteSpace (longitude )) {
377
+ LatLng latLng = new LatLng (Double .parseDouble (latitude ), Double .parseDouble (longitude ), 0 );
378
+ media .setCoordinates (latLng );
379
+ }
380
+
381
+ media .setLicenseInformation (metadata .licenseShortName ().value (), metadata .licenseUrl ().value ());
382
+ return media ;
383
+ }
384
+
385
+ public String getLicenseUrl () {
386
+ return licenseUrl ;
387
+ }
388
+
335
389
/**
336
390
* Sets the license name of the file.
337
391
* @param license license name as a String
338
392
*/
339
- public void setLicense (String license ) {
393
+ public void setLicenseInformation (String license , String licenseUrl ) {
340
394
this .license = license ;
395
+
396
+ if (!licenseUrl .startsWith ("http://" ) && !licenseUrl .startsWith ("https://" )) {
397
+ licenseUrl = "https://" + licenseUrl ;
398
+ }
399
+ this .licenseUrl = licenseUrl ;
341
400
}
342
401
343
402
/**
@@ -457,50 +516,11 @@ public boolean getRequestedDeletion(){
457
516
}
458
517
459
518
/**
460
- * Creating Media object from MWQueryPage.
461
- * Earlier only basic details were set for the media object but going forward,
462
- * a full media object(with categories, descriptions, coordinates etc) can be constructed using this method
519
+ * Sets the license name of the file.
463
520
*
464
- * @param page response from the API
465
- * @return Media object
521
+ * @param license license name as a String
466
522
*/
467
- @ Nullable
468
- public static Media from (MwQueryPage page ) {
469
- ImageInfo imageInfo = page .imageInfo ();
470
- if (imageInfo == null ) {
471
- return null ;
472
- }
473
- ExtMetadata metadata = imageInfo .getMetadata ();
474
- if (metadata == null ) {
475
- return new Media (null , imageInfo .getOriginalUrl (),
476
- page .title (), "" , 0 , null , null , null );
477
- }
478
-
479
- Media media = new Media (null ,
480
- imageInfo .getOriginalUrl (),
481
- page .title (),
482
- "" ,
483
- 0 ,
484
- DateUtils .getDateFromString (metadata .dateTimeOriginal ().value ()),
485
- DateUtils .getDateFromString (metadata .dateTime ().value ()),
486
- StringUtils .getParsedStringFromHtml (metadata .artist ().value ())
487
- );
488
-
489
- String language = Locale .getDefault ().getLanguage ();
490
- if (StringUtils .isNullOrWhiteSpace (language )) {
491
- language = "default" ;
492
- }
493
- media .setDescriptions (Collections .singletonMap (language , metadata .imageDescription ().value ()));
494
- media .setCategories (MediaDataExtractorUtil .extractCategoriesFromList (metadata .categories ().value ()));
495
- String latitude = metadata .gpsLatitude ().value ();
496
- String longitude = metadata .gpsLongitude ().value ();
497
-
498
- if (!StringUtils .isNullOrWhiteSpace (latitude ) && !StringUtils .isNullOrWhiteSpace (longitude )) {
499
- LatLng latLng = new LatLng (Double .parseDouble (latitude ), Double .parseDouble (longitude ), 0 );
500
- media .setCoordinates (latLng );
501
- }
502
-
503
- media .setLicense (metadata .licenseShortName ().value ());
504
- return media ;
523
+ public void setLicense (String license ) {
524
+ this .license = license ;
505
525
}
506
526
}
0 commit comments