Skip to content

Commit

Permalink
Create nfo files 7
Browse files Browse the repository at this point in the history
refactoring genre translating for film scrapers
  • Loading branch information
zbyna committed Nov 5, 2016
1 parent e8ce5eb commit eb7ef6c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
12 changes: 6 additions & 6 deletions unit7.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ inherited FormNastaveni: TFormNastaveni
TabOrder = 0
object Scrapers: TTabSheet
Caption = 'Scrapers'
ClientHeight = 439
ClientHeight = 441
ClientWidth = 712
object FilmScrapers: TRadioGroup
Left = 17
Expand All @@ -172,7 +172,7 @@ inherited FormNastaveni: TFormNastaveni
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 253
ClientHeight = 255
ClientWidth = 151
Items.Strings = (
'themoviedb.org'
Expand All @@ -195,7 +195,7 @@ inherited FormNastaveni: TFormNastaveni
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 253
ClientHeight = 255
ClientWidth = 151
Items.Strings = (
'themoviedb.org'
Expand All @@ -219,7 +219,7 @@ inherited FormNastaveni: TFormNastaveni
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclTopToBottomThenLeftToRight
ChildSizing.ControlsPerLine = 12
ClientHeight = 350
ClientHeight = 352
ClientWidth = 308
ColumnLayout = clVerticalThenHorizontal
Columns = 2
Expand Down Expand Up @@ -269,7 +269,7 @@ inherited FormNastaveni: TFormNastaveni
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 161
ClientHeight = 163
ClientWidth = 237
Items.Strings = (
'Čeština'
Expand Down Expand Up @@ -297,7 +297,7 @@ inherited FormNastaveni: TFormNastaveni
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 98
ClientHeight = 100
ClientWidth = 351
Items.Strings = (
'Highlight initial position'
Expand Down
7 changes: 4 additions & 3 deletions unit7.pas
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ procedure TFormNastaveni.nastavStatusBar;

procedure TFormNastaveni.spustReinicializaci(Data: PtrInt);
begin
initGenres(genresMovieDB,
'https://api.themoviedb.org/3/genre/movie/list?api_key='+theMovidedbAPI+
'&language='+aktualniJazyk,'$json("genres")() ! [.("id"), .("name")]');
//initGenres(genresMovieDB,
// 'https://api.themoviedb.org/3/genre/movie/list?api_key='+theMovidedbAPI+
// '&language='+aktualniJazyk,'$json("genres")() ! [.("id"), .("name")]');
InitGenresLanguageFilm[TScraperFilm(FormNastaveni.FilmScrapers.ItemIndex)](aktualniJazyk);
end;

procedure TFormNastaveni.UpdateTranslation(ALang: String);
Expand Down
31 changes: 30 additions & 1 deletion unit8.pas
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ ProHash = class

TScraperFilm = (Fthemoviedb,imdb,csfd);
TfunctionScraperFilm = function(PomNazev:string):string;
TprocedureInitGenresLanguageFilm = procedure(lang:string);

{ pro scraping roku k seriálu }

TScraperSerial = (Sthemoviedb,tvmaze,thetvdb,Scsfd);
TfunctionScraperSerial = function(PomNazev:string):string;
TprocedureInitGenresLanguageSerial = procedure(lang:string);

{ general action for all scrapers - něco jako closures ve Swiftu :-) }
TprocedureSraperAction = procedure(v: IXQValue) is nested;
Expand Down Expand Up @@ -94,6 +96,9 @@ TFormScraper = class(TLocalizedForm)
procedure initGenres(var tabulka:TGenresMovieDB;
pathToFile:String;
parseString:String);
procedure initGenresMovieDBFilm(lang:String);
procedure initGenresImdbFilm(lang:String);
procedure initGenresCsfdFilm(lang:String);

var
FormScraper: TFormScraper;
Expand All @@ -106,6 +111,8 @@ TFormScraper = class(TLocalizedForm)
ScraperySerial :array[TScraperSerial] of TFunctionScraperSerial;
aktualniScraperSerial:TfunctionScraperSerial;
genresMovieDB : TgenresMovieDB;
InitGenresLanguageFilm :array[TScraperFilm] of TprocedureInitGenresLanguageFilm;
InitGenresLanguageSerial:array[TScraperSerial] of TprocedureInitGenresLanguageSerial;



Expand Down Expand Up @@ -211,7 +218,8 @@ function FilmImdb(PomNazev: string):string;
w: IXQValue;
begin
pomImdbId:= (v as TXQValueJSONArray).seq.get(0).toString;
FormScraper.vyberReferer.Add('Referer: http://www.imdb.com/title/'+
//formScraper.EventLog1.Debug('konec první části imdbID: '+pomImdbId);
formScraper.vyberReferer.Add('Referer: http://www.imdb.com/title/'+
pomImdbId+'/');
w:= process('http://www.omdbapi.com/?i='+pomImdbId,
'$json ! [.("Title"),string(.("Year")),'+
Expand All @@ -223,6 +231,7 @@ function FilmImdb(PomNazev: string):string;
formScraper.vyberDeju.Add((w as TXQValueJSONArray).seq.get(3).toString);
FormScraper.vyberZanru.Add((w as TXQValueJSONArray).seq.get(4).toString);
FormScraper.vyberHodnoceni.Add((w as TXQValueJSONArray).seq.get(5).toString);
//formScraper.EventLog1.Debug('konec druhé části imdbID: '+pomImdbId);
if length(pomRok)=4 then {když api vrací rovnou čtyři znaky roku}
begin
formScraper.vyberFilmu.Items.AddText(pomNazev+'~'+pomRok);
Expand Down Expand Up @@ -825,6 +834,9 @@ procedure TFormScraper.FormCreate(Sender: TObject);
initGenres(genresMovieDB,
'https://api.themoviedb.org/3/genre/movie/list?api_key='+theMovidedbAPI+
'&language='+aktualniJazyk,'$json("genres")() ! [.("id"), .("name")]');
InitGenresLanguageFilm[Fthemoviedb]:=@(initGenresMovieDBFilm);
InitGenresLanguageFilm[imdb]:=@(initGenresImdbFilm);
InitGenresLanguageFilm[csfd]:=@(initGenresCsfdFilm);
end;

procedure TFormScraper.FormClose(Sender:TObject; var CloseAction:TCloseAction);
Expand Down Expand Up @@ -883,5 +895,22 @@ procedure initGenres(var tabulka:TGenresMovieDB;
end;
end;

procedure initGenresMovieDBFilm(lang: String);
begin
initGenres(genresMovieDB,
'https://api.themoviedb.org/3/genre/movie/list?api_key='+theMovidedbAPI+
'&language='+lang,'$json("genres")() ! [.("id"), .("name")]');
end;

procedure initGenresImdbFilm(lang: String);
begin
// pripare for possible genre translating
end;

procedure initGenresCsfdFilm(lang: String);
begin
// pripare for possible genre translating
end;

end.

0 comments on commit eb7ef6c

Please sign in to comment.