Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PageMetaData.cs
4
5namespace Waher.Content.Html
6{
14 public class PageMetaData
15 {
16 private ImageInformation[] images = null;
17 private AudioInformation[] audio = null;
18 private VideoInformation[] video = null;
19 private string[] localeAlternate = null;
20 private string title = null;
21 private string type = null;
22 private string url = null;
23 private string description = null;
24 private string determiner = null;
25 private string locale = null;
26 private string siteName = null;
27
35 public PageMetaData()
36 {
37 }
38
47 {
52 ImageInformation LastImage = null;
53 AudioInformation LastAudio = null;
54 VideoInformation LastVideo = null;
55 string Name;
56 string Value;
57
58 if (!(Doc.Meta is null))
59 {
60 foreach (Meta Meta in Doc.Meta)
61 {
63 continue;
64
65 Name = Value = null;
66
68 {
69 foreach (HtmlAttribute Attr in Meta.Attributes)
70 {
71 switch (Attr.FullName)
72 {
73 case "property":
74 case "name":
75 Name = Attr.Value;
76 break;
77
78 case "content":
79 Value = Attr.Value;
80 break;
81 }
82 }
83 }
84
85 if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Value))
86 continue;
87
88 switch (Name)
89 {
90 case "og:title":
91 this.title = Value;
92 break;
93
94 case "twitter:title":
95 if (string.IsNullOrEmpty(this.title))
96 this.title = Value;
97 break;
98
99 case "og:type":
100 this.type = Value;
101 break;
102
103 case "twitter:card":
104 if (string.IsNullOrEmpty(this.type))
105 this.type = Value;
106 break;
107
108 case "og:url":
109 this.url = Value;
110 break;
111
112 case "og:image":
113 case "og:image:url":
114 case "twitter:image":
115 if (!(Images is null))
116 {
117 LastImage = null;
118
119 foreach (ImageInformation Image in Images)
120 {
121 if (Image.Url == Value)
122 {
123 LastImage = Image;
124 break;
125 }
126 }
127
128 if (!(LastImage is null))
129 break;
130 }
131
132 LastImage = new ImageInformation()
133 {
134 Url = Value
135 };
136
137 if (Images is null)
139
140 Images.Add(LastImage);
141 break;
142
143 case "og:image:secure_url":
144 if (!(LastImage is null))
145 LastImage.SecureUrl = Value;
146 break;
147
148 case "og:image:type":
149 if (!(LastImage is null))
150 LastImage.ContentType = Value;
151 break;
152
153 case "og:image:width":
154 if (!(LastImage is null) && int.TryParse(Value, out int i))
155 LastImage.Width = i;
156 break;
157
158 case "og:image:height":
159 if (!(LastImage is null) && int.TryParse(Value, out i))
160 LastImage.Height = i;
161 break;
162
163 case "og:image:alt":
164 case "twitter:image:alt":
165 if (!(LastImage is null))
166 LastImage.Description = Value;
167 break;
168
169 case "og:audio":
170 LastAudio = new AudioInformation()
171 {
172 Url = Value
173 };
174
175 if (Audio is null)
177
178 Audio.Add(LastAudio);
179 break;
180
181 case "og:audio:secure_url":
182 if (!(LastAudio is null))
183 LastAudio.SecureUrl = Value;
184 break;
185
186 case "og:audio:type":
187 if (!(LastAudio is null))
188 LastAudio.ContentType = Value;
189 break;
190
191 case "og:description":
192 this.description = Value;
193 break;
194
195 case "twitter:description":
196 case "description":
197 if (string.IsNullOrEmpty(this.description))
198 this.description = Value;
199 break;
200
201 case "og:determiner":
202 this.determiner = Value;
203 break;
204
205 case "og:locale":
206 this.locale = Value;
207 break;
208
209 case "og:locale:alternate":
210 if (LocaleAlternate is null)
212
213 LocaleAlternate.Add(Value);
214 break;
215
216 case "og:site_name":
217 this.siteName = Value;
218 break;
219
220 case "og:video":
221 LastVideo = new VideoInformation()
222 {
223 Url = Value
224 };
225
226 if (Video is null)
228
229 Video.Add(LastVideo);
230 break;
231
232 case "og:video:secure_url":
233 if (!(LastVideo is null))
234 LastVideo.SecureUrl = Value;
235 break;
236
237 case "og:video:type":
238 if (!(LastVideo is null))
239 LastVideo.ContentType = Value;
240 break;
241
242 case "og:video:width":
243 if (!(LastVideo is null) && int.TryParse(Value, out i))
244 LastVideo.Width = i;
245 break;
246
247 case "og:video:height":
248 if (!(LastVideo is null) && int.TryParse(Value, out i))
249 LastVideo.Height = i;
250 break;
251 }
252 }
253 }
254
255 if (string.IsNullOrEmpty(this.title) && !(Doc.Title is null))
256 this.title = Doc.Title.InnerText.Trim();
257
258 this.images = Images?.ToArray();
259 this.audio = Audio?.ToArray();
260 this.video = Video?.ToArray();
261 this.localeAlternate = LocaleAlternate?.ToArray();
262 }
263
268 {
269 get => this.images;
270 set => this.images = value;
271 }
272
277 {
278 get => this.audio;
279 set => this.audio = value;
280 }
281
286 {
287 get => this.video;
288 set => this.video = value;
289 }
290
294 public string[] LocaleAlternate
295 {
296 get => this.localeAlternate;
297 set => this.localeAlternate = value;
298 }
299
303 public string Title
304 {
305 get => this.title;
306 set => this.title = value;
307 }
308
312 public string Type
313 {
314 get => this.type;
315 set => this.type = value;
316 }
317
321 public string Url
322 {
323 get => this.url;
324 set => this.url = value;
325 }
326
330 public string Description
331 {
332 get => this.description;
333 set => this.description = value;
334 }
335
339 public string Determiner
340 {
341 get => this.determiner;
342 set => this.determiner = value;
343 }
344
348 public string Locale
349 {
350 get => this.locale;
351 set => this.locale = value;
352 }
353
357 public string SiteName
358 {
359 get => this.siteName;
360 set => this.siteName = value;
361 }
362
364 public override bool Equals(object obj)
365 {
367 int i, c;
368
369 if ((this is null) ^ (Meta is null))
370 return false;
371
372 if (this is null)
373 return true;
374
375 if (this.title != Meta.title ||
376 this.type != Meta.type ||
377 this.url != Meta.url ||
378 this.description != Meta.description ||
379 this.determiner != Meta.determiner ||
380 this.locale != Meta.locale ||
381 this.siteName != Meta.siteName)
382 {
383 return false;
384 }
385
386 if ((this.localeAlternate is null) ^ (Meta.localeAlternate is null))
387 return false;
388
389 if (!(this.localeAlternate is null))
390 {
391 if ((c = this.localeAlternate.Length) != Meta.localeAlternate.Length)
392 return false;
393
394 for (i = 0; i < c; i++)
395 {
396 if (this.localeAlternate[i] != Meta.localeAlternate[i])
397 return false;
398 }
399 }
400
401 if ((this.images is null) ^ (Meta.images is null))
402 return false;
403
404 if (!(this.images is null))
405 {
406 if ((c = this.images.Length) != Meta.images.Length)
407 return false;
408
409 for (i = 0; i < c; i++)
410 {
411 if (!this.images[i].Equals(Meta.images[i]))
412 return false;
413 }
414 }
415
416 if ((this.audio is null) ^ (Meta.audio is null))
417 return false;
418
419 if (!(this.audio is null))
420 {
421 if ((c = this.audio.Length) != Meta.audio.Length)
422 return false;
423
424 for (i = 0; i < c; i++)
425 {
426 if (!this.audio[i].Equals(Meta.audio[i]))
427 return false;
428 }
429 }
430
431 if ((this.video is null) ^ (Meta.video is null))
432 return false;
433
434 if (!(this.video is null))
435 {
436 if ((c = this.video.Length) != Meta.video.Length)
437 return false;
438
439 for (i = 0; i < c; i++)
440 {
441 if (!this.video[i].Equals(Meta.video[i]))
442 return false;
443 }
444 }
445
446 return true;
447 }
448
450 public override int GetHashCode()
451 {
452 int Result = 0;
453
454 if (!(this.title is null))
455 Result = this.title.GetHashCode();
456
457 if (!(this.type is null))
458 Result ^= Result << 5 ^ this.type.GetHashCode();
459
460 if (!(this.url is null))
461 Result ^= Result << 5 ^ this.url.GetHashCode();
462
463 if (!(this.description is null))
464 Result ^= Result << 5 ^ this.description.GetHashCode();
465
466 if (!(this.determiner is null))
467 Result ^= Result << 5 ^ this.determiner.GetHashCode();
468
469 if (!(this.locale is null))
470 Result ^= Result << 5 ^ this.locale.GetHashCode();
471
472 if (!(this.siteName is null))
473 Result ^= Result << 5 ^ this.siteName.GetHashCode();
474
475 if (!(this.localeAlternate is null))
476 {
477 foreach (string s in this.localeAlternate)
478 Result ^= Result << 5 ^ s.GetHashCode();
479 }
480
481 if (!(this.images is null))
482 {
483 foreach (ImageInformation Obj in this.images)
484 Result ^= Result << 5 ^ Obj.GetHashCode();
485 }
486
487 if (!(this.audio is null))
488 {
489 foreach (AudioInformation Obj in this.audio)
490 Result ^= Result << 5 ^ Obj.GetHashCode();
491 }
492
493 if (!(this.video is null))
494 {
495 foreach (VideoInformation Obj in this.video)
496 Result ^= Result << 5 ^ Obj.GetHashCode();
497 }
498
499 return Result;
500 }
501
502 }
503}
string FullName
Attribute full name (including prefix).
string Value
Attribute value.
Title Title
First TITLE element of document, if found, null otherwise.
Definition: HtmlDocument.cs:97
IEnumerable< Meta > Meta
META elements found in document, or null if none found.
IEnumerable< HtmlAttribute > Attributes
Attributes, or null if none.
Definition: HtmlElement.cs:120
bool HasAttributes
If the element has attributes.
Definition: HtmlElement.cs:110
Audio information, as defined by the Open Graph protocol.
Image information, as defined by the Open Graph protocol.
Video information, as defined by the Open Graph protocol.
Contains meta-data about a page.
Definition: PageMetaData.cs:15
PageMetaData()
Contains meta-data about a page.
Definition: PageMetaData.cs:35
ImageInformation[] Images
Image representing page.
string Description
A description of the page.
override bool Equals(object obj)
PageMetaData(HtmlDocument Doc)
Contains meta-data about a page.
Definition: PageMetaData.cs:46
string Determiner
A word that appears before the title.
string Url
Canonical URL of page.
string Locale
Locale of information.
string SiteName
Name of web site publishing page
string[] LocaleAlternate
Alternate locales
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54