From 338caaa4bf753c11c317c0bcbfc290afd22abcf6 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Mon, 26 Dec 2022 17:25:14 -0500 Subject: [PATCH] Migrating YouTube enlarger. --- README.md | 19 ++++++++++--------- Shortener/Shortener.class.st | 2 +- Shortener/YouTube.class.st | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 Shortener/YouTube.class.st diff --git a/README.md b/README.md index 1f82f36..b7c2e14 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,12 @@ This is an small wrapper around the [ethical shortener](https://is.gd/ethics.php ## Installation -Run this two steps in a playground: +First install ExoRepo and then run this in a playground: ```smalltalk -"Start by loading the configuration of Shortener" - Gofer new - url: 'http://smalltalkhub.com/mc/Offray/Shortener/main'; - package: 'ConfigurationOfShortener'; - load. - -"After that load Shortener" -ConfigurationOfShortener load. +ExoRepo new + repository: 'https://code.sustrato.red/Offray/Shortener'; + load. ``` ## Usage @@ -34,5 +29,11 @@ ConfigurationOfShortener load. or will raise an error once a short url have been taken. For example, by running the previous example the alias 'pharo' has been taken for all future short urls and can not be used again (you will need to pick a new short url alias). + + You can also enlarge a link from YouTube using: + + `YouTube enlargeLink: 'https://youtu.be/ggSyF1SVFr4'` + + which produces `https://www.youtube.com/watch?v=ggSyF1SVFr4`. Migrated from: \ No newline at end of file diff --git a/Shortener/Shortener.class.st b/Shortener/Shortener.class.st index be29bd6..d0a4ad5 100644 --- a/Shortener/Shortener.class.st +++ b/Shortener/Shortener.class.st @@ -10,7 +10,7 @@ I use the public API as described in https://is.gd/apishorteningreference.php#re Class { #name : #Shortener, #superclass : #Object, - #category : #Shortener + #category : #'Shortener-Model' } { #category : #'as yet unclassified' } diff --git a/Shortener/YouTube.class.st b/Shortener/YouTube.class.st new file mode 100644 index 0000000..b0eca9e --- /dev/null +++ b/Shortener/YouTube.class.st @@ -0,0 +1,22 @@ +Class { + #name : #YouTube, + #superclass : #Object, + #category : #'Shortener-Model' +} + +{ #category : #'as yet unclassified' } +YouTube class >> enlargeLink: shortLinkString [ + | videoId videoLink shortLinkHost | + + 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. +]