Skip to content

Commit

Permalink
Merge branch 'soimort:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ifui authored Jan 9, 2024
2 parents c7e5a29 + 9f38d7d commit dfac58a
Show file tree
Hide file tree
Showing 21 changed files with 427 additions and 337 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: develop

Expand All @@ -16,12 +15,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10", pypy3]
python-version: [3.7, 3.8, 3.9, '3.10', '3.11', pypy-3.8, pypy-3.9]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ install:
$(SETUP) install --user --prefix=

release:
zenity --question
$(SETUP) sdist bdist_wheel upload --sign
#zenity --question
$(SETUP) sdist bdist_wheel
echo 'Upload new version to PyPI using:'
echo ' twine upload --sign dist/you-get-VERSION.tar.gz dist/you_get-VERSION-py3-none-any.whl'
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
[![PyPI version](https://img.shields.io/pypi/v/you-get.svg)](https://pypi.python.org/pypi/you-get/)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/soimort/you-get?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

**NOTICE: Read [this](https://github.com/soimort/you-get/blob/develop/CONTRIBUTING.md) if you are looking for the conventional "Issues" tab.**
**NOTICE (30 May 2022): Support for Python 3.5, 3.6 and 3.7 will eventually be dropped. ([see details here](https://github.com/soimort/you-get/wiki/TLS-1.3-post-handshake-authentication-(PHA)))**

**NOTICE (8 Mar 2019): Read [this](https://github.com/soimort/you-get/blob/develop/CONTRIBUTING.md) if you are looking for the conventional "Issues" tab.**

---

Expand Down Expand Up @@ -53,9 +55,9 @@ Are you a Python programmer? Then check out [the source](https://github.com/soim

### Prerequisites

The following dependencies are necessary:
The following dependencies are recommended:

* **[Python](https://www.python.org/downloads/)** 3.2 or above
* **[Python](https://www.python.org/downloads/)** 3.7.4 or above
* **[FFmpeg](https://www.ffmpeg.org/)** 1.0 or above
* (Optional) [RTMPDump](https://rtmpdump.mplayerhq.hu/)

Expand Down Expand Up @@ -89,6 +91,14 @@ $ python3 setup.py install --user

to install `you-get` to a permanent path.

You can also use the [pipenv](https://pipenv.pypa.io/en/latest) to install the `you-get` in the Python virtual environment.

```
$ pipenv install -e .
$ pipenv run you-get --version
you-get: version 0.4.1555, a tiny downloader that scrapes the web.
```

### Option 4: Git clone

This is the recommended way for all developers, even if you don't often code in Python.
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ source <https://github.com/soimort/you-get>`__ and fork it!

.. |PyPI version| image:: https://badge.fury.io/py/you-get.png
:target: http://badge.fury.io/py/you-get
.. |Build Status| image:: https://api.travis-ci.org/soimort/you-get.png
:target: https://travis-ci.org/soimort/you-get
.. |Build Status| image:: https://github.com/soimort/you-get/workflows/develop/badge.svg
:target: https://github.com/soimort/you-get/actions
.. |Gitter| image:: https://badges.gitter.im/Join%20Chat.svg
:target: https://gitter.im/soimort/you-get?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
64 changes: 45 additions & 19 deletions src/you_get/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@
insecure = False
m3u8 = False
postfix = False
prefix = None

fake_headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', # noqa
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'UTF-8,*;q=0.5',
'Accept-Encoding': 'gzip,deflate,sdch',
'Accept-Language': 'en-US,en;q=0.8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.74 Safari/537.36 Edg/79.0.309.43', # noqa
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.183' # Latest Edge
}

if sys.stdout.isatty():
Expand Down Expand Up @@ -342,21 +343,48 @@ def undeflate(data):
return decompressobj.decompress(data)+decompressobj.flush()


# an http.client implementation of get_content()
# because urllib does not support "Connection: keep-alive"
def getHttps(host, url, headers, debuglevel=0):
import http.client

conn = http.client.HTTPSConnection(host)
conn.set_debuglevel(debuglevel)
conn.request("GET", url, headers=headers)
resp = conn.getresponse()
set_cookie = resp.getheader('set-cookie')

data = resp.read()
try:
data = ungzip(data) # gzip
data = undeflate(data) # deflate
except:
pass

conn.close()
return str(data, encoding='utf-8'), set_cookie


# DEPRECATED in favor of get_content()
def get_response(url, faker=False):
logging.debug('get_response: %s' % url)

ctx = None
if insecure:
# ignore ssl errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
# install cookies
if cookies:
opener = request.build_opener(request.HTTPCookieProcessor(cookies))
request.install_opener(opener)

if faker:
response = request.urlopen(
request.Request(url, headers=fake_headers), None
request.Request(url, headers=fake_headers), None, context=ctx,
)
else:
response = request.urlopen(url)
response = request.urlopen(url, context=ctx)

data = response.read()
if response.info().get('Content-Encoding') == 'gzip':
Expand Down Expand Up @@ -987,6 +1015,8 @@ def download_urls(
title = tr(get_filename(title))
if postfix and 'vid' in kwargs:
title = "%s [%s]" % (title, kwargs['vid'])
if prefix is not None:
title = "[%s] %s" % (prefix, title)
output_filename = get_output_filename(urls, title, ext, output_dir, merge)
output_filepath = os.path.join(output_dir, output_filename)

Expand Down Expand Up @@ -1536,9 +1566,13 @@ def print_version():
help='Do not download captions (subtitles, lyrics, danmaku, ...)'
)
download_grp.add_argument(
'--postfix', action='store_true', default=False,
'--post', '--postfix', dest='postfix', action='store_true', default=False,
help='Postfix downloaded files with unique identifiers'
)
download_grp.add_argument(
'--pre', '--prefix', dest='prefix', metavar='PREFIX', default=None,
help='Prefix downloaded files with string'
)
download_grp.add_argument(
'-f', '--force', action='store_true', default=False,
help='Force overwriting existing files'
Expand Down Expand Up @@ -1632,7 +1666,7 @@ def print_version():
download_grp.add_argument('--itag', help=argparse.SUPPRESS)

download_grp.add_argument('-m', '--m3u8', action='store_true', default=False,
help = 'download vide using an m3u8 url')
help = 'download video using an m3u8 url')


parser.add_argument('URL', nargs='*', help=argparse.SUPPRESS)
Expand Down Expand Up @@ -1662,6 +1696,7 @@ def print_version():
global insecure
global m3u8
global postfix
global prefix
output_filename = args.output_filename
extractor_proxy = args.extractor_proxy

Expand Down Expand Up @@ -1699,6 +1734,7 @@ def print_version():
insecure = True

postfix = args.postfix
prefix = args.prefix

if args.no_proxy:
set_http_proxy('')
Expand Down Expand Up @@ -1785,20 +1821,10 @@ def google_search(url):
url = 'https://www.google.com/search?tbm=vid&q=%s' % parse.quote(keywords)
page = get_content(url, headers=fake_headers)
videos = re.findall(
r'<a href="(https?://[^"]+)" onmousedown="[^"]+"><h3 class="[^"]*">([^<]+)<', page
r'(https://www\.youtube\.com/watch\?v=[\w-]+)', page
)
vdurs = re.findall(r'<span class="vdur[^"]*">([^<]+)<', page)
durs = [r1(r'(\d+:\d+)', unescape_html(dur)) for dur in vdurs]
print('Google Videos search:')
for v in zip(videos, durs):
print('- video: {} [{}]'.format(
unescape_html(v[0][1]),
v[1] if v[1] else '?'
))
print('# you-get %s' % log.sprint(v[0][0], log.UNDERLINE))
print()
print('Best matched result:')
return(videos[0][0])
return(videos[0])


def url_to_module(url):
Expand Down
Loading

0 comments on commit dfac58a

Please sign in to comment.