Skip to main content

automateYT is lightweight library that automates downloading of youtube videos, subtitles (if available) and playlist.

Project description

automateYT

automateYT is lightweight library for automating to download youtube videos, subtitles (if available) and playlist.

Installation

automateYT requires an installation of python 3.6 or greater and pytube, as well as pip. Pip is typically bundled with python installations, and you can find options for how to install python at https://python.org.

  • To install from pypi with pip:
pip install automateYT
  • Clone GitHub repository
git clone https://github.com/umutambyi-gad/automateYT

Overview

Classes:

Methods:

Usage

First of all import Automate class from automateYT

from automateYT import Automate

Quick demo: let's say you want to download three videos and their subtitles after two hours and half and when it's done the computer shuts down itself

from automateYT import Automate
from automateYT import Timing

Timing().after('2h-30m') # or Automate().after('2h-30m') since Automate extends Timing
Automate([
	'https://www.youtube.com/watch?v=XqZsoesa55w',
	'https://www.youtube.com/watch?v=F4tHL8reNCs',
	'https://www.youtube.com/watch?v=F4tHL8reNCs'
]).download(subtitle=True, location='C:/Users/GentleMan/videos', shutdown=True)

The above script will download all given videos and output them on C:/Users/GentleMan/videos but if you didn't specify location by default will in the Downloads and also script will pick the highest resolution available but what if you want to customize the videos' resolution just see the following example.

Automate(url_with_res={
	'https://www.youtube.com/watch?v=XqZsoesa55w': '720p',
	'https://www.youtube.com/watch?v=F4tHL8reNCs': '1080p',
	'https://www.youtube.com/watch?v=F4tHL8reNCs': '144p'
}).download(subtitle=True, shutdown=True)

Watch closely before passing dict where keys are valid watch urls and values are valid resolution I passed an argument called url_with_res it's an obligation to pass argument before the dict otherwise it will raise an error but cool thing is that you don't have to memorize this url_with_res you can simply rename it to whatever you want without any further configurations just like.

Automate(watchUrls_with_their_resolution={
    'https://www.youtube.com/watch?v=XqZsoesa55w': '720p',
    ...
})...

Now you saw how to download them but we have passed watch url on in Automate class like Automate('https://www.youtube.com/watch?v=XqZsoesa55w') so what makes you think it's the true watch url here is how you can view major information about the watch url.

info = Automate(
    'https://www.youtube.com/watch?v=XqZsoesa55w'
).info()
print(info)

Output will be something like -

[
    {
        "watch_url": "https://www.youtube.com/watch?v=XqZsoesa55w",
        "video_id": "XqZsoesa55w",
        "title": "Baby Shark Dance | #babyshark Most Viewed Video | Animal Songs | PINKFONG Songs for Children",
        "thumbnail_url": "https://i.ytimg.com/vi/XqZsoesa55w/maxresdefault.jpg",
        "author": "Pinkfong! Kids' Songs & Stories",
        "publish_date": "2016-06-17",
        "type": "video/mp4",
        "filesize": "11.4MiB",
        "available_resolution": [
            "144p",
            "240p",
            "360p",
            "480p",
            "720p",
            "1080p"
        ],
        "highest_resolution": "1080p",
        "lowest_resolution": "360p",
        "views": "8,350,191,773",
        "rating": 3.7,
        "age_restricted": false
    }
]

As you can see the output above is in json format but what if you prefer yaml format than json just pass keyword string yaml as an argument in the info like -

info = Automate(
    ('https://www.youtube.com/watch?v=XqZsoesa55w',)
).info('yaml')
print(info)

Output will be in yaml format -

-   age_restricted: false
    author: Pinkfong! Kids' Songs & Stories
    available_resolution:
    - 144p
    - 240p
    - 360p
    - 480p
    - 720p
    - 1080p
    filesize: 11.4MiB
    highest_resolution: 1080p
    lowest_resolution: 360p
    publish_date: '2016-06-17'
    rating: 3.7
    thumbnail_url: https://i.ytimg.com/vi/XqZsoesa55w/maxresdefault.jpg
    title: 'Baby Shark Dance | #babyshark Most Viewed Video | Animal Songs | PINKFONG
        Songs for Children'
    type: video/mp4
    video_id: XqZsoesa55w
    views: 8,350,191,773
    watch_url: https://www.youtube.com/watch?v=XqZsoesa55w

And we all know that youtube can have playlist which contains couple of videos, the following is how you can generate watch urls of every single video from the playlist.

from pprint import pprint

watchUrls = Automate(
    "https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n"
).generate_watch_url_from_playlist()
pprint(watchUrls)

An output will be something like -

[
    'https://www.youtube.com/watch?v=F9TZb0XBow0',
    'https://www.youtube.com/watch?v=26VtIlzEcmU',
    'https://www.youtube.com/watch?v=41qgdwd3zAg',
    ...
]

