mikf / gallery-dl

Command-line program to download image galleries and collections from several image hosting sites
GNU General Public License v2.0
11.38k stars 929 forks source link

Help with special characters in a PS1 file #2673

Closed a84r7a3rga76fg closed 2 years ago

a84r7a3rga76fg commented 2 years ago

I saved this in a PS1 file

gallery-dl -d 'G:\rips gallery-dl\Artists Kemono TEXT\加瀬大輝' --ig -c 'C:\Users\Administrator\gallery-dl\gallery-dl-KEMONO-TEXT.conf' https://kemono.party/fanbox/user/273185
gallery-dl -d 'G:\rips gallery-dl\Artists Kemono\加瀬大輝' https://kemono.party/fanbox/user/273185

When I run the PS1 file, I'm getting this error

usage: gallery-dl.exe [OPTION]... URL...
gallery-dl.exe: error: unrecognized arguments: https://kemono.party/fanbox/user/273185
[1/2] ‡ãã¨ã‰
[gallery-dl][error] No suitable extractor found for '‡ãã¨ã‰'
[2/2] https://kemono.party/fanbox/user/273185

If someone knows the fix to this, please help me

rautamiekka commented 2 years ago

What did you use to save the PS1 ?

Also: you should have the target folder -d in the config, everything that possibly can be needs to be in the config, preferably in 1 config, that being the main one, since you should be able to script the finer details.

If you need to use subconfigs, take a look at https://github.com/mikf/gallery-dl/issues/2164#issuecomment-1006944666

a84r7a3rga76fg commented 2 years ago

I used Notepad ++, I made sure it was saved as UTF-8 BOM too.

mikf commented 2 years ago

I think it has trouble with the non-ASCII characters (加瀬大輝), possibly due to encoding problems. Try replacing them with some simple ASCII characters as a test and see if it works with that.

BOM

That usually causes more trouble than it's worth. Try plain UTF-8 without BOM or your native system encoding.

a84r7a3rga76fg commented 2 years ago

Tried it with UTF-8, same issue as well. It's strange how typing this in the PS console "gallery-dl -d 'G:\rips gallery-dl\Artists Kemono\加瀬大輝' https://kemono.party/fanbox/user/273185" works just fine but not when it's in a PS1 file.

Hrxn commented 2 years ago

What is your exact Windows version (Like this: Version 10.0.19043.1706)? What is your PowerShell version ($PSVersionTable.PSVersion)?

Also, can you give me the output of the following in your console?

[System.Console]::OutputEncoding
[System.Console]::InputEncoding
a84r7a3rga76fg commented 2 years ago

Windows 10, 21H2, Build 19044, 1706

IsSingleByte      : True
BodyName          : IBM437
EncodingName      : OEM United States
HeaderName        : IBM437
WebName           : IBM437
WindowsCodePage   : 1252
IsBrowserDisplay  : False
IsBrowserSave     : False
IsMailNewsDisplay : False
IsMailNewsSave    : False
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 437
IsSingleByte      : True
BodyName          : IBM437
EncodingName      : OEM United States
HeaderName        : IBM437
WebName           : IBM437
WindowsCodePage   : 1252
IsBrowserDisplay  : False
IsBrowserSave     : False
IsMailNewsDisplay : False
IsMailNewsSave    : False
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 437
Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  1682
Hrxn commented 2 years ago

Okay, Windows version is absolutely fine.

Your PowerShell version is still PS 5.1, aka "Windows PowerShell". That is also fine, it should work as well, is still officially supported etc. But, apparently, it does not seem to work straight out of the box.

So you can try one of the following two things:

  1. You can install the latest PowerShell, aka just "PowerShell", formerly aka "PowerShell Core", currently at version 7.2.4 Where this should work out of the box AFAIK, from here: https://github.com/PowerShell/PowerShell#get-powershell
  2. Make the following changes to your $PROFILE file:

    1. Test if such a file currently exists: Test-Path $PROFILE
    2. If it exists, open the profile file with any editor, or notepad: notepad $PROFILE
    3. If not, create this file: New-Item -Path $PROFILE -ItemType File -Force Careful, -Force will create all missing directories in that path, but also overwrite a file should it already exist there.

      Add these lines:

