diff --git a/lib/core/web_address.dart b/lib/core/web_address.dart index b9370c5..851b310 100644 --- a/lib/core/web_address.dart +++ b/lib/core/web_address.dart @@ -24,3 +24,15 @@ bool looksLikeVideoPage(String url) { caseSensitive: false, ).hasMatch(url); } + +/// 137: 동영상 페이지 주소가 정해져 있는 사이트 (YouTube 등). 이런 사이트는 주소만으로 판단한다 - +/// 첫 화면 · 구독 목록에도 미리보기 <video> 가 있어 "동영상 있음" 으로 보였다. +bool isKnownVideoSite(String url) => RegExp( + r'^https?://([\w-]+\.)*(youtube\.com|youtu\.be|vimeo\.com|dailymotion\.com|twitch\.tv|tiktok\.com|instagram\.com|' + r'tv\.naver\.com|chzzk\.naver\.com|bilibili\.com|nicovideo\.jp)(/|$)', + caseSensitive: false, + ).hasMatch(url); + +/// 137: 다운로드 버튼을 눈에 띄게 (채움) 할지 - 주소가 동영상 페이지이거나, 주소로 판단하지 않는 사이트에서 <video> 를 찾았을 때 +bool downloadLooksUseful(String url, {required bool pageHasVideo}) => + looksLikeVideoPage(url) || (pageHasVideo && !isKnownVideoSite(url)); diff --git a/lib/ui/browser_page.dart b/lib/ui/browser_page.dart index d9cdc2f..40c6cbc 100644 --- a/lib/ui/browser_page.dart +++ b/lib/ui/browser_page.dart @@ -399,8 +399,8 @@ class _BrowserPageState extends State with RouteAware { /// 27: 어느 사이트에서나 받아 볼 수 있다 (yt-dlp 가 지원하면 받고, 아니면 다운로드 목록에 이유가 보인다) bool get _canDownload => widget.downloads != null && _url.startsWith('http'); - /// 동영상이 있어 보이는 페이지 (버튼을 눈에 띄게) - bool get _likelyVideo => looksLikeVideoPage(_url) || _hasVideo; + /// 동영상이 있어 보이는 페이지 (버튼을 눈에 띄게). 137: 못 찾은 페이지는 테두리만 있는 버튼 + bool get _likelyVideo => downloadLooksUseful(_url, pageHasVideo: _hasVideo); String get _downloadTip => _likelyVideo ? tr('다운로드') : tr('다운로드 (이 페이지에서 동영상을 찾지 못했지만 받아 볼 수 있습니다)'); @@ -650,7 +650,7 @@ class _BrowserPageState extends State with RouteAware { onPressed: _canDownload ? _download : null, icon: const Icon(Icons.download, size: 18), ) - : IconButton.filledTonal( + : IconButton.outlined( tooltip: _downloadTip, visualDensity: VisualDensity.compact, onPressed: _canDownload ? _download : null, @@ -665,7 +665,7 @@ class _BrowserPageState extends State with RouteAware { icon: const Icon(Icons.download, size: 18), label: Text(tr('다운로드')), ) - : FilledButton.tonalIcon( + : OutlinedButton.icon( onPressed: _canDownload ? _download : null, icon: const Icon(Icons.download, size: 18), label: Text(tr('다운로드')), diff --git a/test/browser_test.dart b/test/browser_test.dart index 24a2419..db95a00 100644 --- a/test/browser_test.dart +++ b/test/browser_test.dart @@ -146,6 +146,14 @@ void main() { expect(looksLikeVideoPage('https://tv.naver.com/v/123'), isTrue); expect(looksLikeVideoPage('https://www.google.com/'), isFalse); }); + test('137: 다운로드 버튼을 눈에 띄게 할지 - YouTube 첫 화면 · 구독 목록은 미리보기