2019-07-06 18:47:29 +00:00
# include "programManager.h"
ProgramManager : : ProgramManager ( )
{
}
int ProgramManager : : start ( Settings setting )
{
switch ( setting . modus ) {
case Modus : : DEFAULT_MODUS :
return defaultModus ( & setting ) ;
case Modus : : DIRECT_LINK_MODUS :
return directLinkModus ( & setting ) ;
default :
return - 1 ;
}
}
int ProgramManager : : defaultModus ( Settings * settings )
{
AccountManager accountManager ( settings - > accountFilePath ) ;
2019-07-07 16:30:37 +00:00
pageManager . setProxy ( settings - > proxy_ip , settings - > proxy_port ) ;
2019-07-06 18:47:29 +00:00
std : : string nameInUrl = pageManager . checkName ( settings - > name ) ;
if ( nameInUrl = = " -1 " )
return 25 ;
else if ( pageManager . login ( accountManager . getNextAccount ( ) ) ! = 0 )
return 29 ;
2019-07-07 16:30:37 +00:00
pageManager . writeToFile ( settings - > outputFilePath , " Name: " + settings - > name ) ;
2019-07-06 18:47:29 +00:00
//Find out number of all seasons
Reply tmp_reply = pageManager . getServerRequest ( pageManager . UrlPraefix + nameInUrl ) ;
2019-07-07 16:30:37 +00:00
if ( tmp_reply . html = = " -1 " )
return 32 ;
2019-07-06 18:47:29 +00:00
int maxStaffel = pageManager . counterContains ( tmp_reply . html , " /staffel-%i " ) ;
//For every season
for ( int staffel = 1 ; staffel < = maxStaffel ; + + staffel ) {
//Find out number of all episodes
tmp_reply = pageManager . getServerRequest ( pageManager . UrlPraefix + nameInUrl + " /staffel- " + std : : to_string ( staffel ) ) ;
2019-07-07 16:30:37 +00:00
if ( tmp_reply . html = = " -1 " )
return 40 ;
2019-07-06 18:47:29 +00:00
int maxFolge = pageManager . counterContains ( tmp_reply . html , " /episode-%i " ) ;
//for every episode
for ( int folge = 1 ; folge < = maxFolge ; + + folge ) {
tmp_reply = pageManager . getServerRequest ( pageManager . UrlPraefix + nameInUrl + " /staffel- " + std : : to_string ( staffel ) + " /episode- " + std : : to_string ( folge ) ) ;
2019-07-07 16:30:37 +00:00
if ( tmp_reply . html = = " -1 " )
return 47 ;
2019-07-06 18:47:29 +00:00
std : : string allLinks = pageManager . getLinks ( tmp_reply . html ) ;
2019-07-07 16:30:37 +00:00
std : : string Link = pageManager . chooseHosterLink ( allLinks , settings - > genaueHoster , settings - > languages ) ;
2019-07-06 18:47:29 +00:00
2019-07-07 16:30:37 +00:00
std : : cout < < " -> Link: https://s.to " < < Link < < std : : endl ;
2019-07-06 18:47:29 +00:00
if ( convertLink ( Link , & accountManager , settings , staffel , folge , allLinks ) ! = 0 )
return 51 ;
} std : : cout < < " season: " < < staffel < < " hat " < < maxFolge < < " folgen " < < std : : endl ;
}
return 0 ;
}
int ProgramManager : : directLinkModus ( Settings * settings )
{
AccountManager accountManager ( settings - > accountFilePath ) ;
std : : istringstream iStrStream ( pageManager . replace ( settings - > name , " , " , " \n " ) + " \n " ) ;
std : : string line ;
2019-07-07 16:30:37 +00:00
if ( pageManager . login ( accountManager . getNextAccount ( ) ) ! = 0 )
return 71 ;
2019-07-06 18:47:29 +00:00
while ( getline ( iStrStream , line ) . good ( ) ) {
2019-07-07 16:30:37 +00:00
if ( line . find ( " https://s.to/redirect/ " ) = = std : : string : : npos ) {
2019-07-06 18:47:29 +00:00
std : : cout < < " Invalid Redirect Link: ' " < < line < < " ' " < < std : : endl ;
continue ;
}
2019-07-07 16:30:37 +00:00
else if ( convertLink ( pageManager . replace ( line , " https://s.to " , " " ) , & accountManager , settings ) ! = 0 )
2019-07-06 18:47:29 +00:00
return 78 ;
}
return 0 ;
}
int ProgramManager : : convertLink ( std : : string redirectLink , AccountManager * accountManager , Settings * settings , int Staffel , int Folge , std : : string allLinks )
{
std : : string folgenID = std : : string ( ( Staffel = = - 1 | | Folge = = - 1 ) ? " " : " S " + std : : string ( ( Staffel < 10 ) ? " 0 " : " " ) + std : : to_string ( Staffel )
2019-07-07 16:30:37 +00:00
+ " E " + std : : string ( ( Folge < 10 ) ? " 0 " : " " ) + std : : to_string ( Folge ) + " : " ) ;
std : : string green = ( ( settings - > colorless ) ? " " : " \033 [32m " ) , red = ( ( settings - > colorless ) ? " " : " \033 [31m " ) , orange = ( ( settings - > colorless ) ? " " : " \033 [33m " ) , blue = ( ( settings - > colorless ) ? " " : " \033 [34m " ) ;
if ( redirectLink = = " " & & settings - > modus = = Modus : : DEFAULT_MODUS ) {
std : : cout < < " => " < < ( ( allLinks = = " " ) ? " \033 [31mKEINEN " : " \033 [33mKeinen PASSENDEN " ) < < " Hoster für die Folge " < < folgenID < < " gefunden. " < < " \033 [0m " < < std : : endl ;
2019-07-06 18:47:29 +00:00
return 0 ;
}
2019-07-07 16:30:37 +00:00
for ( int i = 1 ; i < = 3 ; + + i ) {
2019-07-06 18:47:29 +00:00
std : : string newUrl = pageManager . getUrlAfterRedirect ( " https://s.to " + redirectLink ) ;
if ( newUrl = = " -1 " ) {
return 102 ;
} else if ( newUrl . find ( " /s.to/redirect/ " ) ! = std : : string : : npos ) {
if ( pageManager . login ( accountManager - > getNextAccount ( ) ) ! = 0 )
return - 1 ;
continue ;
}
else {
2019-07-07 16:30:37 +00:00
std : : cout < < " => " < < folgenID < < green < < newUrl < < " \033 [0m " < < std : : endl ;
if ( settings - > outputFilePath ! = " " )
if ( pageManager . writeToFile ( folgenID + settings - > outputFilePath , newUrl ) ! = 0 )
return 108 ;
2019-07-06 18:47:29 +00:00
return 0 ;
}
}
2019-07-07 16:30:37 +00:00
std : : cout < < " => " < < folgenID < < red < < " https://s.to " < < redirectLink < < " \033 [0m " < < std : : endl ;
if ( settings - > outputFilePath ! = " " )
if ( pageManager . writeToFile ( settings - > outputFilePath , folgenID + redirectLink ) ! = 0 )
return 114 ;
2019-07-06 18:47:29 +00:00
return 0 ;
}