Example #1
0
        public string GetImgPathForGame(GameRom game, ScraperType sGDBType)
        {
            var    emulator   = dbService.GetEmulator(game.EmulatorID);
            var    plateforme = dbService.GetSysteme(emulator.SystemeID);
            string imgfolder  = Path.Combine(FileJSONService.appSettings.AppSettingsFolder, "media", plateforme.Shortname);

            if (sGDBType == ScraperType.ArtWork)
            {
                //if(game.SteamID > 0)
                //    return Path.Combine(imgfolder, "fanart", $"{game.SteamID}");
                //else
                //    return Path.Combine(imgfolder, "fanart", $"{game.Name}");
                Directory.CreateDirectory(Path.Combine(imgfolder, "fanart"));
                return(Path.Combine(imgfolder, "fanart", $"{Guid.NewGuid().ToString()}"));
            }
            else if (sGDBType == ScraperType.Boxart)
            {
                //if (game.SteamID > 0)
                //    return Path.Combine(imgfolder, "box2dfront", $"{game.SteamID}");
                //else
                //    return Path.Combine(imgfolder, "box2dfront", $"{game.Name}");
                Directory.CreateDirectory(Path.Combine(imgfolder, "box2dfront"));
                return(Path.Combine(imgfolder, "box2dfront", $"{Guid.NewGuid().ToString()}"));
            }
            else if (sGDBType == ScraperType.Banner)
            {
                //if (game.SteamID > 0)
                //    return Path.Combine(imgfolder, "steamgrid", $"{game.SteamID}");
                //else
                //    return Path.Combine(imgfolder, "steamgrid", $"{game.Name}");
                Directory.CreateDirectory(Path.Combine(imgfolder, "steamgrid"));
                return(Path.Combine(imgfolder, "steamgrid", $"{Guid.NewGuid().ToString()}"));
            }
            else if (sGDBType == ScraperType.Logo)
            {
                //if (game.SteamID > 0)
                //    return Path.Combine(imgfolder, "wheel", $"{game.SteamID}");
                //else
                //    return Path.Combine(imgfolder, "wheel", $"{game.Name}");
                Directory.CreateDirectory(Path.Combine(imgfolder, "wheel"));
                return(Path.Combine(imgfolder, "wheel", $"{Guid.NewGuid().ToString()}"));
            }
            else if (sGDBType == ScraperType.Video)
            {
                //if (game.SteamID > 0)
                //    return Path.Combine(imgfolder, "wheel", $"{game.SteamID}");
                //else
                //    return Path.Combine(imgfolder, "wheel", $"{game.Name}");
                Directory.CreateDirectory(Path.Combine(imgfolder, "videos"));
                return(Path.Combine(imgfolder, "videos", $"{Guid.NewGuid().ToString()}"));
            }
            else
            {
                return(string.Empty);
            }
        }
 public ScraperDto(ScraperType scraperType, bool isActivated, int nbDecks, string urlDeckList)
 {
     Type        = scraperType.Type.ToString().ToLower();
     Id          = scraperType.Id;
     Format      = scraperType.Format.ToString().ToLower();
     IsByUser    = scraperType.IsByUser;
     Url         = urlDeckList ?? scraperType.Url;
     IsActivated = isActivated;
     NbDecks     = nbDecks;
 }
Example #3
0
 public ImgFinderSearchViewModel(GameRom game, ScraperSource currentScrapeSource, ScraperType currentScraperType)
 {
     steamGridDBService = App.ServiceProvider.GetRequiredService <ISteamGridDBService>();
     iGDBService        = App.ServiceProvider.GetRequiredService <IIGDBService>();
     dialogService      = App.ServiceProvider.GetRequiredService <IDialogService>();
     Title               = $"Recherche de {CurrentScraperType.ToString()} pour {game.Name}";
     ResultImgs          = new ObservableCollection <string>();
     CurrentScrapeSource = currentScrapeSource;
     CurrentScraperType  = currentScraperType;
     LoadingProposal(game);
 }