The output in your console should then show something like this:

PS D:\Temp>
>> [System.Console]::OutputEncoding
>> [System.Console]::InputEncoding
>>

Preamble          :
BodyName          : utf-8
EncodingName      : Unicode (UTF-8)
HeaderName        : utf-8
WebName           : utf-8
WindowsCodePage   : 1200
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
IsSingleByte      : False
EncoderFallback   : System.Text.EncoderReplacementFallback
DecoderFallback   : System.Text.DecoderReplacementFallback
IsReadOnly        : False
CodePage          : 65001

Preamble          :
BodyName          : utf-8
EncodingName      : Unicode (UTF-8)
HeaderName        : utf-8
WebName           : utf-8
WindowsCodePage   : 1200
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
IsSingleByte      : False
EncoderFallback   : System.Text.EncoderReplacementFallback
DecoderFallback   : System.Text.DecoderReplacementFallback
IsReadOnly        : False
CodePage          : 65001

PS D:\Temp>

Then you can try your URL again..

a84r7a3rga76fg commented 2 years ago

Can Powershell 7.2 be installed alongside the pre-installed Powershell?

Hrxn commented 2 years ago

Yes. Edit: That's even the default, i.e. it is supposed to be installed in parallel to the existing Windows PowerShell.

a84r7a3rga76fg commented 2 years ago

I downloaded the 7.2.4 zip package from here and extracted the content to C:\1 and dragged the PS1 file to pwsh.exe and it worked.

How do I create a profile that'll only be used by 7.2.4? Sorry for the noob question, I've just never done this before. Also, Test-Path $PROFILE returned "False" in regular PS and 7.2.4.

Hrxn commented 2 years ago

Test-Path $PROFILE returned "False" in regular PS and 7.2.4.

This simply means that a profile file does not exist, so nothing that gets automatically loaded into every PS session that you start. That is the default on every fresh system, so this is normal.

You can easily create the file with the line mentioned in my comment above (cf. point 2.iii).

The path for the new PowerShell is usually: ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 Whereas the path for Windows PowerShell is: ~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

So they are loading the config from different paths by default, that's the point. But, the thing is, this might depend on your system settings, or if you are part of a domain network or something.

You can easily check by simply running $PROFILE in your console. To be more exact, $PROFILE has four properties that each represent a different path it tries to load a configuration file from, you can pick whatever fits best to your needs, or simply use the path returned by just $PROFILE. (Which should be equal to $PROFILE.CurrentUserCurrentHost)

This is what these properties looks like, for my PS 7:

AllUsersAllHosts       NoteProperty          string AllUsersAllHosts=C:\Program Files\PowerShell\7\profile.ps1
AllUsersCurrentHost    NoteProperty          string AllUsersCurrentHost=C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts    NoteProperty          string CurrentUserAllHosts=C:\Users\Hrxn\OneDrive\Documents\PowerShell\profile.ps1
CurrentUserCurrentHost NoteProperty          string CurrentUserCurrentHost=C:\Users\Hrxns\OneDrive\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

If you extract the ZIP package, you don't get an automatically created shortcut to launch PowerShell, unlike with the MSI installer (which is perfectly fine to use as well), so you have to create the shortcut yourself (a normal, standard Windows shortcut, which can be created for any file).

The correct target is, in your case, something like C:\1\pwsh.exe You can also specify CLI options here, i.e. C:\1\pwsh.exe -NoLogo -SettingsFile <filePath> -WorkingDirectory <directoryPath> and so on..

a84r7a3rga76fg commented 2 years ago

I've installed it with the MSI installer and this works well, thank you.