Exemplo n.º 1
0
 async def link(self, ctx: commands.Context, steamID_input: str):
     steamID = SteamID(steamID_input)
     if not steamID.is_valid():
         steamID = from_url(steamID_input, http_timeout=15)
         if steamID is None:
             steamID = from_url(
                 f'https://steamcommunity.com/id/{steamID_input}/',
                 http_timeout=15)
             if steamID is None:
                 raise commands.UserInputError(
                     message='Please enter a valid SteamID or community url.'
                 )
     db = Database('sqlite:///main.sqlite')
     await db.connect()
     await db.execute(
         '''
                     REPLACE INTO users (discord_id, steam_id)
                     VALUES( :discord_id, :steam_id )
                     ''', {
             "discord_id": str(ctx.author.id),
             "steam_id": str(steamID.as_steam2_zero)
         })
     embed = discord.Embed(
         description=
         f'Connected {ctx.author.mention} \n `{steamID.as_steam2}`',
         color=0x00FF00)
     await ctx.send(embed=embed)
Exemplo n.º 2
0
    def test_is_valid(self):
        # default
        self.assertFalse(SteamID().is_valid())
        # id = 0
        self.assertFalse(SteamID(0).is_valid())
        self.assertFalse(SteamID(id=0).is_valid())
        self.assertFalse(SteamID(-50).is_valid())
        self.assertFalse(SteamID(id=-50).is_valid())
        # id > 0
        self.assertTrue(SteamID(5).is_valid())
        # type out of bound
        self.assertFalse(SteamID(1, EType.Max).is_valid())
        # universe out of bound
        self.assertFalse(SteamID(1, universe=EUniverse.Max).is_valid())
        # individual
        self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=0).is_valid())
        self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=1).is_valid())
        self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=2).is_valid())
        self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=3).is_valid())
        self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=4).is_valid())
        self.assertFalse(SteamID(123, EType.Individual, EUniverse.Public, instance=5).is_valid())
        self.assertFalse(SteamID(123, EType.Individual, EUniverse.Public, instance=333).is_valid())
        # clan
        self.assertTrue(SteamID(1, EType.Clan, EUniverse.Public, instance=0).is_valid())
        self.assertFalse(SteamID(1, EType.Clan, EUniverse.Public, instance=1).is_valid())
        self.assertFalse(SteamID(1, EType.Clan, EUniverse.Public, instance=1234).is_valid())

        s = SteamID(123, type=EType.Clan, universe=EUniverse.Public, instance=333)
        self.assertFalse(s.is_valid())
Exemplo n.º 3
0
 async def link(self, ctx: commands.Context, steamID_input: str):
     self.logger.debug(
         f'{ctx.author}: {ctx.prefix}{ctx.invoked_with} {ctx.args[2:]}')
     steamID = SteamID(steamID_input)
     if not steamID.is_valid():
         steamID = from_url(steamID_input, http_timeout=15)
         if steamID is None:
             steamID = from_url(
                 f'https://steamcommunity.com/id/{steamID_input}/',
                 http_timeout=15)
             if steamID is None:
                 raise commands.UserInputError(
                     message='Please enter a valid SteamID or community url.'
                 )
     db = Database('sqlite:///main.sqlite')
     await db.connect()
     await db.execute(
         '''
                     REPLACE INTO users (discord_id, steam_id)
                     VALUES( :discord_id, :steam_id )
                     ''', {
             "discord_id": str(ctx.author.id),
             "steam_id": str(steamID.as_steam2_zero)
         })
     embed = discord.Embed(
         description=
         f'Connected {ctx.author.mention} \n [{steamID.as_steam2}]({steamID_input})',
         color=0x00FF00)
     await ctx.send(embed=embed)
     #add another way to add roles for the users after login.
     #await ctx.author.add_roles(ctx.guild.get_role(808304852676378624))
     self.logger.info(f'{ctx.author} connected to {steamID.as_steam2}')
