def transform(self, data):
        transforms = []
        in_fenced_code_block = False
        linenum = 0

        for line in data:
            # Handling fenced code blocks (for Github-flavored markdown)
            if fencedcodere.search(line):
                if in_fenced_code_block:
                    in_fenced_code_block = False
                else:
                    in_fenced_code_block = True

            # Are we in a code block?
            if not in_fenced_code_block and not codere.search(line):
                match = youtube_url_re.search(line)
                if match:
                    # find URL of youtube video and screenshot
                    url = match.group(1)
                    image_url = 'http://img.youtube.com/vi/%s/0.jpg' % url
                    video_url = 'http://www.youtube.com/watch?v=%s' % url
                    processed_image_dir = os.path.join('images', 'youtube')
                    processed_image_path = os.path.join(processed_image_dir,
                                                        '%s.png' % url)

                    # do we already have a screenshot?
                    if not os.path.isfile(processed_image_path):
                        # try to add a play button to the screenshot
                        try:
                            import Image
                            from tempfile import NamedTemporaryFile

                            # create directories if needed
                            if not os.path.exists(processed_image_dir):
                                os.makedirs(processed_image_dir)

                            # create temporary files for image operations
                            screenshot_img = NamedTemporaryFile(suffix=".jpg")
                            button_img = NamedTemporaryFile(suffix=".png")

                            # grab screenshot and button image
                            urllib.urlretrieve(image_url, screenshot_img.name)
                            urllib.urlretrieve(play_button_url,
                                               button_img.name)

                            # layer the images using PIL and save
                            background = Image.open(screenshot_img.name)
                            foreground = Image.open(button_img.name)
                            background.paste(foreground, (90, 65), foreground)
                            background.save(processed_image_path)

                        except Exception as e:
                            print('Unable to add play button to YouTube '
                                  'screenshot (%s). Using the screenshot '
                                  'on its own instead.' % e)

                    image_link = ('[![Link to Youtube video](%s)](%s)\n' %
                                  (processed_image_path, video_url))
                    transforms.append(Transform(linenum, "swap", image_link))

            linenum += 1

        return transforms
dataset/ETHPy150Open jreese/markdown-pp/MarkdownPP/Modules/YoutubeEmbed.py/YoutubeEmbed.transform/original