Example #4
0
        public string SearchVideo(GameRom game, ScraperType type, ScraperSource source)
        {
            ModalWindow modalWindow = new ModalWindow();
            var         vm          = new VideoFinderSearchViewModel(game, source, type);

            modalWindow.DataContext = vm;
            if (modalWindow.ShowDialog().Value)
            {
                return(vm.ResultPath);
            }
            return(null);
        }
Example #5
0
        public async Task <IScrapeSession> GetScrapeSessionAsync(string source, ScraperType type, IScrapeSession lastSession = null, CancellationToken cancellationToken = default)
        {
            var scrapeFrom = type == ScraperType.Local
                ? (await _context.GetLatestLocalMovieBySourceAsync(source, cancellationToken))?.DateCreated
                : (await _context.GetLatestMovieBySourceAsync(source, cancellationToken))?.DateCreated;

            var movieImdbCodes = lastSession?.MovieImdbCodes ?? await _context.Set <Movie>().Select(x => x.ImdbCode).ToListAsync(cancellationToken);

            var localImdbCodes = lastSession?.LocalImdbCodes ?? await _context.Set <LocalMovie>().Select(x => x.ImdbCode).ToListAsync(cancellationToken);

            return(new ScrapeSession(source, type, scrapeFrom, movieImdbCodes, localImdbCodes, _context, _clock, cancellationToken, _options.Value));
        }
        public GetPictureForSystemViewModel(Systeme title, string themename, ScraperType scraperType)
        {
            Title         = $"Rechercher de {scraperType.ToString()} pour {title.Name}";
            ScraperType   = scraperType;
            dialogService = App.ServiceProvider.GetRequiredService <IDialogService>();
            themeService  = App.ServiceProvider.GetRequiredService <IThemeService>();
            var img = themeService.GetBckForTheme(title.Shortname, themename);

            if (img != null)
            {
                ImgPath = img;
            }
        }
 public ScrapeInfo(UInt32 a, UInt32 b, UInt32 c, ScraperType type)
 {
     if (type == ScraperType.HTTP)
     {
         Complete   = a;
         Downloaded = b;
         Incomplete = c;
     }
     else if (type == ScraperType.UDP)
     {
         Seeders  = a;
         Complete = b;
         Leachers = c;
     }
 }
Example #8
0
 public ScrapeInfo(UInt32 a, UInt32 b, UInt32 c, ScraperType type)
 {
     if (type == ScraperType.HTTP)
     {
         this.Complete   = a;
         this.Downloaded = b;
         this.Incomplete = c;
     }
     else if (type == ScraperType.UDP)
     {
         this.Seeders  = a;
         this.Complete = b;
         this.Leechers = c;
     }
 }
        public IWebScraper CreateWebScraper(ScraperType scraperType)
        {
            IWebScraper newWebScraperInstance = default;

            switch (scraperType)
            {
            case ScraperType.Unidentified:
                throw new Exception("Scraper Type Must Be Identified");

            case ScraperType.HackerNewsScraper:
                newWebScraperInstance = new HackerNewsScraper();
                break;
            }

            return(newWebScraperInstance);
        }
Example #10
0
        protected void ValidateInput(string url, string[] hashes, ScraperType type)
        {
            if (hashes.Length < MINIMUM_HASH_LENGTH)
            {
                throw new ArgumentOutOfRangeException(nameof(hashes), hashes, $"Must have at least {MINIMUM_HASH_LENGTH} hash when calling scrape");
            }

            if (hashes.Length > MAXIMUM_HASH_LENGTH)
            {
                throw new ArgumentOutOfRangeException(nameof(hashes), hashes, $"Must have a maximum of {MAXIMUM_HASH_LENGTH} hashes when calling scrape");
            }

            foreach (var hash in hashes)
            {
                if (!HashRegex.IsMatch(hash))
                {
                    throw new ArgumentOutOfRangeException(nameof(hashes), hash, "Hash is not valid");
                }
            }

            if (type == ScraperType.UDP)
            {
                var match = UDPRegex.Match(url);

                if (!match.Success)
                {
                    throw new ArgumentOutOfRangeException(nameof(url), url, "URL is not a valid UDP tracker address");
                }

                Tracker = match.Groups[1].Value;
                Port    = match.Groups.Count == 3 ? Convert.ToInt32(match.Groups[2].Value) : 80;
            }
            else if (type == ScraperType.HTTP)
            {
                var match = HTTPRegex.Match(url);

                if (!match.Success)
                {
                    throw new ArgumentOutOfRangeException(nameof(url), url, "URL is not a valid HTTP tracker address");
                }

                Tracker = match.Groups[0].Value;
            }
        }
