Provide programmatic access #20
This commit is contained in:
parent
07ef013ce3
commit
e1bed8b1be
|
@ -4,3 +4,33 @@
|
|||
"""delarte - ArteTV downloader."""
|
||||
|
||||
__version__ = "0.1"
|
||||
|
||||
from . import api, hls, muxing
|
||||
from .model import (
|
||||
Metadata,
|
||||
Rendition,
|
||||
RenditionAudio,
|
||||
RenditionSubtitles,
|
||||
Source,
|
||||
Variant,
|
||||
)
|
||||
from .www import parse_url as parse_web_url
|
||||
|
||||
|
||||
def fetch_sources(http_session, target_id, www_lang):
|
||||
"""Fetch a target's sources."""
|
||||
return [
|
||||
source
|
||||
for metadata, master_playlist_url in api.fetch_program_info(
|
||||
http_session, target_id, www_lang
|
||||
)
|
||||
for source in hls.fetch_program_sources(
|
||||
http_session, metadata, master_playlist_url
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def download_source(http_session, source, file_name, progress):
|
||||
"""Download the given source into given file."""
|
||||
with hls.download_source(http_session, source, progress) as local_source:
|
||||
muxing.mux_source(local_source, file_name, progress)
|
||||
|
|
|
@ -14,7 +14,7 @@ import time
|
|||
|
||||
import requests
|
||||
|
||||
from . import api, cli, error, hls, muxing, naming, www
|
||||
from . import cli, download_source, error, fetch_sources, naming, www
|
||||
|
||||
|
||||
class Abort(error.ModuleError):
|
||||
|
@ -147,15 +147,7 @@ def main():
|
|||
|
||||
http_session = requests.sessions.Session()
|
||||
|
||||
sources = [
|
||||
source
|
||||
for metadata, master_playlist_url in api.fetch_program_info(
|
||||
http_session, target_id, www_lang
|
||||
)
|
||||
for source in hls.fetch_program_sources(
|
||||
http_session, metadata, master_playlist_url
|
||||
)
|
||||
]
|
||||
sources = fetch_sources(http_session, target_id, www_lang)
|
||||
|
||||
if not args:
|
||||
print(f"Available versions:")
|
||||
|
@ -178,8 +170,7 @@ def main():
|
|||
progress = create_progress()
|
||||
|
||||
for source, file_name in zip(sources, file_names):
|
||||
with hls.download_source(http_session, source, progress) as local_source:
|
||||
muxing.mux_source(local_source, file_name, progress)
|
||||
download_source(http_session, source, file_name, progress)
|
||||
|
||||
except error.UnexpectedError as e:
|
||||
print(str(e))
|
||||
|
|
Loading…
Reference in New Issue