Exemplo n.º 4
0
def cmd_steamid(args):
    from steam.steamid import SteamID

    if args.s_input.startswith('http'):
        _LOG.debug("Input is URL. Making online request to resolve SteamID")
        s = SteamID.from_url(args.s_input) or SteamID()
    else:
        s = SteamID(args.s_input)

    lines = [
        "SteamID: {s.as_64}",
        "Account ID: {s.as_32}",
        "Type: {s.type} ({stype})",
        "Universe: {s.universe} ({suniverse})",
        "Instance: {s.instance}",
        "Steam2: {s.as_steam2}",
        "Steam2Legacy: {s.as_steam2_zero}",
        "Steam3: {s.as_steam3}",
    ]

    if s.community_url:
        lines += ["Community URL: {s.community_url}"]

    lines += ["Valid: {is_valid}"]

    print("\n".join(lines).format(
        s=s,
        stype=str(s.type),
        suniverse=str(s.universe),
        is_valid=str(s.is_valid()),
    ))
Exemplo n.º 5
0
    def test_is_valid(self):
        # default
        self.assertFalse(SteamID().is_valid())
        # id = 0
        self.assertFalse(SteamID(0).is_valid())
        self.assertFalse(SteamID(id=0).is_valid())
        self.assertFalse(SteamID(-50).is_valid())
        self.assertFalse(SteamID(id=-50).is_valid())
        # id > 0
        self.assertTrue(SteamID(5).is_valid())
        # type out of bound
        self.assertFalse(SteamID(1, EType.Max).is_valid())
        # universe out of bound
        self.assertFalse(SteamID(1, universe=EUniverse.Max).is_valid())
        # individual
        self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=0).is_valid())
        self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=1).is_valid())
        self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=2).is_valid())
        self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=3).is_valid())
        self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=4).is_valid())
        self.assertFalse(SteamID(123, EType.Individual, EUniverse.Public, instance=5).is_valid())
        self.assertFalse(SteamID(123, EType.Individual, EUniverse.Public, instance=333).is_valid())
        # clan
        self.assertTrue(SteamID(1, EType.Clan, EUniverse.Public, instance=0).is_valid())
        self.assertFalse(SteamID(1, EType.Clan, EUniverse.Public, instance=1).is_valid())
        self.assertFalse(SteamID(1, EType.Clan, EUniverse.Public, instance=1234).is_valid())

        s = SteamID(123, type=EType.Clan, universe=EUniverse.Public, instance=333)
        self.assertFalse(s.is_valid())
def main(local_mode = True):
    try:
        steam_path = SteamDataReader.get_steam_installpath()
    except:
        print("Could not find steam install path")
        sys.exit(1)
    print("Steam path:",steam_path)

    

    if local_mode:
        steam_data_reader = SteamDataReaderLocal(steam_path)
        try:
            steamid = steam_data_reader.get_steam_id()
            if not steamid.is_valid():
                steamid = SteamID(input_steamid())
            if not steamid.is_valid():
                print("Invalid steam id")
                sys.exit(2)
            print("SteamID:",steamid.as_32)
            
            
        except Exception as error:
            print(error)
            print("Switch to remote mode")
            local_mode = False


    if not local_mode:
        client = SteamClient()
        if client.cli_login() != EResult.OK:
            print("Login Error")
            sys.exit(3)
        else:
            print("Login Success")

        steam_data_reader = SteamDataReaderRemote(client)

        steamid = client.steam_id
        print("SteamID:",steamid.as_32)
        
    steam_grid_path = STEAM_GRIDPATH.format(steam_path,steamid.as_32)
    if not os.path.isdir(steam_grid_path):
        os.mkdir(steam_grid_path)
    print("Steam grid path:",steam_grid_path)
    missing_cover_app_dict =  steam_data_reader.get_missing_cover_app_dict(not local_mode)
    
    print("Total games missing cover in library:",len(missing_cover_app_dict))
    local_cover_appids = {int(file[:len(file)-5]) for file in os.listdir(steam_grid_path) if re.match(r"^\d+p.(png|jpg)$",file)}
    print("Total local covers found:",len(local_cover_appids))
    local_missing_cover_appids = missing_cover_app_dict.keys() - local_cover_appids
    print("Total missing covers locally:",len(local_missing_cover_appids))
    
    print("Finding covers from steamgriddb.com")
    local_missing_cover_appids = list(local_missing_cover_appids)
    local_missing_cover_appids.sort()
    
    total_downloaded = asyncio.run(download_covers_temp(local_missing_cover_appids,steam_grid_path,missing_cover_app_dict))
    print("Total cover downloaded:",total_downloaded)