Example #11
0
        protected void ValidateInput(String url, String[] hashes, ScraperType type)
        {
            if (hashes.Length < 1)
            {
                throw new ArgumentOutOfRangeException("hashes", hashes, "Must have at least one hash when calling scrape");
            }

            if (hashes.Length > 74)
            {
                throw new ArgumentOutOfRangeException("hashes", hashes, "Must have a maximum of 74 hashes when calling scrape");
            }

            foreach (String hash in hashes)
            {
                if (!HashRegex.IsMatch(hash))
                {
                    throw new ArgumentOutOfRangeException("hashes", hash, "Hash is not valid");
                }
            }

            if (type == ScraperType.UDP)
            {
                Match match = UDPRegex.Match(url);

                if (!match.Success)
                {
                    throw new ArgumentOutOfRangeException("url", url, "URL is not a valid UDP tracker address");
                }

                Tracker = match.Groups[1].Value;
                Port    = match.Groups.Count == 3 ? Convert.ToInt32(match.Groups[2].Value) : 80;
            }
            else if (type == ScraperType.HTTP)
            {
                Match match = HTTPRegex.Match(url);

                if (!match.Success)
                {
                    throw new ArgumentOutOfRangeException("url", url, "URL is not a valid HTTP tracker address");
                }

                Tracker = match.Groups[0].Value;
            }
        }
Example #12
0
        protected void ValidateInput(String url, String[] hashes, ScraperType type)
        {
            if (hashes.Length < 1)
            {
                throw new ArgumentOutOfRangeException("hashes", hashes, "Must have at least one hash when calling scrape");
            }

            if (hashes.Length > 74)
            {
                throw new ArgumentOutOfRangeException("hashes", hashes, "Must have a maximum of 74 hashes when calling scrape");
            }

            foreach (String hash in hashes)
            {
                if (!HashRegex.IsMatch(hash))
                {
                    throw new ArgumentOutOfRangeException("hashes", hash, "Hash is not valid");
                }
            }

            if (type == ScraperType.UDP)
            {
                Match match = UDPRegex.Match(url);

                if (!match.Success)
                {
                    throw new ArgumentOutOfRangeException("url", url, "URL is not a valid UDP tracker address");
                }

                Tracker = match.Groups[1].Value;
                Port = match.Groups.Count == 3 ? Convert.ToInt32(match.Groups[2].Value) : 80;
            }
            else if (type == ScraperType.HTTP)
            {
                Match match = HTTPRegex.Match(url);

                if (!match.Success)
                {
                    throw new ArgumentOutOfRangeException("url", url, "URL is not a valid HTTP tracker address");
                }

                Tracker = match.Groups[0].Value;
            }
        }
Example #13
0
 public ScrapeSession(
     string source,
     ScraperType type,
     DateTime?scrapeFrom,
     List <string> movieImdbCodes,
     List <string> localImdbCodes,
     MolliesMoviesContext context,
     ISystemClock clock,
     CancellationToken cancellationToken,
     MovieOptions options)
 {
     ScrapeFrom         = scrapeFrom;
     _source            = source;
     _type              = type;
     MovieImdbCodes     = movieImdbCodes;
     LocalImdbCodes     = localImdbCodes;
     _context           = context;
     _scrapeDate        = clock.UtcNow;
     _cancellationToken = cancellationToken;
     _options           = options;
 }
 public static IWebScraper CreateWebScraperInstance(ScraperType scraperType) => new ScraperFactory().CreateWebScraper(scraperType);
