From f1ddf104809017784aa136ebb8ff7e2cfb96d5f4 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Sun, 11 Oct 2015 00:15:23 +0200 Subject: Changed directory structure to use pyscaffold --- .coveragerc | 23 +++ .gitignore | 45 ++++- AUTHORS.rst | 5 + CHANGES.rst | 4 + README.md | 22 --- README.rst | 36 ++++ docs/Makefile | 177 ++++++++++++++++++ docs/_static/.gitignore | 1 + docs/authors.rst | 2 + docs/changes.rst | 2 + docs/conf.py | 238 ++++++++++++++++++++++++ docs/index.rst | 45 +++++ docs/license.rst | 7 + requirements.txt | 3 + setup.cfg | 74 ++++++++ setup.py | 24 +++ tests/conftest.py | 12 ++ youtube-podcaster | 159 ---------------- youtube-podcaster.json.sample | 10 - youtube/__init__.py | 6 - youtube/downloader.py | 42 ----- youtube/youtube.py | 44 ----- youtube_podcaster/youtube-podcaster | 159 ++++++++++++++++ youtube_podcaster/youtube-podcaster.json.sample | 10 + youtube_podcaster/youtube/__init__.py | 6 + youtube_podcaster/youtube/downloader.py | 42 +++++ youtube_podcaster/youtube/youtube.py | 44 +++++ 27 files changed, 953 insertions(+), 289 deletions(-) create mode 100644 .coveragerc create mode 100644 AUTHORS.rst create mode 100644 CHANGES.rst delete mode 100644 README.md create mode 100644 README.rst create mode 100644 docs/Makefile create mode 100644 docs/_static/.gitignore create mode 100644 docs/authors.rst create mode 100644 docs/changes.rst create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/license.rst create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 tests/conftest.py delete mode 100755 youtube-podcaster delete mode 100644 youtube-podcaster.json.sample delete mode 100644 youtube/__init__.py delete mode 100644 youtube/downloader.py delete mode 100644 youtube/youtube.py create mode 100755 youtube_podcaster/youtube-podcaster create mode 100644 youtube_podcaster/youtube-podcaster.json.sample create mode 100644 youtube_podcaster/youtube/__init__.py create mode 100644 youtube_podcaster/youtube/downloader.py create mode 100644 youtube_podcaster/youtube/youtube.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..142021c --- /dev/null +++ b/.coveragerc @@ -0,0 +1,23 @@ +# .coveragerc to control coverage.py +[run] +branch = True +source = youtube_podcaster +# omit = bad_file.py + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: diff --git a/.gitignore b/.gitignore index 1d7362c..f41c0ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,41 @@ -downloads/ +# Temporary and binary files +*~ +*.py[cod] +*.so +*.cfg +!setup.cfg +*.orig +*.log +*.pot +__pycache__/* +.cache/* +.*.swp -feeds.save -youtube-podcaster.json +# Project files +.ropeproject +.project +.pydevproject +.settings +.idea -*.pyc -*.xml -*.sw? +# Package files +*.egg +*.eggs/ +.installed.cfg +*.egg-info + +# Unittest and coverage +htmlcov/* +.coverage +.tox +junit.xml +coverage.xml + +# Build and docs folder/files +build/* +dist/* +sdist/* +docs/api/* +docs/_build/* +cover/* +MANIFEST diff --git a/AUTHORS.rst b/AUTHORS.rst new file mode 100644 index 0000000..b4de63b --- /dev/null +++ b/AUTHORS.rst @@ -0,0 +1,5 @@ +========== +Developers +========== + +* Tom van der Lee diff --git a/CHANGES.rst b/CHANGES.rst new file mode 100644 index 0000000..889f44c --- /dev/null +++ b/CHANGES.rst @@ -0,0 +1,4 @@ +========= +Changelog +========= + diff --git a/README.md b/README.md deleted file mode 100644 index 8028dfd..0000000 --- a/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# YouTube Podcaster -Lets you covert YouTube-playlists to RSS podcast feeds and serve them. - -## Features -* Check playlists on HTTP-request -* Downloads videos and converts them to Ogg Vorbis files. -* Serve RSS feed - -## What it doesn't do (at the moment) -* Convert to mp3, mp4 or any other audio/video format -* Serve the downloaded audio files (needs to be done by an other server) - -## Dependencies -* [youtube-dl](https://github.com/rg3/youtube-dl) -* [python-feedgen](https://github.com/lkiesow/python-feedgen) - -## To do -* Add comments/documentation -* Support multiple audio/video formats - -## LICENSE -YouTube Podcaster is licensed under the MIT License, see the LICENSE file for more info. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..b485fbb --- /dev/null +++ b/README.rst @@ -0,0 +1,36 @@ +YouTube Podcaster +================= + +Lets you covert YouTube-playlists to RSS podcast feeds and serve them. + +Features +-------- + +- Check playlists on HTTP-request +- Downloads videos and converts them to Ogg Vorbis files. +- Serve RSS feed + +What it doesn't do (at the moment) +---------------------------------- + +- Convert to mp3, mp4 or any other audio/video format +- Serve the downloaded audio files (needs to be done by an other + server) + +Dependencies +------------ + +- `youtube-dl `__ +- `python-feedgen `__ + +To do +----- + +- Add comments/documentation +- Support multiple audio/video formats + +LICENSE +------- + +YouTube Podcaster is licensed under the MIT License, see the LICENSE +file for more info. diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..e8b986c --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,177 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/youtube-podcaster.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/youtube-podcaster.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $HOME/.local/share/devhelp/youtube-podcaster" + @echo "# ln -s $(BUILDDIR)/devhelp $HOME/.local/share/devhelp/youtube-podcaster" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/_static/.gitignore b/docs/_static/.gitignore new file mode 100644 index 0000000..3c96363 --- /dev/null +++ b/docs/_static/.gitignore @@ -0,0 +1 @@ +# Empty directory diff --git a/docs/authors.rst b/docs/authors.rst new file mode 100644 index 0000000..cd8e091 --- /dev/null +++ b/docs/authors.rst @@ -0,0 +1,2 @@ +.. _authors: +.. include:: ../AUTHORS.rst diff --git a/docs/changes.rst b/docs/changes.rst new file mode 100644 index 0000000..257630a --- /dev/null +++ b/docs/changes.rst @@ -0,0 +1,2 @@ +.. _changes: +.. include:: ../CHANGES.rst diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..6467b89 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,238 @@ +# -*- coding: utf-8 -*- +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import inspect +from sphinx import apidoc + + +__location__ = os.path.join(os.getcwd(), os.path.dirname( + inspect.getfile(inspect.currentframe()))) + +package = "youtube_podcaster" +namespace = [] +namespace_pkg = ".".join([namespace[-1], package]) if namespace else package + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', + 'sphinx.ext.autosummary', 'sphinx.ext.viewcode', 'sphinx.ext.coverage', + 'sphinx.ext.doctest', 'sphinx.ext.ifconfig', 'sphinx.ext.pngmath'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'youtube-podcaster' +copyright = u'2015, Tom van der Lee' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '' # Is set by calling `setup.py docs` +# The full version, including alpha/beta/rc tags. +release = '' # Is set by calling `setup.py docs` + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +try: + from namespace_pkg import __version__ as version +except ImportError: + pass +else: + release = version + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = "" + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'youtube_podcaster-doc' + + +# -- Options for LaTeX output -------------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +# 'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +# 'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +# 'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'user_guide.tex', u'youtube-podcaster Documentation', + u'Tom van der Lee', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = "" + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + +# -- External mapping ------------------------------------------------------------ +python_version = '.'.join(map(str, sys.version_info[0:2])) +intersphinx_mapping = { + 'sphinx': ('http://sphinx.pocoo.org', None), + 'python': ('http://docs.python.org/' + python_version, None), + 'matplotlib': ('http://matplotlib.sourceforge.net', None), + 'numpy': ('http://docs.scipy.org/doc/numpy', None), + 'sklearn': ('http://scikit-learn.org/stable', None), + 'pandas': ('http://pandas.pydata.org/pandas-docs/stable', None), + 'scipy': ('http://docs.scipy.org/doc/scipy/reference/', None), +} diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..62a305d --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,45 @@ +================= +youtube-podcaster +================= + +This is the documentation of **youtube-podcaster**. + +.. note:: + + This is the main page of your project's `Sphinx `_ + documentation. It is formatted in `reStructuredText + `__. Add additional pages by creating + rst-files in ``docs`` and adding them to the `toctree + `_ below. Use then + `references `__ in order to link + them from this page, e.g. :ref:`authors ` and :ref:`changes`. + It is also possible to refer to the documentation of other Python packages + with the `Python domain syntax + `__. By default you + can reference the documentation of `Sphinx `__, + `Python `__, `matplotlib + `__, `NumPy + `__, `Scikit-Learn + `__, `Pandas + `__, `SciPy + `__. You can add more by + extending the ``intersphinx_mapping`` in your Sphinx's ``conf.py``. + +Contents +======== + +.. toctree:: + :maxdepth: 2 + + License + Authors + Changelog + Module Reference + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/license.rst b/docs/license.rst new file mode 100644 index 0000000..943758d --- /dev/null +++ b/docs/license.rst @@ -0,0 +1,7 @@ +.. _license: + +======= +License +======= + +.. literalinclude:: ../LICENSE diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bee56c1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +# Add your requirements here like: +youtube-dl +feedgen diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..1d3b7c5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,74 @@ +[metadata] +name = youtube-podcaster +summary = Converts youtube playlists to RSS-feeds +author = Tom van der Lee +author-email = t0m.vd.l33@gmail.com +license = MIT License +home-page = http://github.com/tomvanderlee/youtube-podcaster +description-file = README.rst +# Add here all kinds of additional classifiers as defined under +# https://pypi.python.org/pypi?%3Aaction=list_classifiers +classifiers = Development Status :: 3 - Alpha, + License :: OSI Approved :: MIT License + Programming Language :: Python :: 3 :: Only + +[entry_points] +# Add here console scripts like: +# console_scripts = +# hello_world = youtube_podcaster.module:function +# as well as other entry_points. + + +[files] +# Add here 'data_files', 'packages' or 'namespace_packages'. +# Additional data files are defined as key value pairs of source and target: +packages = + youtube_podcaster +# data_files = +# share/youtube_podcaster_docs = docs/* + +[extras] +# Add here additional requirements for extra features, like: +# PDF = +# ReportLab>=1.2 +# RXP + +[test] +# py.test options when running `python setup.py test` +addopts = tests + +[pytest] +# Options for py.test: +# Specify command line options as you would do when invoking py.test directly. +# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml +# in order to write a coverage file that can be read by Jenkins. +addopts = + --cov youtube_podcaster --cov-report term-missing + --verbose + +[aliases] +docs = build_sphinx + +[bdist_wheel] +# Use this option if your package is pure-python +universal = 1 + +[build_sphinx] +source_dir = docs +build_dir = docs/_build + +[pbr] +# Let pbr run sphinx-apidoc +autodoc_tree_index_modules = True +# autodoc_tree_excludes = ... +# Let pbr itself generate the apidoc +# autodoc_index_modules = True +# autodoc_exclude_modules = ... +# Convert warnings to errors +# warnerrors = True + +[devpi:upload] +# Options for the devpi: PyPI serer and packaging tool +# VCS export must be deactivated since we are using setuptools-scm +no-vcs = 1 +format = bdist_wheel diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..3ec3131 --- /dev/null +++ b/setup.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" + Setup file for youtube_podcaster. + + This file was generated with PyScaffold 2.4.2, a tool that easily + puts up a scaffold for your new Python project. Learn more under: + http://pyscaffold.readthedocs.org/ +""" + +import sys +from setuptools import setup + + +def setup_package(): + needs_sphinx = {'build_sphinx', 'upload_docs'}.intersection(sys.argv) + sphinx = ['sphinx'] if needs_sphinx else [] + setup(setup_requires=['six', 'pyscaffold>=2.4rc1,<2.5a0'] + sphinx, + tests_require=['pytest_cov', 'pytest'], + use_pyscaffold=True) + + +if __name__ == "__main__": + setup_package() diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..1a40d64 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" + Dummy conftest.py for youtube_podcaster. + + If you don't know what this is for, just leave it empty. + Read more about conftest.py under: + https://pytest.org/latest/plugins.html +""" +from __future__ import print_function, absolute_import, division + +import pytest diff --git a/youtube-podcaster b/youtube-podcaster deleted file mode 100755 index bb2db26..0000000 --- a/youtube-podcaster +++ /dev/null @@ -1,159 +0,0 @@ -#!/usr/bin/env python3 -import time -import os -import pickle -import json - -from http.server import HTTPServer, BaseHTTPRequestHandler -from hashlib import sha1 - -from feedgen.feed import FeedGenerator - -import youtube - - -class PodcastUpdater: - instance = None - - def get_instance(): - if PodcastUpdater.instance: - return PodcastUpdater.instance - else: - PodcastUpdater.instance = PodcastUpdater() - return PodcastUpdater.instance - - def __init__(self): - self.podcasts = config["podcasts"] - - self.feeds_file = "feeds.save" - if os.path.isfile(self.feeds_file): - with open(self.feeds_file, "rb") as feeds: - self.feeds = pickle.load(feeds) - else: - self.feeds = {} - - def get_xml(self, channel, playlist): - channel = channel.replace('_', ' ') - playlist = playlist.replace('_', ' ') - - for podcast in self.podcasts: - if podcast["username"] == channel: - break - else: - return None - - if playlist not in podcast["playlists"]: - return None - - xml = self.update_podcast(channel, playlist) - - if xml: - return open(xml).read() - - def update_podcast(self, channel, playlist): - feed_id = sha1(bytes("%s %s" % (channel, playlist), "UTF-8")).hexdigest() - yt_channel = yt.get_channel(channel)[0] - yt_playlists = yt.get_playlists(yt_channel, 50) - - for yt_playlist in yt_playlists: - if yt_playlist["snippet"]["title"] == playlist: - break - else: - return None - - if feed_id in self.feeds: - feed = self.feeds[feed_id] - else: - feed = self.add_feed(feed_id, yt_playlist) - - if feed.last_updated < time.time() - 600: - self.populate_feed(feed, feed_id, yt_playlist) - - feed_file = "%s.xml" % (feed_id) - self.feeds[feed_id].rss_file(feed_file) - - with open(self.feeds_file, "wb") as feed: - pickle.dump(self.feeds, feed) - - return "%s.xml" % (feed_id) - - def add_feed(self, feed_id, yt_playlist): - feed = FeedGenerator() - feed.load_extension("podcast") - feed.id(feed_id) - feed.title(yt_playlist["snippet"]["title"]) - feed.author({"name": yt_playlist["snippet"]["channelTitle"]}) - feed.description(yt_playlist["snippet"]["description"]) - feed.logo(yt_playlist["snippet"]["thumbnails"]["standard"]["url"]) - feed.link(href="https://www.youtube.com/playlist?list=%s" % (yt_playlist["id"])) - feed.rss_str(pretty=True) - feed.last_updated = 0 - self.feeds[feed_id] = feed - return feed - - def populate_feed(self, feed, feed_id, yt_playlist, max_results=5): - videos = yt.get_playlist_items(yt_playlist, max_results) - downloader = youtube.Downloader.get_instance("vorbis", "downloads", "192.168.178.100") - - entries = feed.entry() - for video in videos: - video_id = sha1(bytes(video["id"], "UTF-8")).hexdigest() - for entry in entries: - if entry.id() == video_id: - break - else: - url, size, mime = downloader.download(video, video_id, feed_id) - feed_entry = feed.add_entry() - feed_entry.id(video_id) - feed_entry.guid(video_id) - feed_entry.title(video["snippet"]["title"]) - feed_entry.description(video["snippet"]["description"]) - feed_entry.published(video["snippet"]["publishedAt"]) - feed_entry.enclosure(url, size, mime) - - feed.last_updated = time.time() - - -class PodcastFeeder(BaseHTTPRequestHandler): - def do_GET(self): - updater = PodcastUpdater.get_instance() - path = self.path.split('/') - - if len(path) == 3: - channel = path[1] - playlist = path[2] - else: - return self.return_error(404) - - xml = updater.get_xml(channel, playlist) - - if not xml: - return self.return_error(404) - else: - self.send_response(200) - self.send_header("Content-type", "text/xml") - self.end_headers() - self.wfile.write(bytes(xml, 'UTF-8')) - - def return_error(self, code): - self.send_response(code) - self.send_header("Content-type", "text/html") - self.end_headers() - - reponse = "Error: %s" % (code) - self.wfile.write(bytes(reponse, 'UTF-8')) - - -def main(): - try: - server = HTTPServer(("", 8888), PodcastFeeder) - server.serve_forever() - except KeyboardInterrupt: - server.socket.close() - -if __name__ == "__main__": - config = json.load(open("youtube-podcaster.json")) - yt = youtube.Youtube(config["youtube"]["api-key"]) - main() - -# vim: set ts=8 sw=4 tw=0 et : diff --git a/youtube-podcaster.json.sample b/youtube-podcaster.json.sample deleted file mode 100644 index d9d078f..0000000 --- a/youtube-podcaster.json.sample +++ /dev/null @@ -1,10 +0,0 @@ -{ - "youtube": { - "api-key": "youtube-api-v3-key-here" - }, - - "podcasts": [{ - "username": "youtube-username-here", - "playlists": ["playlist-name-here"] - }] -} diff --git a/youtube/__init__.py b/youtube/__init__.py deleted file mode 100644 index d26ae61..0000000 --- a/youtube/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python3 - -from youtube.youtube import Youtube -from youtube.downloader import Downloader - -# vim: set ts=8 sw=4 tw=0 et : diff --git a/youtube/downloader.py b/youtube/downloader.py deleted file mode 100644 index ca1327b..0000000 --- a/youtube/downloader.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python3 - -import youtube_dl -import os - - -class Downloader: - instance = None - - def get_instance(file_format, location, base_url): - if Downloader.instance: - return Downloader.instance - else: - Downloader.instance = Downloader(file_format, location, base_url) - return Downloader.instance - - def __init__(self, file_format, location, base_url): - self.file_format = file_format - self.location = location - self.base_url = base_url - - def download(self, video, video_id, feed_id): - output = "%s/%s/%s.ogg" % (self.location, feed_id, video_id) - options = {"format": "bestaudio/best", - "outtmpl": output, - "postprocessors": [{ - "key": "FFmpegExtractAudio", - "preferredcodec": self.file_format - }], - "nooverwrites": True - } - - video_url = "https://www.youtube.com/watch?v=%s" % (video["snippet"]["resourceId"]["videoId"]) - youtube_dl.YoutubeDL(options).download([video_url]) - - url = "%s/%s/%s.ogg" % (self.base_url, feed_id, video_id) - size = str(os.path.getsize(output)) - mime = "audio/ogg" - - return (url, size, mime) - -# vim: set ts=8 sw=4 tw=0 et : diff --git a/youtube/youtube.py b/youtube/youtube.py deleted file mode 100644 index bcbff21..0000000 --- a/youtube/youtube.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python3 - -from urllib import parse, request -import json - - -class Youtube: - - def __init__(self, api_key): - self.api_key = api_key - - def _api_call(self, section, parameters): - parameters["key"] = self.api_key - data = parse.urlencode(parameters) - api_base = "https://www.googleapis.com/youtube/v3" - response = request.urlopen("%s/%s?%s" % (api_base, section, data)) - return json.loads(response.read().decode("UTF-8"))["items"] - - def search(self, query): - return self._api_call("search", {"part": "snippet", - "q": query}) - - def get_channel(self, username): - return self._api_call("channels", {"part": "snippet", - "forUsername": username}) - - def get_uploads(self, channel): - content_details = self._api_call("channels", {"part": "contentDetails", - "id": channel["id"]}) - uploads_id = content_details[0]["contentDetails"]["relatedPlaylists"]["uploads"] - return self._api_call("playlists", {"part": "snippet", - "id": uploads_id}) - - def get_playlists(self, channel, max_results=5): - return self._api_call("playlists", {"part": "snippet", - "channelId": channel["id"], - "maxResults": max_results}) - - def get_playlist_items(self, playlist, max_results=5): - return self._api_call("playlistItems", {"part": "snippet", - "playlistId": playlist["id"], - "maxResults": max_results}) - -# vim: set ts=8 sw=4 tw=0 et : diff --git a/youtube_podcaster/youtube-podcaster b/youtube_podcaster/youtube-podcaster new file mode 100755 index 0000000..bb2db26 --- /dev/null +++ b/youtube_podcaster/youtube-podcaster @@ -0,0 +1,159 @@ +#!/usr/bin/env python3 +import time +import os +import pickle +import json + +from http.server import HTTPServer, BaseHTTPRequestHandler +from hashlib import sha1 + +from feedgen.feed import FeedGenerator + +import youtube + + +class PodcastUpdater: + instance = None + + def get_instance(): + if PodcastUpdater.instance: + return PodcastUpdater.instance + else: + PodcastUpdater.instance = PodcastUpdater() + return PodcastUpdater.instance + + def __init__(self): + self.podcasts = config["podcasts"] + + self.feeds_file = "feeds.save" + if os.path.isfile(self.feeds_file): + with open(self.feeds_file, "rb") as feeds: + self.feeds = pickle.load(feeds) + else: + self.feeds = {} + + def get_xml(self, channel, playlist): + channel = channel.replace('_', ' ') + playlist = playlist.replace('_', ' ') + + for podcast in self.podcasts: + if podcast["username"] == channel: + break + else: + return None + + if playlist not in podcast["playlists"]: + return None + + xml = self.update_podcast(channel, playlist) + + if xml: + return open(xml).read() + + def update_podcast(self, channel, playlist): + feed_id = sha1(bytes("%s %s" % (channel, playlist), "UTF-8")).hexdigest() + yt_channel = yt.get_channel(channel)[0] + yt_playlists = yt.get_playlists(yt_channel, 50) + + for yt_playlist in yt_playlists: + if yt_playlist["snippet"]["title"] == playlist: + break + else: + return None + + if feed_id in self.feeds: + feed = self.feeds[feed_id] + else: + feed = self.add_feed(feed_id, yt_playlist) + + if feed.last_updated < time.time() - 600: + self.populate_feed(feed, feed_id, yt_playlist) + + feed_file = "%s.xml" % (feed_id) + self.feeds[feed_id].rss_file(feed_file) + + with open(self.feeds_file, "wb") as feed: + pickle.dump(self.feeds, feed) + + return "%s.xml" % (feed_id) + + def add_feed(self, feed_id, yt_playlist): + feed = FeedGenerator() + feed.load_extension("podcast") + feed.id(feed_id) + feed.title(yt_playlist["snippet"]["title"]) + feed.author({"name": yt_playlist["snippet"]["channelTitle"]}) + feed.description(yt_playlist["snippet"]["description"]) + feed.logo(yt_playlist["snippet"]["thumbnails"]["standard"]["url"]) + feed.link(href="https://www.youtube.com/playlist?list=%s" % (yt_playlist["id"])) + feed.rss_str(pretty=True) + feed.last_updated = 0 + self.feeds[feed_id] = feed + return feed + + def populate_feed(self, feed, feed_id, yt_playlist, max_results=5): + videos = yt.get_playlist_items(yt_playlist, max_results) + downloader = youtube.Downloader.get_instance("vorbis", "downloads", "192.168.178.100") + + entries = feed.entry() + for video in videos: + video_id = sha1(bytes(video["id"], "UTF-8")).hexdigest() + for entry in entries: + if entry.id() == video_id: + break + else: + url, size, mime = downloader.download(video, video_id, feed_id) + feed_entry = feed.add_entry() + feed_entry.id(video_id) + feed_entry.guid(video_id) + feed_entry.title(video["snippet"]["title"]) + feed_entry.description(video["snippet"]["description"]) + feed_entry.published(video["snippet"]["publishedAt"]) + feed_entry.enclosure(url, size, mime) + + feed.last_updated = time.time() + + +class PodcastFeeder(BaseHTTPRequestHandler): + def do_GET(self): + updater = PodcastUpdater.get_instance() + path = self.path.split('/') + + if len(path) == 3: + channel = path[1] + playlist = path[2] + else: + return self.return_error(404) + + xml = updater.get_xml(channel, playlist) + + if not xml: + return self.return_error(404) + else: + self.send_response(200) + self.send_header("Content-type", "text/xml") + self.end_headers() + self.wfile.write(bytes(xml, 'UTF-8')) + + def return_error(self, code): + self.send_response(code) + self.send_header("Content-type", "text/html") + self.end_headers() + + reponse = "Error: %s" % (code) + self.wfile.write(bytes(reponse, 'UTF-8')) + + +def main(): + try: + server = HTTPServer(("", 8888), PodcastFeeder) + server.serve_forever() + except KeyboardInterrupt: + server.socket.close() + +if __name__ == "__main__": + config = json.load(open("youtube-podcaster.json")) + yt = youtube.Youtube(config["youtube"]["api-key"]) + main() + +# vim: set ts=8 sw=4 tw=0 et : diff --git a/youtube_podcaster/youtube-podcaster.json.sample b/youtube_podcaster/youtube-podcaster.json.sample new file mode 100644 index 0000000..d9d078f --- /dev/null +++ b/youtube_podcaster/youtube-podcaster.json.sample @@ -0,0 +1,10 @@ +{ + "youtube": { + "api-key": "youtube-api-v3-key-here" + }, + + "podcasts": [{ + "username": "youtube-username-here", + "playlists": ["playlist-name-here"] + }] +} diff --git a/youtube_podcaster/youtube/__init__.py b/youtube_podcaster/youtube/__init__.py new file mode 100644 index 0000000..d26ae61 --- /dev/null +++ b/youtube_podcaster/youtube/__init__.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 + +from youtube.youtube import Youtube +from youtube.downloader import Downloader + +# vim: set ts=8 sw=4 tw=0 et : diff --git a/youtube_podcaster/youtube/downloader.py b/youtube_podcaster/youtube/downloader.py new file mode 100644 index 0000000..ca1327b --- /dev/null +++ b/youtube_podcaster/youtube/downloader.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +import youtube_dl +import os + + +class Downloader: + instance = None + + def get_instance(file_format, location, base_url): + if Downloader.instance: + return Downloader.instance + else: + Downloader.instance = Downloader(file_format, location, base_url) + return Downloader.instance + + def __init__(self, file_format, location, base_url): + self.file_format = file_format + self.location = location + self.base_url = base_url + + def download(self, video, video_id, feed_id): + output = "%s/%s/%s.ogg" % (self.location, feed_id, video_id) + options = {"format": "bestaudio/best", + "outtmpl": output, + "postprocessors": [{ + "key": "FFmpegExtractAudio", + "preferredcodec": self.file_format + }], + "nooverwrites": True + } + + video_url = "https://www.youtube.com/watch?v=%s" % (video["snippet"]["resourceId"]["videoId"]) + youtube_dl.YoutubeDL(options).download([video_url]) + + url = "%s/%s/%s.ogg" % (self.base_url, feed_id, video_id) + size = str(os.path.getsize(output)) + mime = "audio/ogg" + + return (url, size, mime) + +# vim: set ts=8 sw=4 tw=0 et : diff --git a/youtube_podcaster/youtube/youtube.py b/youtube_podcaster/youtube/youtube.py new file mode 100644 index 0000000..bcbff21 --- /dev/null +++ b/youtube_podcaster/youtube/youtube.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +from urllib import parse, request +import json + + +class Youtube: + + def __init__(self, api_key): + self.api_key = api_key + + def _api_call(self, section, parameters): + parameters["key"] = self.api_key + data = parse.urlencode(parameters) + api_base = "https://www.googleapis.com/youtube/v3" + response = request.urlopen("%s/%s?%s" % (api_base, section, data)) + return json.loads(response.read().decode("UTF-8"))["items"] + + def search(self, query): + return self._api_call("search", {"part": "snippet", + "q": query}) + + def get_channel(self, username): + return self._api_call("channels", {"part": "snippet", + "forUsername": username}) + + def get_uploads(self, channel): + content_details = self._api_call("channels", {"part": "contentDetails", + "id": channel["id"]}) + uploads_id = content_details[0]["contentDetails"]["relatedPlaylists"]["uploads"] + return self._api_call("playlists", {"part": "snippet", + "id": uploads_id}) + + def get_playlists(self, channel, max_results=5): + return self._api_call("playlists", {"part": "snippet", + "channelId": channel["id"], + "maxResults": max_results}) + + def get_playlist_items(self, playlist, max_results=5): + return self._api_call("playlistItems", {"part": "snippet", + "playlistId": playlist["id"], + "maxResults": max_results}) + +# vim: set ts=8 sw=4 tw=0 et : -- cgit v1.2.3