Exemplo n.º 7
0
def string_to_steamid(string, resolve_customurl=True):
    try:
        steamid = SteamID(string)
        if not steamid.is_valid() and resolve_customurl:
            steamid = SteamID(
                steam_api.ISteamUser.ResolveVanityURL(vanityurl=string).get(
                    'response', {}).get('steamid'))
        return steamid
    except ValueError:
        return SteamID()
Exemplo n.º 8
0
    def __convert_id(self, given_id: Any) -> str:
        """Converts any steamID format to 32.

        Parameters
        ----------
        given_id : Any
            Given steamID.

        Returns
        -------
        str
            SteamID32

        Raises
        ------
        InvalidSteamID
            Raised when the given ID isn't understood.
        """

        steam_id = SteamID(given_id)
        if not steam_id.is_valid():
            raise InvalidSteamID()

        return steam_id.as_steam2
Exemplo n.º 9
0
def main():
    try:
        steam_path = SteamDataReader.get_steam_installpath()
    except:
        print("Could not find steam install path")
        sys.exit(1)
    print("Steam path:", steam_path)

    parser = argparse.ArgumentParser(
        description=
        'Downloads missing covers for new steam UI. Covers are downloaded from steamgriddb.com'
    )
    parser.add_argument('-l',
                        '--local',
                        action='store_true',
                        dest='local_mode',
                        help='Local mode, this is the default operation.')
    parser.add_argument(
        '-r',
        '--remote',
        action='store_true',
        dest='remote_mode',
        help=
        'Remote mode, if both local and remote are specified, will try local mode first.'
    )
    parser.add_argument('-m',
                        '--minscore',
                        dest='min_score',
                        type=int,
                        default=None,
                        help='Set min score for a cover to be downloaded.')
    parser.add_argument(
        '-s',
        '--styles',
        dest='styles',
        type=str,
        default=None,
        help=
        'Set styles of cover, can be comma separated list of alternate, blurred, white_logo, material or no_logo.'
    )
    parser.add_argument(
        '-o',
        '--overwrite',
        action='store_true',
        dest='overwrite',
        help=
        'Overwrite covers that are already present in local steam grid path.')
    parser.add_argument(
        '-d',
        '--delete-local',
        action='store_true',
        dest='delete_local',
        help='Delete local covers for games that already have official ones.')

    args = parser.parse_args()
    local_mode = True
    remote_fallback = True
    if not args.local_mode and args.remote_mode:
        local_mode = False
    elif args.local_mode and not args.remote_mode:
        remote_fallback = False

    if local_mode:
        steam_data_reader = SteamDataReaderLocal(steam_path)
        try:
            steamid = steam_data_reader.get_steam_id()
            if not steamid.is_valid():
                steamid = SteamID(input_steamid())
            if not steamid.is_valid():
                print("Invalid steam id")
                sys.exit(2)
            print("SteamID:", steamid.as_32)

        except Exception as error:
            print(error)
            if remote_fallback:
                print("Switch to remote mode")
                local_mode = False
            else:
                sys.exit(2)

    if not local_mode:
        client = SteamClient()
        if client.cli_login() != EResult.OK:
            print("Login Error")
            sys.exit(3)
        else:
            print("Login Success")

        steam_data_reader = SteamDataReaderRemote(client)

        steamid = client.steam_id
        print("SteamID:", steamid.as_32)

    steam_grid_path = STEAM_GRIDPATH.format(steam_path, steamid.as_32)
    if not os.path.isdir(steam_grid_path):
        os.mkdir(steam_grid_path)
    print("Steam grid path:", steam_grid_path)
    missing_cover_app_dict = steam_data_reader.get_missing_cover_app_dict(
        not local_mode)

    print("Total games missing cover in library:", len(missing_cover_app_dict))
    local_cover_map = {
        int(file[:len(file) - 5]): file
        for file in os.listdir(steam_grid_path)
        if re.match(r"^\d+p.(png|jpg)$", file)
    }
    local_cover_appids = set(local_cover_map.keys())
    print("Total local covers found:", len(local_cover_appids))
    local_missing_cover_appids = missing_cover_app_dict.keys(
    ) - local_cover_appids
    print("Total missing covers locally:", len(local_missing_cover_appids))
    if args.overwrite:
        local_missing_cover_appids = set(missing_cover_app_dict.keys())

    if args.delete_local:
        local_duplicate_cover_appids = local_cover_appids - missing_cover_app_dict.keys(
        )
        print(
            f'Found {len(local_duplicate_cover_appids)} games already have official covers.'
        )
        for appid in local_duplicate_cover_appids:
            path = os.path.join(steam_grid_path, local_cover_map[appid])
            print(f'Deleting file {path}')
            os.remove(path)

    print("Finding covers from steamgriddb.com")
    local_missing_cover_appids = list(local_missing_cover_appids)
    local_missing_cover_appids.sort()

    total_downloaded = asyncio.run(
        download_covers(local_missing_cover_appids, steam_grid_path,
                        missing_cover_app_dict, args))
    print("Total cover downloaded:", total_downloaded)
