Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Git diff drivers for Markdown and Python #3343

Closed
wants to merge 2 commits into from

Conversation

cffswb
Copy link
Contributor

@cffswb cffswb commented Apr 7, 2022

Please follow the guide below

  • You will be asked some questions, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your pull request (like that [x])
  • Use Preview tab to see how your pull request will actually look like

Before submitting a pull request make sure you have:

In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check one of the following options:

  • I am the original author of this code and I am willing to release it under Unlicense
  • I am not the original author of this code but it is in public domain or released under Unlicense (provide reliable evidence)

What is the purpose of your pull request?

  • Bug fix
  • Improvement
  • New extractor
  • New feature

Description of your pull request and other information

Git supports displaying more informative diffs for files with suitable diff drivers enabled. By using these diff drivers we can gain some more context on where the modifications are.

Example of Python without "python" diff driver:

diff --git a/yt_dlp/downloader/http.py b/yt_dlp/downloader/http.py
index 591a9b08d..a232168fa 100644
--- a/yt_dlp/downloader/http.py
+++ b/yt_dlp/downloader/http.py
@@ -145,7 +145,8 @@ class HttpFD(FileDownloader):
                             or content_len < range_end)
                         if accept_content_len:
                             ctx.content_len = content_len
-                            ctx.data_len = min(content_len, req_end or content_len) - (req_start or 0)
+                            if content_len or req_end:
+                                ctx.data_len = min(content_len or req_end, req_end or content_len) - (req_start or 0)
                             return
                     # Content-Range is either not present or invalid. Assuming remote webserver is
                     # trying to send the whole file, resume is not possible, so wiping the local file

With "python" diff driver:

diff --git a/yt_dlp/downloader/http.py b/yt_dlp/downloader/http.py
index 591a9b08d..a232168fa 100644
--- a/yt_dlp/downloader/http.py
+++ b/yt_dlp/downloader/http.py
@@ -145,7 +145,8 @@ def establish_connection():
                             or content_len < range_end)
                         if accept_content_len:
                             ctx.content_len = content_len
-                            ctx.data_len = min(content_len, req_end or content_len) - (req_start or 0)
+                            if content_len or req_end:
+                                ctx.data_len = min(content_len or req_end, req_end or content_len) - (req_start or 0)
                             return
                     # Content-Range is either not present or invalid. Assuming remote webserver is
                     # trying to send the whole file, resume is not possible, so wiping the local file

We can see the diff now shows def establish_connection(): instead of class HttpFD(FileDownloader): after the @@.

Example of Markdown without "markdown" diff driver:

diff --git a/README.md b/README.md
index 1aab0ba94..ce5af129e 100644
--- a/README.md
+++ b/README.md
@@ -737,9 +737,6 @@ You can also fork the project on github and run your fork's [build workflow](.gi
     --prefer-insecure                Use an unencrypted connection to retrieve
                                      information about the video (Currently
                                      supported only for YouTube)
-    --user-agent UA                  Specify a custom user agent
-    --referer URL                    Specify a custom referer, use if the video
-                                     access is restricted to one domain
     --add-header FIELD:VALUE         Specify a custom HTTP header and its value,
                                      separated by a colon ":". You can use this
                                      option multiple times
@@ -1866,6 +1863,8 @@ While these options are redundant, they are still expected to be used due to the
     --reject-title REGEX             --match-filter "title !~= (?i)REGEX"
     --min-views COUNT                --match-filter "view_count >=? COUNT"
     --max-views COUNT                --match-filter "view_count <=? COUNT"
+    --user-agent UA                  --add-header "User-Agent:UA"
+    --referer URL                    --add-header "Referer:URL"

With "markdown" diff driver (requires Git 2.27 or later):

diff --git a/README.md b/README.md
index 1aab0ba94..ce5af129e 100644
--- a/README.md
+++ b/README.md
@@ -737,9 +737,6 @@ ## Workarounds:
     --prefer-insecure                Use an unencrypted connection to retrieve
                                      information about the video (Currently
                                      supported only for YouTube)
-    --user-agent UA                  Specify a custom user agent
-    --referer URL                    Specify a custom referer, use if the video
-                                     access is restricted to one domain
     --add-header FIELD:VALUE         Specify a custom HTTP header and its value,
                                      separated by a colon ":". You can use this
                                      option multiple times
@@ -1866,6 +1863,8 @@ #### Redundant options
     --reject-title REGEX             --match-filter "title !~= (?i)REGEX"
     --min-views COUNT                --match-filter "view_count >=? COUNT"
     --max-views COUNT                --match-filter "view_count <=? COUNT"
+    --user-agent UA                  --add-header "User-Agent:UA"
+    --referer URL                    --add-header "Referer:URL"

@pukkandan pukkandan added the docs/meta/cleanup related to docs, code cleanup, templates, devscripts etc label Apr 8, 2022
pukkandan added a commit that referenced this pull request Apr 8, 2022
Authored by: cffswb, danielyli


Co-authored-by: Daniel Li <dan@danielyli.com>
Co-authored-by: cffswb <karte577@gmail.com>
@pukkandan
Copy link
Member

ebc7d3f

@pukkandan pukkandan closed this Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs/meta/cleanup related to docs, code cleanup, templates, devscripts etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants