Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

YouTube MP4 Downloader [Source Code]

Close close close close close close
1) you're declaring the useragent everywhere you need it, just store in a constant variable.
2) try name your textbox's.
3) when you catch all exceptions, do something with them, don't just ignore them.
3) use url encoding.
4) dont just assume the response was json, check the content-type header.
5) why is the main project called "tests?" lol
(Dec 26, 2017 09:37 PM)eithan1231 Wrote:  4) dont just assume the response was json, check the content-type header.

If JSON is returned as standard I wouldn't bother.
(Dec 27, 2017 05:45 AM)Owl Wrote:  If JSON is returned as standard I wouldn't bother.

If the url has changed?
If the url is beeing redirected?
If it throws an error like unreachable?
Many other things...
(Dec 27, 2017 07:28 AM)abratar Wrote:  If the url has changed?
If the url is beeing redirected?
If it throws an error like unreachable?
Many other things...

None of which can be determined from the content-type header.
(Dec 27, 2017 07:28 AM)abratar Wrote:  If the url has changed?
If the url is beeing redirected?
If it throws an error like unreachable?
Many other things...

That would be determined all by the HTTP response code. Not any of the headers.

404, 303, 301, etc..

Still it's good pre-validation if you want to avoid potential deserialization issues. I see nothing wrong with adding in sanity checks.

Other notes - SaveFileDialog is IDisposable btw. And that try {} catch {} style is horrible.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Dec 27, 2017 07:28 AM)abratar Wrote:  If it throws an error like unreachable?

Then it would throw a WebException and you can use the WebException.Response property.


On line 123 on the MainForm.cs you are getting the WebResponse object but you are not disposing of it. You are only disposing of the response stream and the stream reader.
The WebRequest by default has the method "GET" set, so no need to set it again.
KeepAlive is by default true, so no need to set it.
You could re-use the code to set WebRequest headers. You could make a (extension-)method for WebRequest that sets the headers automatically, or loads them from a collection and sets them.
ShowDialog() returns a DialogResult enum, you should check if the value is "DialogResult.OK".
And finally, instead of doing TextBox.Text = "" you can do TextBox.Clear().
(Dec 27, 2017 11:28 AM)Ninja Wrote:  Then it would throw a WebException and you can use the WebException.Response property.


On line 123 on the MainForm.cs you are getting the WebResponse object but you are not disposing of it. You are only disposing of the response stream and the stream reader.
The WebRequest by default has the method "GET" set, so no need to set it again.
KeepAlive is by default true, so no need to set it.
You could re-use the code to set WebRequest headers. You could make a (extension-)method for WebRequest that sets the headers automatically, or loads them from a collection and sets them.
ShowDialog() returns a DialogResult enum, you should check if the value is "DialogResult.OK".
And finally, instead of doing TextBox.Text = "" you can do TextBox.Clear().

Some of these are a little too picky but still all fair points. For re-setting default values I don't think there's anything wrong in doing that as it just adds verbosity to the code with no real adverse side effects. Readability is always a nice thing to have so if there's things that are explicit in the code, it isn't always a terrible thing. I think some people sleep better at night too knowing that they don't have to rely on default behavior to stay the same. You never know what minor changes Microsoft makes between framework versions based on feedback of other developers.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Dec 27, 2017 12:04 PM)0xDEAD10CC Wrote:  Some of these are a little too picky but still all fair points. For re-setting default values I don't think there's anything wrong in doing that as it just adds verbosity to the code with no real adverse side effects. Readability is always a nice thing to have so if there's things that are explicit in the code, it isn't always a terrible thing. I think some people sleep better at night too knowing that they don't have to rely on default behavior to stay the same. You never know what minor changes Microsoft makes between framework versions based on feedback of other developers.

True, however, I was just pointing out that they OP does not have to set them. Maybe OP didn't know the default values and thought he had to set them.
FYI the api your using when getting the download route is using a session token (hash) that you got to swap out after abit of time.
Not that hard 2 add since already did it for my version. Also added a playlist download function.

If u need any help adding it just DM me :)
Awesome tips guys. Tyvm, will improve the code.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by jj89XDJun 2, 2026 03:58 AM 2 1,498 Jun 2, 2026 03:58 AM
Last Post: palmer_style2009
[Python] by EdgeDec 13, 2021 02:46 PM 3 239 Dec 13, 2021 02:46 PM
Last Post: Edge
[.NET] by ZeakZNov 17, 2018 09:53 AM 22 817 Nov 17, 2018 09:53 AM
Last Post: ZeakZ