YouTube video iframe generator
Project description
YT iframe Generator
yt_iframe is a python module which can convert a youtube video link into an embeddable iframe.
Getting started
In order to use this module, install it through your terminal.
foo@bar:~$ pip install yt-iframe
Import the module in Python.
from yt_iframe import yt
Using the module
yt.video()
Generates a YouTube embed video iFrame from a YouTube video link.
url = 'https://www.youtube.com/watch?v=UzIQOQGKeyI' # (Required)
width = '560' # (Optional)
height = '315' # (Optional)
iframe = yt.video(url, width=width, height=height)
Parameters
- link : str (required)
- A link to a YouTube video.
- width : str (optional. default="560")
- The width of the iFrame in pixels.
- height : str (optional. default="315")
- The height of the iFrame in pixels.
Returns
- html : str
- The iFrame for the YouTube video.
yt.channel()
Generates a list of YouTube video links from a YouTube channel.
url = 'https://www.youtube.com/user/ouramazingspace' # (Required)
videolist = yt.channel(url)
Parameters
- link : str (required)
- A link to a YouTube channel.
Returns
- links : list
- A list of links to YouTube videos.
yt.channelDict()
Generates videos and metadata from a YouTube channel.
url = 'https://www.youtube.com/user/ouramazingspace'
videolist = yt.channelDict(url)
videolist['name'] # Name of channel
videolist['videos'] # Nested dictionary. Key = video title, Value = link
Parameters
- link : str (required)
- A link to a YouTube channel.
Returns
- channel : dict
- A dictionary of the YouTube channel's information.
- Key/value pairs:
- name = the name of the YouTube channel
- videos = List of video links
yt.getFrames()
Generates a list of iFrames from a list of YouTube videos.
channel = yt.channel('https://www.youtube.com/user/ouramazingspace') # (Required)
width = '560' # (Optional)
height = '315' # (Optional)
responsive = True # (Optional)
# Fixed size iframes
iframes = yt.getFrames(channel, width=width, height=height)
# Responsive iframes
iframes = yt.getFrames(channel, responsive=responsive)
Parameters
- links : list (required)_
- A list of links to YouTube videos.
- width : str (optional. default="560")
- The width of each iFrame in pixels.
- height : str (optional. default="315")
- The height of each iFrame in pixels.
- responsive : bool (optional. default = False)
- Determines whether each iFrame is dynamically or statically sized.
Returns
- iframes : list
- List of iFrames.
yt.linkResponsive()
Get link to css for styling the iFrames. Alternatively, you can add this line of html in your head tag. '<link rel="stylesheet" href="https://raw.githubusercontent.com/RobbyB97/yt-iframe-python/master/yt_iframe/yt_iframe.css">'
Returns
- str
- HTML link tag to import css for iFrames
yt.videoResponsive()
Generates a responsive iFrame video. Make sure you have the css file imported with the linkResponsive() function. You can wrap a bunch of these generated tags in a container and the iFrames will resize to fit the layout within that container.
url = 'https://www.youtube.com/watch?v=UzIQOQGKeyI' # (Required)
layout = 'singlecolumn' # (Optional)
video = yt.videoResponsive(url, layout=layout) # Get HTML
Parameters
- link : str (required)
- A link to a YouTube video.
- layout : str (optional. default="onecolumn")
- Soecifies the relative size of the iFrame.
- Acceptable values:
- 'onecolumn' - Generates one column layout
- 'twocolumn' - Generates two column video
Returns
- iframes : list
- List of iFrames.
Changelog
== v1.0.5 ==
- Fix css import link
- Fix argument error in videoResponsive()
- Fix xml parsing (the lxml dependency issue)
- Add docstrings for all functions
- Refactor functions to improve readability
== v1.0.4 ==
- Add layout argument to videoResponsive() and getFrames()
- Add two column layout option to videoResponsive()
== v1.0.3 ==
- Add responsive iframes
- getFrames() arguments changed from framewidth and frameheight to width and height
== v1.0.1 ==
- Allow size of iframe to be specified in video() function
- Allow sizes of iframes to be specified in getFrames() function
== v1.0.0 ==
- Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.