So not only you can generate watch urls from playlist url but also you can download them all or provide an integer limit argument to limit videos to be downloaded from the playlist.

Automate(
    "https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n"
).download_playlist(limit=10)

Remember if you don't specify location by default will be in Downloads don't worry about on what platform you are on. and also you can download their subtitles to by passing this subtitle=True argument.

Documentation

Timing

class for converting string time looks like (2h:30m, 2h30m, or 2h-30m) into seconds and delay time

Automate

Class with methods for automating to download youtube videos as either videos or audios, subtitles (if available) and generating watch urls from youtube playlist.

Automate(*urls: tuple or list,**urls_with_res: dict)

:param: list or tuple urls:
         valid list or tuple of YouTube watch URLs.

:param: dict urls_with_res:
         dict where keys are valid YouTube watch URLs and values are valid video resolutions.

after

Method for delaying time which are in format of human readable time (2h:30m)

Timing().after('20m:15s')

:param: str time
         string time for delaying which written in human readable format - ex. 2h:30m or 2h-30m or 30s where h -> hours, m -> minutes and s -> second

info

Method for giving some useful information about the youtube videos in easy and readable format.

Automate('https://www.youtube.com/watch?v=XqZsoesa55w').info()

-- or --

Automate('https://www.youtube.com/watch?v=XqZsoesa55w').info('yaml')

:param: str fmt
         String ftm (format) controls the return type by default is json and other available format is yaml
:rtype: yaml or json

generate_watch_url_from_playlist

Method for generating valid youtube watch urls from the youtube playlist

Automate(
    'https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n'
).generate_watch_url_from_playlist()

:rtype: list

download

Method for downloading of custom resolution YouTube videos as videos or audio and also subtitles (if available)

Automate(
    'https://www.youtube.com/watch?v=XqZsoesa55w',
).download(
    subtitle=True,
    location='C:/Users/GentleMan/videos',
    only_audio=True,
    shutdown=True
)

:param: str location
         location path on your computer to save the downloads, by default is in Downloads

:param: bool highest_res
         if highest_res is True the script gets the highest resolution available

:param: bool lowest_res
         if lowest_res is True the script gets the lowest resolution available

:param: bool subtitle
         if subtitle is True english version or english auto generated subtitle is downloaded within its video

:param: bool shutdown
         if shutdown is True the computer shuts down after downloads is completely done

:param: bool only_audio
         if only_audio is True audio only is downloaded

download_subtitle

Method for downloading YouTube video's subtitles (if available) or auto generated one in whatever language

Automate(
    'https://www.youtube.com/watch?v=XqZsoesa55w',
).download(
    location='C:/Users/GentleMan/videos',
    lang_code='en',
    auto_generated=False,
    shutdown=True
)

:param: str lang_code
         language code of the subtitle to automate its downloading notice that the default is 'en' (English).

:param: str auto_generated
         by default True, this downloads auto generated version of the same language code in absence of offical one.

:param: str location
         location on your computer to save the downloads, by default is in Downloads.

:param: bool shutdown
         if shutdown is True the computer shuts down after downloads is completely done.

download_playlist

Method for downloading youtube playlist till the limit given is reached

Automate(
    "https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n"
).download_playlist(
    limit=30
)

:param: str location
         location on your computer to save the downloads, by default is in Downloads.

:param: bool highest_res
         if highest_res is True the script gets the highest resolution available.

:param: bool lowest_res
         if lowest_res is True the script gets the lowest resolution available.

:param: int limit
         integer limit limits the number of the videos to be downloaded.

:param: bool subtitle
         if subtitle is True english version or english auto generated subtitle is downloaded within its video.

:param: bool shutdown
         if shutdown is True the computer shuts down after downloads is completely done.

License

This project is under the MIT license

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

automateYT-1.0.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

automateYT-1.0.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file automateYT-1.0.0.tar.gz.

File metadata

  • Download URL: automateYT-1.0.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.8.0 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for automateYT-1.0.0.tar.gz
Algorithm Hash digest
SHA256 36b6f8f0e132d4947d6d3de8e784fcbda58617f9598d7b4a0be9e73dfc00ee94
MD5 27f07158734f7f8dfea3cb422034ca91
BLAKE2b-256 a9afe2bf9c2a6dead74bfe3037c3cae81f39dee20f08ce687203490885ac42f0

See more details on using hashes here.

File details

Details for the file automateYT-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: automateYT-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.8.0 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for automateYT-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc8df554a06e1083e806287ee07c6887cb7e4c6c29013326d81be072d71e7909
MD5 f6a4b4ca35e86744382e467a48387e89
BLAKE2b-256 9d7b61f033875d5f125a41be7bd221c280706302c11bd859db726d4b9c89dbed

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page