Skip to content

Commit

Permalink
Youtubeのショート動画URL対応。
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanasu committed Sep 29, 2024
1 parent 8f60154 commit 22f3695
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/app/class/cut-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ export class CutIn extends ObjectNode {
let ret = '';
if (StringUtil.validUrl(this.videoUrl)) {
const hostname = (new URL(this.videoUrl)).hostname
if (hostname == 'youtube.com' || hostname == 'www.youtube.com') {
let tmp = this.videoUrl.split('v=');
if (tmp[1]) ret = encodeURI(tmp[1].split(/[\?\&\#\/]/)[0]);
if (hostname == 'youtube.com' || hostname == 'www.youtube.com') {
if (this.videoUrl.indexOf('/shorts/') >= 0) {
let tmp = this.videoUrl.split('/shorts/');
if (tmp[1]) ret = encodeURI(tmp[1].split(/[\?\&\#\/]/)[0]);
} else if (this.videoUrl.indexOf('?v=') >= 0) {
let tmp = this.videoUrl.split('?v=');
if (tmp[1]) ret = encodeURI(tmp[1].split(/[\?\&\#\/]/)[0]);
}
} else if (hostname == 'youtu.be') {
let tmp = this.videoUrl.split('youtu.be/');
if (tmp[1]) ret = encodeURI(tmp[1].split(/[\?\&\#\/]/)[0]);
Expand Down
4 changes: 3 additions & 1 deletion src/app/component/cut-in/cut-in.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export class CutInComponent implements OnInit, OnDestroy {
private _naturalWidth = 0;
private _naturalHeight = 0;
private get naturalWidth(): number {
if (this.videoId && !this.isSoundOnly) return 480;
if (this.videoId && !this.isSoundOnly) {
return (this.cutIn.videoUrl.indexOf('/shorts/') >= 0) ? 270 : 480;
}
return this._naturalWidth;
}
private get naturalHeight(): number {
Expand Down

0 comments on commit 22f3695

Please sign in to comment.