Permalink
Browse files

add test for flv2mp4 hook

  • Loading branch information...
1 parent a5a53ca commit 7fdd513f2cfb0636c1f6f4c0e4728a9ed699486a Bernd Schlapsi committed Oct 30, 2011
Showing with 73 additions and 13 deletions.
  1. +21 −6 flv2mp4.py
  2. +4 −4 tests/config/data.py
  3. +37 −0 tests/flv2mp4_test.py
  4. +11 −3 tests/runtests.py
View
@@ -11,12 +11,20 @@
from gpodder import youtube
import os
+import shlex
import subprocess
import logging
logger = logging.getLogger(__name__)
+
+FFMPEG_CMD = 'ffmpeg -i "%(infile)s" -vcodec copy -acodec copy "%(outfile)s"'
+
+
class gPodderHooks(object):
+ def __init__(self, test=False):
+ self.test = test
+
def on_episode_downloaded(self, episode):
self._convert_episode(episode)
@@ -40,14 +48,21 @@ def _convert_episode(self, episode):
filename = newname
target = os.path.join(dirname, basename+'.mp4')
- ffmpeg = subprocess.Popen(['ffmpeg', '-i', filename,
- '-vcodec', 'copy', '-acodec', 'copy', target])
+ cmd = FFMPEG_CMD % {
+ 'infile': filename,
+ 'outfile': target
+ }
+ ffmpeg = subprocess.Popen(shlex.split(str(cmd)),
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE
+ )
+ stdout, stderr = ffmpeg.communicate()
- if ffmpeg.wait() == 0:
+ if ffmpeg.returncode == 0:
logger.info('FLV conversion successful.')
- os.remove(filename)
- episode.download_filename = basename+'.mp4'
- episode.save()
+ if not self.test:
+ os.remove(filename)
+ episode.download_filename = basename+'.mp4'
+ episode.save()
else:
logger.info('Error converting file. FFMPEG installed?')
try:
View
@@ -32,8 +32,8 @@
'TEDTalks': {'url': 'file://%s/tedtalks_video.rss' % config_dir,
'episode': -31},
- # selected episode should be 'Richie Hawtin, "The Tunnel" music video, directed by Ali Demirel. (flv)'
- #'drovics': {#'url': 'http://m-nus.com/podcast.xml',
- # 'url': 'https://www.youtube.com/user/drovics',
- # 'episode': 0 },
+ # YouTube-Channel
+ 'drovics': {#'url': 'https://www.youtube.com/user/drovics',
+ 'url': 'http://gdata.youtube.com/feeds/base/users/drovics/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile',
+ 'episode': 0 },
}
View
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+import os
+import shutil
+import unittest
+
+from gpodder import api
+from config import data
+import flv2mp4
+
+
+class TestFlv2Mp4(unittest.TestCase):
+ def setUp(self):
+ self.client = api.PodcastClient()
+
+ url = data.TEST_PODCASTS['drovics']['url']
+ episode_no = data.TEST_PODCASTS['drovics']['episode']
+ self.podcast = self.client.get_podcast(url)
+
+ self.episode = self.podcast.get_episodes()[episode_no]
+ self.filename = self.episode._episode.local_filename(create=False, check_only=True)
+ self.converted_file = os.path.splitext(self.filename)[0] + '.mp4'
+
+ def tearDown(self):
+ self.client._db.close()
+
+ if os.path.exists(self.converted_file):
+ os.remove(self.converted_file)
+
+ def test_mp4convert(self):
+ self.assertIsNotNone(self.filename)
+
+ flv_hook = flv2mp4.gPodderHooks(test=True)
+ flv_hook.on_episode_downloaded(self.episode._episode)
+
+ self.assertTrue(os.path.exists(self.converted_file))
+ self.assertTrue(os.path.getsize(self.converted_file)>0)
View
@@ -56,10 +56,12 @@ def check_version(gpo_bin):
def ins_test_podcast(client, podcast_url, episode2dl=None):
- podcast = client.create_podcast(podcast_url)
- podcast.disable()
+ podcast = client.get_podcast(podcast_url)
+ if podcast is None:
+ podcast = client.create_podcast(podcast_url)
+ podcast.disable()
- if episode2dl:
+ if episode2dl is not None:
episode = podcast.get_episodes()[episode2dl]
if (not episode.is_downloaded):
episode.download()
@@ -71,6 +73,10 @@ def init_data():
client = api.PodcastClient()
+ # set preferred youtube format to FLV (for flv2mp4 test)
+ client._config.youtube_preferred_fmt_id = 34
+ client._config.save()
+
for name, conf in data.TEST_PODCASTS.items():
ins_test_podcast(client, conf['url'], conf['episode'])
@@ -97,6 +103,7 @@ def init_data():
#import all test files
import bittorrent_test
import cmml_creator_test
+ import flv2mp4_test
import mp3split_test
import rename_downloads_test
import rm_ogg_cover_test
@@ -109,6 +116,7 @@ def init_data():
suite = loader.loadTestsFromModule(bittorrent_test)
suite.addTests(loader.loadTestsFromModule(cmml_creator_test))
+ suite.addTests(loader.loadTestsFromModule(flv2mp4_test))
suite.addTests(loader.loadTestsFromModule(mp3split_test))
suite.addTests(loader.loadTestsFromModule(rename_downloads_test))
suite.addTests(loader.loadTestsFromModule(rm_ogg_cover_test))

0 comments on commit 7fdd513

Please sign in to comment.