Example #15
0
        public string showImgPickerForPlateformeDialog(Systeme title, string themename, ScraperType scraperType)
        {
            ModalWindow modalWindow = new ModalWindow();
            var         vm          = new GetPictureForSystemViewModel(title, themename, scraperType);

            modalWindow.DataContext = vm;
            if (modalWindow.ShowDialog().Value)
            {
                return(vm.ResultPath);
            }
            return(null);
        }
Example #16
0
 public ScrapeInfo(UInt32 a, UInt32 b, UInt32 c, ScraperType type)
 {
     if (type == ScraperType.HTTP)
     {
         Complete = a;
         Downloaded = b;
         Incomplete = c;
     }
     else if (type == ScraperType.UDP)
     {
         Seeders = a;
         Complete = b;
         Leachers = c;
     }
 }
Example #17
0
        //Will load a dictionary that will associate moniker arguments with its uri and web scraping type it will use
        public Dictionary <string, (string Uri, ScraperType ScraperType)> LoadMonikerUriMappingDictionary()
        {
            //Ensure MonikerURI mapping property is present in the configuration file
            if (!m_configurationInstance.TryGetValue(ConfigOptions.MonikerUriMapping, out _))
            {
                throw new Exception(ConfigManipulatorErrorMessage.EnsureMonikerUriMappingInConfigFile);
            }

            Dictionary <string, (string Uri, ScraperType ScraperType)> monikerUriMapping = new Dictionary <string, (string, ScraperType)>();

            //Collect the collection of moniker uri mapping items
            JArray jsonNameAndUriMappingCollection = JArray.FromObject(m_configurationInstance[ConfigOptions.MonikerUriMapping]);

            //ToDo - Load moniker uri mapping item properties generically from a property setting
            string[] monikerUriMappingProperties = new string[] { MonikerUriMappingProperty.MonikerName, MonikerUriMappingProperty.Uri, MonikerUriMappingProperty.ScraperType };

            foreach (JToken mappingItem in jsonNameAndUriMappingCollection)
            {   //Change JToken mapping item to a JObject to provide simplified access to its properties
                JObject mappingItemObject = JObject.FromObject(mappingItem);

                //Validate the MonikerUriItem structure is valid - if any test fails then the property will not be valid
                foreach (string propertyName in monikerUriMappingProperties)
                {
                    bool validProperty = true;
                    //A property name should be present in the configuration file
                    validProperty = (mappingItemObject.TryGetValue(propertyName, out JToken parsedProperty)) ? validProperty : false;
                    //There should be a value for the property
                    validProperty = (!string.IsNullOrEmpty(parsedProperty?.ToString())) ? validProperty : false;

                    if (!validProperty)
                    {
                        throw new Exception(ConfigManipulatorErrorMessage.InvalidMonikerUriMappingItem);
                    }
                }

                ScraperType selectedScraperType = default;

                //Try to see if the value of the ScraperType is identified by the application
                if (!Enum.TryParse(mappingItemObject[MonikerUriMappingProperty.ScraperType].ToString(), ignoreCase: true, out ScraperType parsedScraperType))
                {
                    selectedScraperType = ScraperType.Unidentified;
                }

                //If the provided scraper type is not unidentified then update the selectedScraper type value
                if (parsedScraperType != ScraperType.Unidentified)
                {
                    selectedScraperType = parsedScraperType;
                }

                //The provided moniker name must be unique
                if (monikerUriMapping.ContainsKey(mappingItemObject[MonikerUriMappingProperty.MonikerName].ToString()))
                {
                    throw new Exception(ConfigManipulatorErrorMessage.DuplicateMappingItemDetected);
                }

                //Store the new valid and unique moniker uri mapping
                monikerUriMapping.Add(mappingItemObject[MonikerUriMappingProperty.MonikerName].ToString(), (mappingItemObject[MonikerUriMappingProperty.Uri].ToString(), selectedScraperType));
            }

            //Valid moniker uri mappings are expected by the application
            if (monikerUriMapping.Count == 0)
            {
                throw new Exception(ConfigManipulatorErrorMessage.MonikerUriMappingInvalidFormat);
            }

            return(monikerUriMapping);
        }