Shortener/Shortener/YouTube.class.st

23 lines
550 B
Smalltalk
Raw Permalink Normal View History

2022-12-26 22:25:14 +00:00
Class {
#name : #YouTube,
#superclass : #Object,
#category : #'Shortener-Model'
}
2022-12-27 22:35:02 +00:00
{ #category : #operation }
2022-12-26 22:25:14 +00:00
YouTube class >> enlargeLink: shortLinkString [
2022-12-27 22:35:02 +00:00
| videoId shortLinkHost |
2022-12-26 22:25:14 +00:00
shortLinkHost := shortLinkString asZnUrl host.
(shortLinkHost = 'www.youtube.com') ifTrue: [ ^ shortLinkHost ].
(shortLinkHost = 'youtu.be') ifFalse: [ ^ self ].
videoId := (ZnUrl fromString: shortLinkString) lastPathSegment.
^ ZnUrl new
scheme: #https;
host: 'www.youtube.com';
addPathSegment: 'watch';
queryAt: 'v' put: videoId;
yourself.
]