Skip to content

Commit

Permalink
eatgram
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnsanders committed Jul 7, 2022
1 parent 37149e0 commit da6e801
Show file tree
Hide file tree
Showing 15 changed files with 1,424 additions and 43 deletions.
5 changes: 5 additions & 0 deletions Web.xxmp
Expand Up @@ -106,6 +106,11 @@
"path": "HotList.xxm",
"unitName": "hotlist_xxm1",
"unitPath": ""
},
"get_xxm": {
"path": "Get.xxm",
"unitName": "get_xxm1",
"unitPath": ""
}
},
"units": {
Expand Down
3 changes: 2 additions & 1 deletion eater/eater.dpr
Expand Up @@ -27,7 +27,8 @@ uses
feedTitanium in 'feedTitanium.pas',
feedFusion in 'feedFusion.pas',
feedNextData in 'feedNextData.pas',
eaterRun in 'eaterRun.pas';
eaterRun in 'eaterRun.pas',
eatgram_TLB in '..\eatgram\eatgram_TLB.pas';

{$R *.res}
{$APPTYPE CONSOLE}
Expand Down
1 change: 1 addition & 0 deletions eater/eater.dproj
Expand Up @@ -145,6 +145,7 @@
<DCCReference Include="feedFusion.pas"/>
<DCCReference Include="feedNextData.pas"/>
<DCCReference Include="eaterRun.pas"/>
<DCCReference Include="..\eatgram\eatgram_TLB.pas"/>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
Expand Down
52 changes: 15 additions & 37 deletions eater/eaterFeeds.pas
Expand Up @@ -67,7 +67,7 @@ TFeedEater=class(TInterfacedObject, IFeedStore, IFeedHandler)
implementation

uses Windows, SysUtils, Variants, ComObj, eaterUtils, eaterSanitize, MSXML2_TLB,
jsonDoc, VBScript_RegExp_55_TLB, eaterGraphs, feedSoundCloud;
jsonDoc, VBScript_RegExp_55_TLB, eaterGraphs, feedSoundCloud, eatGram_TLB;

const
FeederIniPath='..\..\feeder.ini';
Expand All @@ -83,14 +83,8 @@ implementation
YoutubePrefix1='https://www.youtube.com/channel/';
YoutubePrefix2='https://www.youtube.com/feeds/videos.xml?channel_id=';

InstagramDelaySecs:array[boolean] of cardinal=(20,2);
InstagramSuffixCount=4;
InstagramSuffix:array[0..InstagramSuffixCount-1] of string=(
'?__a=1','channel/?__a=1','?__a=1&__b=1','channel/?__a=1&__b=1');

var
InstagramHot:boolean;
InstagramDelayMS,InstagramSuffixIndex:cardinal;
EaterGram:IEaterGram;

function qrDate(qr:TQueryResult;const Idx:Variant):TDateTime;
var
Expand Down Expand Up @@ -492,6 +486,7 @@ function TFeedEater.DoUpdateFeeds(SpecificFeedID:integer;const FeedLike:string;
if StartsWith(FFeed.URL,'https://www.instagram.com/') then
begin

{
i:=cardinal(GetTickCount-InstagramDelayMS);
j:=InstagramDelaySecs[InstagramHot];
if i<j*1000 then
Expand All @@ -505,26 +500,19 @@ function TFeedEater.DoUpdateFeeds(SpecificFeedID:integer;const FeedLike:string;
end;
Write(#13'[Instagram delay...]');
end;
}

if (FFeed.URL<>'') and (FFeed.URL[Length(FFeed.URL)]<>'/') then
FFeed.URL:=FFeed.URL+'/';
FeedData:=LoadExternal(FFeed.URL+
InstagramSuffix[InstagramSuffixIndex]+'&redirect=false&ts='+IntToStr(GetTickCount),
'xmls\'+Format('%.4d',[FFeed.ID])+'.json',
FFeed.LastMod,
'application/json');

if (FeedData='') then
InstagramSuffixIndex:=(InstagramSuffixIndex+1) mod InstagramSuffixCount;
InstagramHot:=FeedData<>'';
InstagramDelayMS:=GetTickCount;
if FeedData='' then //if StartsWith(FeedData,'HTTP/1.1 301') then
begin
FFeed.Result:='[Instagram]';
FFeed.LoadStart:=FFeed.LoadLast;//retail last LoadLast
end
else
FeedDataType:=ParseExternalHeader(FeedData);
if EaterGram=nil then
EaterGram:=CoEaterGram.Create;
FeedData:=EaterGram.LoadData(FFeed.URL);
FeedDataType:='applicaton/json';

if SaveData then
SaveUTF16('xmls\'+Format('%.4d',[FFeed.ID])+'.json',FeedData);

end
else

Expand Down Expand Up @@ -561,15 +549,6 @@ function TFeedEater.DoUpdateFeeds(SpecificFeedID:integer;const FeedLike:string;
r.setRequestHeader('Accept','application/sparql-results+xml, application/xml, text/xml')
end
else
if StartsWith(FFeed.URL,'https://www.instagram.com/') then
begin
if (FFeed.URL<>'') and (FFeed.URL[Length(FFeed.URL)]<>'/') then
FFeed.URL:=FFeed.URL+'/';
r.open('GET',FFeed.URL+InstagramSuffix[InstagramSuffixIndex],false,EmptyParam,EmptyParam);
r.setRequestHeader('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36');
r.setRequestHeader('Accept','application/json');
end
else
if StartsWith(FFeed.URL,'https://soundcloud.com/') then
begin
r.open('GET','https://api-v2.soundcloud.com/resolve?url='+
Expand Down Expand Up @@ -1120,7 +1099,7 @@ function TFeedEater.LoadExternal(const URL, FilePath, LastMod,
if StartsWith(URL,'https://www.instagram.com/') then
begin
mr:=0;
ua:='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36';
//ua:=
end;

ZeroMemory(@si,SizeOf(TStartupInfo));
Expand Down Expand Up @@ -1475,9 +1454,8 @@ procedure TFeedEater.RenderGraphs;
initialization
PGVersion:='';
BlackList:=TStringList.Create;
InstagramHot:=true;//default
InstagramSuffixIndex:=0;//default
InstagramDelayMS:=GetTickCount-InstagramDelaySecs[false]*1000;
EaterGram:=nil;
finalization
BlackList.Free;
EaterGram:=nil;
end.
7 changes: 2 additions & 5 deletions eater/feedInstagram.pas
Expand Up @@ -16,16 +16,13 @@ TInstagramFeedProcessor=class(TFeedProcessor)

implementation

uses SysUtils, ComObj, ActiveX, eaterUtils, Variants, jsonDoc, MSXML2_TLB,
eaterSanitize;
uses Windows, SysUtils, ComObj, ActiveX, Variants, jsonDoc, MSXML2_TLB,
eaterUtils, eaterSanitize;

const
Base64Codes:array[0..63] of AnsiChar=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

YoutubePrefix1='https://www.youtube.com/channel/';
YoutubePrefix2='https://www.youtube.com/feeds/videos.xml?channel_id=';

function Base64Encode(const x:UTF8String):UTF8String;
var
i,j,l:cardinal;
Expand Down
18 changes: 18 additions & 0 deletions eatgram/eatgram.dpr
@@ -0,0 +1,18 @@
program eatgram;

uses
Vcl.Forms,
eatgram1 in 'eatgram1.pas' {webInstagram},
eatgram_TLB in 'eatgram_TLB.pas',
eatgram2 in 'eatgram2.pas' {EaterGram: CoClass};

{$R *.TLB}

{$R *.res}

begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TwebInstagram, webInstagram);
Application.Run;
end.

0 comments on commit da6e801

Please sign in to comment.