Exemplo n.º 10
0
def main(local_mode = True):
    try:
        steam_path = get_steam_installpath()
    except:
        print("Could not find steam install path")
        sys.exit(1)
    print("Steam path:",steam_path)
    local_mode = True

    if local_mode:
        try:

            steamid = SteamID(get_steamid_local(steam_path))
            if not steamid.is_valid():
                steamid = SteamID(input_steamid())
            if not steamid.is_valid():
                sys.exit(2)
            print("SteamID:",steamid.as_32)
            steam_grid_path = STEAM_GRIDPATH.format(steam_path,steamid.as_32)
            if not os.path.isdir(steam_grid_path):
                os.mkdir(steam_grid_path)
            print("Steam grid path:",steam_grid_path)
            print("Reading cached appinfo")
            owned_apps = get_app_details_local(steam_path)
            print("Total apps in library:",len(owned_apps))
            missing_cover_apps =  get_missing_cover_apps(owned_apps)
            missing_cover_appids = set(missing_cover_apps.keys())
        except Exception as error:
            print(error)
            print("Switch to remote mode")
            local_mode = False


    if not local_mode:
        client = SteamClient()
        owned_apps = []
        if client.cli_login() != EResult.OK:
            print("Login Error")
            sys.exit(3)
        else:
            print("Login Success")

        steamid = client.steam_id
        print("SteamID:",steamid.as_32)
        steam_grid_path = STEAM_GRIDPATH.format(steam_path,steamid.as_32)
        if not os.path.isdir(steam_grid_path):
            os.mkdir(steam_grid_path)
        print("Steam grid path:",steam_grid_path)

    
        owned_packageids = get_owned_packages(client)
        print("Total packages in library:",len(owned_packageids))
        owned_packages = get_package_details(client,owned_packageids)
        print("Retriving package details")
        owned_appids = get_appids_from_packages(owned_packages)
        print("Total apps in library:",len(owned_appids))
        if os.path.exists("missingcoverdb.json"):
            with open("missingcoverdb.json",encoding="utf-8") as f:
                missing_cover_apps = {int(appid):value for appid,value in json.load(f).items()}
            print("Loaded database with {} apps missing covers".format(len(missing_cover_apps)))
        else:
            print("Getting app details")
            owned_apps = get_app_details(client,owned_appids)
            missing_cover_apps =  get_missing_cover_apps(owned_apps)
        client.logout()
        missing_cover_appids = set(missing_cover_apps.keys()) & set(owned_appids)
    print("Total games missing cover in library:",len(missing_cover_appids))
    local_cover_appids = {int(file[:len(file)-5]) for file in os.listdir(steam_grid_path) if re.match(r"^\d+p.(png|jpg)$",file)}
    print("Total local covers found:",len(local_cover_appids))
    local_missing_cover_appids = missing_cover_appids - local_cover_appids
    print("Total missing covers locally:",len(local_missing_cover_appids))
    
    print("Finding covers from steamgriddb.com")
    local_missing_cover_appids = list(local_missing_cover_appids)
    total_downloaded = download_covers_temp(local_missing_cover_appids,steam_grid_path,missing_cover_apps)
    print("Total cover downloaded:",total_downloaded)