From eb7ef6ce1b8bf0757e220eccd2cce3232dfe97c6 Mon Sep 17 00:00:00 2001 From: zbyna Date: Sun, 6 Nov 2016 00:52:49 +0100 Subject: [PATCH] Create nfo files 7 refactoring genre translating for film scrapers --- unit7.lfm | 12 ++++++------ unit7.pas | 7 ++++--- unit8.pas | 31 ++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/unit7.lfm b/unit7.lfm index d582794..7675081 100644 --- a/unit7.lfm +++ b/unit7.lfm @@ -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 @@ -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' @@ -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' @@ -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 @@ -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' @@ -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' diff --git a/unit7.pas b/unit7.pas index e2fc927..94524f4 100644 --- a/unit7.pas +++ b/unit7.pas @@ -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); diff --git a/unit8.pas b/unit8.pas index d7cae5a..a8d7cad 100644 --- a/unit8.pas +++ b/unit8.pas @@ -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; @@ -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; @@ -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; @@ -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")),'+ @@ -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); @@ -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); @@ -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.