1 // OpenTween - Client of Twitter
2 // Copyright (c) 2012 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
5 // This file is part of OpenTween.
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
23 using System.Collections.Generic;
25 using System.Net.Http;
27 using System.Threading;
28 using System.Threading.Tasks;
29 using OpenTween.Connection;
31 namespace OpenTween.Thumbnail
33 public class ThumbnailInfo : IEquatable<ThumbnailInfo>
35 /// <summary>サムネイルとして表示するメディアが掲載されている URL</summary>
37 /// 例えば Youtube のサムネイルの場合、動画そのものの URL ではなく
38 /// https://www.youtube.com/watch?v=****** 形式の URL が含まれる
40 public string MediaPageUrl { get; set; }
42 /// <summary>サムネイルとして表示する画像の URL</summary>
44 /// ここに含まれる URL は直接画像として表示可能である必要がある
46 public string ThumbnailImageUrl { get; set; }
48 /// <summary>最も高解像度な画像の URL</summary>
50 /// サムネイルとしては不適だが、より高解像度な画像を表示する場面に使用できる
53 public string FullSizeImageUrl { get; set; }
55 /// <summary>ツールチップとして表示するテキスト</summary>
57 /// サムネイル画像にマウスオーバーした際に表示されるテキスト
59 public string TooltipText { get; set; }
62 /// 対象となるメディアが動画や音声など再生可能なものであるか否か
64 public bool IsPlayable { get; set; }
66 public Task<MemoryImage> LoadThumbnailImageAsync()
68 return this.LoadThumbnailImageAsync(CancellationToken.None);
71 public Task<MemoryImage> LoadThumbnailImageAsync(CancellationToken cancellationToken)
73 return this.LoadThumbnailImageAsync(Networking.Http, cancellationToken);
76 public async virtual Task<MemoryImage> LoadThumbnailImageAsync(HttpClient http, CancellationToken cancellationToken)
78 MemoryImage image = null;
81 using (var response = await http.GetAsync(this.ThumbnailImageUrl, cancellationToken).ConfigureAwait(false))
83 response.EnsureSuccessStatusCode();
85 using (var imageStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
87 image = await MemoryImage.CopyFromStreamAsync(imageStream)
88 .ConfigureAwait(false);
90 cancellationToken.ThrowIfCancellationRequested();
96 catch (OperationCanceledException)
103 public override bool Equals(object obj)
105 return this.Equals(obj as ThumbnailInfo);
108 public bool Equals(ThumbnailInfo other)
110 return other != null &&
111 other.MediaPageUrl == this.MediaPageUrl &&
112 other.ThumbnailImageUrl == this.ThumbnailImageUrl &&
113 other.TooltipText == this.TooltipText &&
114 other.FullSizeImageUrl == this.FullSizeImageUrl &&
115 other.IsPlayable == this.IsPlayable;
118 public override int GetHashCode()
120 return this.MediaPageUrl.GetHashCode() ^ this.ThumbnailImageUrl.GetHashCode();