Beispiel #1
0
def cli(anki_media,
        bookmarks,
        video_no_sound,
        video_no_resize,
        yt,
        yt_quality,
        yt_itag,
        right_duration,
        convert_wav,
        snapshot_dir,
        srt_padding,
        vlc_quiet,
        source,
        start_at):

    # NOTE: FFMPEG creates some temporary files in CWD when generating new files.
    # To make sure the process has persmission to write in CWD, just change CWD to ~/Downloads
    os.chdir(downloads_path())

    scheme = Scheme(hew.action.scheme,
                    hew.core.scheme,
                    hew.stt.scheme,
                    hew.qt5.scheme,
                    hew.vlc.scheme,
                    hew.subtitles.scheme)

    if yt_itag is None:
        # https://gist.github.com/sidneys/7095afe4da4ae58694d128b1034e01e2
        mapping = {'360p': 18, '720p': 22, '1080p': 37}
        yt_itag = mapping[yt_quality]

    if bookmarks is not None:
        bookmarks = sorted(map(int, bookmarks.split(',')))

    ctx = {
        'anki_media': anki_media,
        'bookmarks': bookmarks,
        'video_no_sound': video_no_sound,
        'video_no_resize': video_no_resize,
        'yt': yt,
        'yt_itag': yt_itag,
        'right_duration': right_duration,
        'convert_wav': convert_wav,
        'snapshot_dir': snapshot_dir,
        'srt_padding': srt_padding,
        'vlc_quiet': vlc_quiet,
        'source': source,
        'start_at': start_at,
    }

    scheme.build(ctx)
    sys.exit(ctx['app'].exec_())
Beispiel #2
0
from collections import OrderedDict
from io import StringIO
from pathlib import Path
import re

import click
from moviepy.editor import CompositeVideoClip, TextClip
from moviepy.video.tools.subtitles import SubtitlesClip
import pysrt

from hew.util import Scheme, tempfile_path

scheme = Scheme()

# VLC register subtitles like "Track 1 - [English]"
# The name is determined by VLC on its own,
# so it's different from that of YouTube.
# The only way to handle it is to manually map these names.
LANGUAGES_INTERESTED_IN = [
    {
        'code': 'en',
        'vlc_name': 'English'
    },
    {
        'code': 'en-US',
        'vlc_name': 'en-US'
    },
    {
        'code': 'en-GB',
        'vlc_name': 'en-GB'
    },
Beispiel #3
0
import pkgutil
import sys

from PyQt5.QtCore import QSettings, QEvent
from PyQt5.QtGui import QFont, QFontMetrics, QPixmap, QIcon, QImage
from PyQt5.QtWidgets import QApplication

from hew.qt5 import window, shortcut
from hew.util import Scheme

scheme = Scheme(window.scheme, shortcut.scheme)


@scheme
def app():
    # 'hew' uses 'click' to process commandline arguments
    # On top of that, 'hew' use no additional Qt arguments.
    # So, just pass the first argument(the script path) to QApplication
    # SEE: https://doc.qt.io/qt-5/qapplication.html#QApplication
    argv = sys.argv[:1]
    a = QApplication(argv)

    # NOTE: This is for future use.
    # This doesn't replace the display name "Python" to "hew on macOS
    a.setApplicationName('Hew')

    # Load Icon
    data = pkgutil.get_data('hew', 'hew.png')
    image = QImage.fromData(data)
    pixmap = QPixmap.fromImage(image)
    icon = QIcon(pixmap)