Creating Instagram local class and improving instagram downloader.

This commit is contained in:
ruidajo 2024-09-16 20:20:26 -05:00
parent 09df2285f7
commit 3315efd807
2 changed files with 78 additions and 5 deletions

View File

@ -8,16 +8,25 @@ Class {
#category : #Instagram
}
{ #category : #accessing }
InstagramDownloader >> asInstagramLocal [
^ InstagramLocal new profiles: self profiles;
rootDir: self profiles values first parent
]
{ #category : #'as yet unclassified' }
InstagramDownloader >> downloadProfile: anInstProfileName [
| profiles |
profiles := (FileLocator documents / 'InstagramDownloader' / 'Profiles') ensureCreateDirectory.
| tempProfiles |
tempProfiles := (FileLocator documents / 'InstagramDownloader' / 'Profiles')
ensureCreateDirectory.
^ GtSubprocessWithInMemoryOutput new
workingDirectory: profiles;
workingDirectory: tempProfiles;
command: bin fullName;
arguments: {anInstProfileName.
'--no-videos'.
'--no-compress-json'};
'--no-compress-json'.
'--filename-pattern'.
'{profile}-{date_utc}-UTC-code:{shortcode}'};
runAndWait;
stdout
]
@ -43,7 +52,8 @@ InstagramDownloader >> loadDefault [
| temp |
temp := FileLocator documents / 'InstagramDownloader'.
bin := temp / 'bin' / 'instaloader'.
profiles := temp / 'Profiles'
profiles := ((temp / 'Profiles') children
collect: [ :dir | dir basename -> dir ]) asDictionary
]
{ #category : #'as yet unclassified' }

View File

@ -0,0 +1,63 @@
Class {
#name : #InstagramLocal,
#superclass : #Object,
#instVars : [
'profiles',
'rootDir',
'posts'
],
#category : #Instagram
}
{ #category : #'as yet unclassified' }
InstagramLocal >> postsProcessed [
| temp shortcodes |
temp := Dictionary new.
shortcodes := OrderedCollection new.
self profiles
keysAndValuesDo: [ :k :v |
| sel col |
sel := v children
select: [ :file | file extension = 'json' and: [ file basename includesSubstring: 'code:' ] ].
col := sel
collect: [ :file | | tempShortcode |
tempShortcode := ('code:' split: file basenameWithoutExtension) second.
shortcodes add: tempShortcode.
(v / ('Post-' , tempShortcode ))
ensureCreateDirectory ].
temp at: k put: col. ].
^ { temp . shortcodes }
]
{ #category : #accessing }
InstagramLocal >> postsTiddlers [
| temp jsons|
temp := OrderedCollection new.
self profiles
valuesDo: [ :v |
temp
add: (v children
select: [ :file | file extension = 'json' and: [ file basename includesSubstring: 'code:' ] ]) ].
jsons := temp flatten collect: [ :post | STONJSON fromString: post contents ].
^ jsons collect: [:json | Tiddler nowLocal ]
]
{ #category : #accessing }
InstagramLocal >> profiles [
^ profiles
]
{ #category : #accessing }
InstagramLocal >> profiles: aCollectionProfiles [
profiles := aCollectionProfiles
]
{ #category : #accessing }
InstagramLocal >> rootDir [
^ rootDir
]
{ #category : #accessing }
InstagramLocal >> rootDir: anObject [
rootDir := anObject
]