93 lines
2.0 KiB
Smalltalk
93 lines
2.0 KiB
Smalltalk
"
|
|
I model the API for the [Invidious](https://invidious.io/) open source front-end for YouTube.
|
|
"
|
|
Class {
|
|
#name : #Invidious,
|
|
#superclass : #Object,
|
|
#instVars : [
|
|
'uri',
|
|
'region',
|
|
'api',
|
|
'monitor'
|
|
],
|
|
#category : #VideoWeb
|
|
}
|
|
|
|
{ #category : #accessing }
|
|
Invidious class >> defaultInstance [
|
|
^ self instances select: [ :instance | instance api = true ]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
Invidious class >> instances [
|
|
|
|
^ self rawInstances collect: [ :instanceData |
|
|
| instanceDict |
|
|
instanceDict := instanceData second.
|
|
Invidious new fromDictionary: instanceDict ]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
Invidious class >> rawInstances [
|
|
^ STON
|
|
fromString: 'https://api.invidious.io/instances.json?sort_by=type,users' asUrl
|
|
retrieveContents
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
Invidious >> api: booleanValue [
|
|
(booleanValue = 'true')
|
|
ifTrue: [ api := true ] ifFalse: [ api := false ]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
Invidious >> fromDictionary: aDictionary [
|
|
| rawMonitor|
|
|
self
|
|
uri: (aDictionary at: 'uri');
|
|
region: (aDictionary at: 'region');
|
|
api: (aDictionary at: 'api').
|
|
rawMonitor := aDictionary at: 'monitor'.
|
|
rawMonitor ifNil: [ ^ self ].
|
|
self monitor
|
|
at: '90DaysRatio' put: ((aDictionary at: 'monitor' at: '90dRatio') at: 'ratio');
|
|
at: '30DaysRatio' put: ((aDictionary at: 'monitor' at: '30dRatio') at: 'ratio');
|
|
yourself.
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
Invidious >> monitor [
|
|
^ monitor ifNil: [ monitor := Dictionary new]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
Invidious >> monitor: aDictionary [
|
|
monitor := aDictionary
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
Invidious >> printOn: aStream [
|
|
super printOn: aStream.
|
|
^ aStream nextPutAll: ' ( ', self uri asString, ' | ', self region, ' | ', (self monitor at: '90DaysRatio'), '% ) '
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
Invidious >> region [
|
|
^ region
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
Invidious >> region: countryISOCode [
|
|
region := countryISOCode
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
Invidious >> uri [
|
|
^ uri
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
Invidious >> uri: urlString [
|
|
uri := urlString asUrl
|
|
]
|