Skip to content

Commit

Permalink
v1.4.1
Browse files Browse the repository at this point in the history
Added argparse
Revert ffmpeg-progress-yield from extras_require to install_requires
Fix ffmpeg-progress-yield name
  • Loading branch information
pizidavi committed Jun 14, 2022
1 parent 3bc5e4e commit b2df90c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 67 deletions.
8 changes: 2 additions & 6 deletions PanoptoDownloader/PanoptoDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
import requests
import urllib.request
from shutil import which

try:
from ffmpeg_progress_yield import FfmpegProgress
use_ffmpeg = which('ffmpeg') is not None
except ImportError:
use_ffmpeg = False
from ffmpeg_progress_yield import FfmpegProgress

from .exceptions import *
from .hls_downloader import hls_downloader
Expand Down Expand Up @@ -41,6 +36,7 @@ def download(uri: str, output: str, callback: callable) -> None:
# raise NotSupported('Extension not supported. Must be one of ' + str(SUPPORTED_FORMATS))

if uri.endswith('master.m3u8'):
use_ffmpeg = which('ffmpeg') is not None
if use_ffmpeg:
command = ['ffmpeg', '-f', 'hls', '-i', uri, '-c', 'copy', output]
ff = FfmpegProgress(command)
Expand Down
73 changes: 37 additions & 36 deletions PanoptoDownloader/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import os
import argparse
import PanoptoDownloader
from tqdm import tqdm


SUPPORTED_FORMATS = PanoptoDownloader.SUPPORTED_FORMATS

parser = argparse.ArgumentParser()
parser.add_argument('URL', type=str, help='URL copied from Panopto-Video-DL-browser')
parser.add_argument('-o', '--output', type=str, default='./output' + SUPPORTED_FORMATS[0], help='Output file path')


def input_yesno(*args) -> bool:
r = None
while r not in ['Y', 'N']:
Expand All @@ -15,43 +23,35 @@ def input_yesno(*args) -> bool:
print('Invalid input. Use Y or N', end='\n\n')


def __main__():
def __main__(args):
print('PanoptoDownloader', end='\n\n')

url = None
while not url:
url = input('URL: ')

while True:
filepath = None
while not filepath:
filepath = input('\nOUTPUT file: ')

if os.path.isdir(filepath):
print('ERROR. Cannot be a folder')
continue
if not os.path.isdir(os.path.split(filepath)[0] or './'):
print('ERROR. Folder does not exist')
continue

extension = os.path.splitext(filepath)[1]
if not extension or extension == '.':
filepath += PanoptoDownloader.SUPPORTED_FORMATS[0] if filepath[-1] != '.' else \
PanoptoDownloader.SUPPORTED_FORMATS[0][1:]

if os.path.exists(filepath):
print('File already exist')
result = input_yesno('Replace it [Y, n]? ')
if result:
os.remove(filepath)
else:
continue
if os.path.splitext(filepath)[1] not in PanoptoDownloader.SUPPORTED_FORMATS:
print('Extension not officially supported. Choose from: ' + str(PanoptoDownloader.SUPPORTED_FORMATS))
result = input_yesno('Continue anyway [Y, n]? ')
if not result:
continue
break
url = args.URL
filepath = args.output

if os.path.isdir(filepath):
print('ERROR. Cannot be a folder')
exit(1)
if not os.path.isdir(os.path.split(filepath)[0] or './'):
print('ERROR. Folder does not exist')
exit(1)

extension = os.path.splitext(filepath)[1]
if not extension or extension == '.':
filepath += SUPPORTED_FORMATS[0] if filepath[-1] != '.' else SUPPORTED_FORMATS[0][1:]

if os.path.exists(filepath):
print('File already exist')
result = input_yesno('Replace it [Y, n]? ')
if result:
os.remove(filepath)
else:
exit(1)
if os.path.splitext(filepath)[1] not in SUPPORTED_FORMATS:
print('Extension not officially supported. Choose from: ' + str(SUPPORTED_FORMATS))
result = input_yesno('Continue anyway [Y, n]? ')
if not result:
exit(1)

print(f'\nDownload started: {filepath}\n')

Expand All @@ -76,7 +76,8 @@ def callback(progress: int) -> None:

def main():
try:
__main__()
args = parser.parse_args()
__main__(args)
except KeyboardInterrupt:
print('\nProgram closed')

Expand Down
2 changes: 1 addition & 1 deletion PanoptoDownloader/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.4.0'
__version__ = '1.4.1'
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Download video from Panopto!
## Prerequisites

- [Panopto-Video-DL-browser](https://github.com/Panopto-Video-DL/Panopto-Video-DL-browser)
- [FFmpeg](https://ffmpeg.org/download.html) (Optional. See [below](#ffmpeg))
**Note**: FFmpeg **must** be added in the _system PATH_
- Python >= 3.7

## Install
Expand All @@ -14,25 +16,18 @@ Run the command:
pip install git+https://github.com/Panopto-Video-DL/Panopto-Video-DL-lib#egg=PanoptoDownloader
```

### FFmpeg extension
### FFmpeg

Since version 1.4.0 _FFmpeg is no longer needed_, but it is still possible to download video
using [ffmpeg](https://ffmpeg.org/download.html) by adding `[ffmpeg]` to the pip command used to install it.
```shell
pip install git+https://github.com/Panopto-Video-DL/Panopto-Video-DL-lib#egg=PanoptoDownloader[ffmpeg]
```

**Note**: FFmpeg **must** be added in the _system PATH_
Since version 1.4.0 FFmpeg is _no longer needed_, but it is highly recommended.
It is possible that some videos will not download properly without FFmpeg.

## Usage

- In a new terminal run the command:
Run the command:

```shell
panoptodownloader
panoptodownloader URL [-o OUTPUT]
```
- Paste the link automatically copied from [Panopto-Video-DL-browser](https://github.com/Panopto-Video-DL/Panopto-Video-DL-browser)
- Set the destination folder
- Wait for the download to finish

## Use as Python Module

Expand Down
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

with open('./README.md', 'r') as fp:
long_description = fp.read()
with open('requirements.txt', 'r') as fp:
install_requires = fp.read().strip().split('\n')


setup(
name='PanoptoDownloader',
Expand All @@ -20,10 +17,13 @@
license='MIT',
packages=find_packages(),
python_requires='>=3.7',
install_requires=install_requires,
extras_require={
'ffmpeg': ['ffmpeg_progress_yield']
},
install_requires=[
'ffmpeg-progress-yield~=0.2.0',
'requests~=2.27.1',
'pycryptodomex~=3.12.0',
'yarl~=1.7.2',
'tqdm~=4.62.2'
],
entry_points="""
[console_scripts]
panoptodownloader=PanoptoDownloader.__main__:main
Expand Down

0 comments on commit b2df90c

Please sign in to comment.