banshee r4367 - in trunk/banshee: . build build/m4/banshee src/Extensions src/Extensions/Banshee.Torrent src/Extensions/Banshee.Torrent/Banshee.Torrent



Author: gburt
Date: Wed Aug 13 17:53:29 2008
New Revision: 4367
URL: http://svn.gnome.org/viewvc/banshee?rev=4367&view=rev

Log:
2008-08-13  Gabriel Burt  <gabriel burt gmail com>

	* src/Extensions/Extensions.mds:
	* src/Extensions/Makefile.am:
	* src/Extensions/Banshee.Torrent/Banshee.Torrent.mdp:
	* src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentService.cs:
	* src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentFileDownloadTask.cs:
	* src/Extensions/Banshee.Torrent/Makefile.am:
	* src/Extensions/Banshee.Torrent/Banshee.Torrent.addin.xml:
	* build/m4/banshee/torrent.m4:
	* build/build.environment.mk:
	* configure.ac: Patch from Alan McGovern adding support for downloading
	.torrent podcast enclosures, with some build/style fixes by me.  Is not
	built by default (requires --enable-torrent option) and probably not
	buildable at all except within MonoDevelop.  Still under development, do
	not enable unless you know what you're doing.



Added:
   trunk/banshee/build/m4/banshee/torrent.m4
   trunk/banshee/src/Extensions/Banshee.Torrent/   (props changed)
   trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/
   trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent.addin.xml
   trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent.mdp
   trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentFileDownloadTask.cs
   trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentService.cs
   trunk/banshee/src/Extensions/Banshee.Torrent/Makefile.am
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/build/build.environment.mk
   trunk/banshee/configure.ac
   trunk/banshee/src/Extensions/Extensions.mds
   trunk/banshee/src/Extensions/Makefile.am

Modified: trunk/banshee/build/build.environment.mk
==============================================================================
--- trunk/banshee/build/build.environment.mk	(original)
+++ trunk/banshee/build/build.environment.mk	Wed Aug 13 17:53:29 2008
@@ -24,6 +24,7 @@
 LINK_IPOD = $(IPODSHARP_LIBS)
 LINK_BOO = $(BOO_LIBS)
 LINK_WEBKIT = $(WEBKIT_LIBS)
+LINK_MONOTORRENT_DBUS = $(MONOTORRENT_DBUS_LIBS)
 
 LINK_MONO_ADDINS_DEPS = $(MONO_ADDINS_LIBS)
 LINK_MONO_ADDINS_SETUP_DEPS = $(MONO_ADDINS_SETUP_LIBS)

Added: trunk/banshee/build/m4/banshee/torrent.m4
==============================================================================
--- (empty file)
+++ trunk/banshee/build/m4/banshee/torrent.m4	Wed Aug 13 17:53:29 2008
@@ -0,0 +1,13 @@
+AC_DEFUN([BANSHEE_CHECK_TORRENT],
+[
+	AC_ARG_ENABLE(torrent, AC_HELP_STRING([--enable-torrent], [Enable BitTorrent support - still in development]), , enable_torrent="no")
+
+	if test "x$enable_torrent" = "xyes"; then
+        PKG_CHECK_MODULES(MONOTORRENT_DBUS, monotorrent-dbus >= 0.1);
+        AC_SUBST(MONOTORRENT_DBUS_LIBS)
+        AM_CONDITIONAL(HAVE_MONOTORRENT_DBUS, true)
+	else
+		AM_CONDITIONAL(HAVE_MONOTORRENT_DBUS, false)
+	fi
+])
+

Modified: trunk/banshee/configure.ac
==============================================================================
--- trunk/banshee/configure.ac	(original)
+++ trunk/banshee/configure.ac	Wed Aug 13 17:53:29 2008
@@ -90,6 +90,9 @@
 dnl DAAP support (optional)
 BANSHEE_CHECK_DAAP
 
+dnl MonoTorrent support (optional)
+BANSHEE_CHECK_TORRENT
+
 dnl i18n
 SHAMROCK_CONFIGURE_I18N($PACKAGE)
 
@@ -181,6 +184,7 @@
 src/Extensions/Banshee.Podcasting/Makefile
 src/Extensions/Banshee.SqlDebugConsole/Makefile
 src/Extensions/Banshee.Sample/Makefile
+src/Extensions/Banshee.Torrent/Makefile
 ])
 
 echo "
@@ -204,8 +208,9 @@
     Boo Scripting:     ${enable_boo}
     X11 Video Support: ${have_xvidmode}
 
-    Unfinished, unstable, unusable components:
+    Unfinished, unstable, under development components:
       MediaWeb:        ${enable_mediaweb}
+      Torrent Podcasts:${enable_torrent}
 
     Unit Tests:        ${do_tests}	(requires nunit >= ${NUNIT_REQUIRED})
 "

Added: trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent.addin.xml
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent.addin.xml	Wed Aug 13 17:53:29 2008
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Addin 
+    id="Banshee.Torrent"
+    version="1.0"
+    compatVersion="1.0"
+    copyright="Â 2008 Novell Inc. Licensed under the MIT X11 license."
+    name="Torrent Downloader"
+    category=""
+    description="Adds support for downloading BitTorrent files from podcasts."
+    author="Alan McGovern"
+    url="http://banshee-project.org/";
+    defaultEnabled="true">
+
+  <Dependencies>
+    <Addin id="Banshee.Services" version="1.0"/>
+  </Dependencies>
+
+  <Extension path="/Banshee/ServiceManager/Service">
+    <Service class="Banshee.Torrent.TorrentService"/>
+  </Extension>
+
+</Addin>

Added: trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent.mdp
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent.mdp	Wed Aug 13 17:53:29 2008
@@ -0,0 +1,33 @@
+<Project name="Banshee.Torrent" fileversion="2.0" language="C#" clr-version="Net_2_0" UseParentDirectoryAsNamespace="True" ctype="DotNetProject">
+  <Configurations active="Debug">
+    <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+      <Output directory="../../../bin" assemblyKeyFile="." assembly="Banshee.Torrent" />
+      <Build debugmode="True" target="Library" />
+      <Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
+      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+    </Configuration>
+  </Configurations>
+  <Contents>
+    <File name="Banshee.Torrent.addin.xml" subtype="Code" buildaction="EmbedAsResource" />
+    <File name="Banshee.Torrent/TorrentService.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Torrent/TorrentFileDownloadTask.cs" subtype="Code" buildaction="Compile" />
+  </Contents>
+  <References>
+    <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+    <ProjectReference type="Gac" localcopy="True" refto="Banshee.Core, Version=0.99.3.35355, Culture=neutral, PublicKeyToken=null" />
+    <ProjectReference type="Gac" localcopy="True" refto="Banshee.Services, Version=0.99.3.35356, Culture=neutral, PublicKeyToken=null" />
+    <ProjectReference type="Assembly" localcopy="True" refto="../../../bin/Migo.dll" />
+    <ProjectReference type="Gac" localcopy="True" refto="NDesk.DBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099" />
+    <ProjectReference type="Gac" localcopy="True" refto="Hyena, Version=0.99.3.39455, Culture=neutral, PublicKeyToken=null" />
+    <ProjectReference type="Assembly" localcopy="True" refto="../../../../bitsharp-dbus/Sample/bin/Debug/monotorrent-dbus.dll" />
+  </References>
+  <MonoDevelop.Autotools.MakefileInfo RelativeMakefileName="./Makefile.am">
+    <BuildFilesVar Sync="True" Name="SOURCES" />
+    <DeployFilesVar />
+    <ResourcesVar Sync="True" Name="RESOURCES" />
+    <OthersVar />
+    <GacRefVar />
+    <AsmRefVar />
+    <ProjectRefVar />
+  </MonoDevelop.Autotools.MakefileInfo>
+</Project>

Added: trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentFileDownloadTask.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentFileDownloadTask.cs	Wed Aug 13 17:53:29 2008
@@ -0,0 +1,125 @@
+//
+// TorrentFileDownloadTask.cs
+//
+// Author:
+//   Alan McGovern <alan mcgovern gmail com>
+//
+// Copyright (C) 2008 Alan McGovern
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.IO;
+using Migo.TaskCore;
+using MonoTorrent.DBus;
+
+namespace Banshee.Torrent
+{
+	public class TorrentFileDownloadTask : Migo.DownloadCore.HttpFileDownloadTask
+	{
+		private string torrentPath;
+		private MonoTorrent.DBus.IDownloader downloader;
+		private MonoTorrent.DBus.ITorrent torrent;
+		
+		public TorrentFileDownloadTask(string remoteUri, string localPath, object userState)
+			: base (remoteUri, localPath.Substring(0, localPath.Length - 8), userState)
+		{
+			
+		}
+		
+		public override long BytesReceived {
+			get 
+			{
+				if (downloader == null)
+                    return 0;
+                
+				return (long)(downloader.Progress / 100.0 * torrent.Size); 
+			}
+		}
+		
+		public override void CancelAsync ()
+		{
+			if (downloader == null)
+                return;
+            
+			downloader.Stop ();
+			SetStatus (TaskStatus.Cancelled);
+            OnTaskCompleted (null, true);
+		}
+
+		public override void ExecuteAsync ()
+		{
+			SetStatus (TaskStatus.Running);
+			TorrentService s = (TorrentService) Banshee.ServiceStack.ServiceManager.Get<TorrentService>("TorrentService");
+			downloader = s.Download (this.RemoteUri.ToString(), Path.GetDirectoryName(this.LocalPath));
+			torrent = MonoTorrent.DBus.TorrentService.Bus.GetObject <MonoTorrent.DBus.ITorrent> (MonoTorrent.DBus.TorrentService.BusName, this.downloader.Torrent);
+			
+			this.downloader.StateChanged += delegate {
+				if (downloader.State == TorrentState.Seeding)
+				{
+					SetProgress(100);
+					SetStatus (TaskStatus.Succeeded);
+					OnTaskCompleted (null, false);
+				}
+			};
+			
+			// There are no events on the torrent IDownloader to indicate when the stats have updated
+			// I need to manually ping the SetProgress event otherwise migo never notices progress changing
+			System.Threading.ThreadPool.QueueUserWorkItem ((System.Threading.WaitCallback)delegate {
+				while (base.Progress != 100 && 
+				       (Status == TaskStatus.Running || Status == TaskStatus.Paused || Status == TaskStatus.Running))
+				{
+					Hyena.Log.Debug ("Torrent Tick");
+					System.Threading.Thread.Sleep (2000);
+					SetProgress((int)downloader.Progress);
+				}
+			});
+		}
+
+		public override void Pause ()
+		{
+			if (downloader == null)
+                return;
+            
+			SetStatus (TaskStatus.Paused);
+			downloader.Pause ();
+		}
+		
+		public override void Resume ()
+		{
+			if (downloader == null)
+                return;
+            
+			SetStatus (TaskStatus.Running);
+			downloader.Stop ();
+		}
+
+		public override void Stop ()
+		{
+			if (downloader == null)
+                return;
+            
+			SetStatus (TaskStatus.Stopped);
+			OnTaskCompleted (null, false);
+			downloader.Stop ();
+		}
+	}
+}

Added: trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentService.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentService.cs	Wed Aug 13 17:53:29 2008
@@ -0,0 +1,141 @@
+//
+// TorrentService.cs
+//
+// Author:
+//   Alan McGovern <alan mcgovern gmail com>
+//
+// Copyright (C) 2008 Alan McGovern
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections.Generic;
+
+using NDesk.DBus;
+using org.freedesktop.DBus;
+using MonoTorrent.DBus;
+
+using Hyena;
+
+using Banshee.ServiceStack;
+
+namespace Banshee.Torrent
+{
+    public class TorrentService : IExtensionService, IDelayedInitializeService
+    {
+        static bool RegisteredInMigo = false;
+        public static readonly string BusName = "org.monotorrent.dbus";
+        public static readonly string EngineName = "banshee";
+        public static readonly ObjectPath ServicePath = new ObjectPath ("/org/monotorrent/service");
+        
+        private Bus bus;
+        private IEngine engine;
+        private ITorrentService service;
+        private IEngineSettings settings;
+        
+        public int MaxDownloadSpeed {
+            get { return settings.GlobalMaxDownloadSpeed; }
+            set { settings.GlobalMaxDownloadSpeed = value; }
+        }
+        
+        public int MaxUploadSpeed {
+            get { return settings.GlobalMaxUploadSpeed; }
+            set { settings.GlobalMaxUploadSpeed = value; }
+        }
+
+        public string ServiceName {
+            get { return "TorrentService"; }
+        }
+        
+        public TorrentService ()
+        {
+        }
+        
+        public IDownloader Download (string torrentUri, string savePath)
+        {
+            // Get the associated downloader
+            ObjectPath path = engine.RegisterTorrent (torrentUri, savePath);
+            IDownloader downloader = bus.GetObject <IDownloader> (BusName, path);
+            
+            if (downloader.State == TorrentState.Stopped)
+            {
+                downloader.Start ();
+                Console.WriteLine ("Started: {0}", downloader.Path);
+            }
+            else
+            {
+                Console.WriteLine ("{0} already running", downloader.Path);
+            }
+            return downloader;
+        }
+        
+        public void Dispose ()
+        {
+            service.DestroyEngine (EngineName);
+        }
+
+        public void Initialize ()
+        {
+        }
+
+        public void DelayedInitialize ()
+        {
+            bus = Bus.Session;
+                        
+            try
+            {
+                // Get the service and call a method on it to ensure that it is
+                // running and able to answer queries.
+                service = bus.GetObject<ITorrentService> (BusName, ServicePath);
+                service.AvailableEngines ();
+            }
+            catch
+            {
+                Log.Error ("Torrent backend could not be found and could not be auto-started");
+                return;
+            }
+            
+            // Register with Migo so we can handle .torrent downloads
+            Migo.DownloadCore.DownloadManager.Register ("torrent", typeof (TorrentFileDownloadTask));
+            RegisteredInMigo = true;
+            
+            // Get the engine from DBus which we will use to download torrents with
+            // and load the details for any existing downloads
+            engine = bus.GetObject <IEngine> (BusName, service.GetEngine (EngineName));
+            CheckExistingDownloads ();
+        }
+        
+        private void CheckExistingDownloads ()
+        {
+            //UserJobManager manager = (UserJobManager)ServiceManager.Get ("UserJobManager");
+            ObjectPath[] downloaders = engine.GetDownloaders ();
+            foreach (ObjectPath o in downloaders)
+            {
+                Console.WriteLine ("Existing download: {0}", o);
+                //IDownloader downloader = this.bus.GetObject<IDownloader> (BusName, o);
+                //ITorrent torrent = this.bus.GetObject<ITorrent> (BusName, downloader.Torrent);
+                //manager.Register (new DownloaderJob (torrent.Name, downloader));
+                //if (downloader.State == TorrentState.Stopped)
+                //    downloader.Start ();
+            }
+        }
+    }
+}

Added: trunk/banshee/src/Extensions/Banshee.Torrent/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.Torrent/Makefile.am	Wed Aug 13 17:53:29 2008
@@ -0,0 +1,15 @@
+ASSEMBLY = Banshee.Torrent
+TARGET = library
+LINK = $(LINK_BANSHEE_SERVICES_DEPS) $(LINK_MIGO_DEPS) $(LINK_MONOTORRENT_DBUS)
+INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
+
+SOURCES =  \
+	Banshee.Torrent/TorrentService.cs \
+	Banshee.Torrent/TorrentFileDownloadTask.cs
+
+if HAVE_MONOTORRENT_DBUS
+include $(top_srcdir)/build/build.mk
+else
+EXTRA_DIST = $(SOURCES) $(RESOURCES)
+endif
+

Modified: trunk/banshee/src/Extensions/Extensions.mds
==============================================================================
--- trunk/banshee/src/Extensions/Extensions.mds	(original)
+++ trunk/banshee/src/Extensions/Extensions.mds	Wed Aug 13 17:53:29 2008
@@ -18,6 +18,7 @@
       <Entry build="True" name="Banshee.FileSystemQueue" configuration="Debug" />
       <Entry build="True" name="Banshee.InternetRadio" configuration="Debug" />
       <Entry build="True" name="Banshee.SqlDebugConsole" configuration="Debug" />
+      <Entry build="True" name="Banshee.Torrent" configuration="Debug" />
     </Configuration>
   </Configurations>
   <StartMode startupentry="Banshee.Daap" single="True">
@@ -38,6 +39,7 @@
     <Execute type="None" entry="Banshee.FileSystemQueue" />
     <Execute type="None" entry="Banshee.InternetRadio" />
     <Execute type="None" entry="Banshee.SqlDebugConsole" />
+    <Execute type="None" entry="Banshee.Torrent" />
   </StartMode>
   <Entries>
     <Entry filename="Banshee.Daap/Banshee.Daap.mdp" />
@@ -57,5 +59,6 @@
     <Entry filename="Banshee.FileSystemQueue/Banshee.FileSystemQueue.mdp" />
     <Entry filename="Banshee.InternetRadio/Banshee.InternetRadio.mdp" />
     <Entry filename="Banshee.SqlDebugConsole/Banshee.SqlDebugConsole.mdp" />
+    <Entry filename="Banshee.Torrent/Banshee.Torrent.mdp" />
   </Entries>
 </Combine>

Modified: trunk/banshee/src/Extensions/Makefile.am
==============================================================================
--- trunk/banshee/src/Extensions/Makefile.am	(original)
+++ trunk/banshee/src/Extensions/Makefile.am	Wed Aug 13 17:53:29 2008
@@ -15,6 +15,7 @@
 	Banshee.PlayQueue \
 	Banshee.Podcasting \
 	Banshee.Sample \
-	Banshee.SqlDebugConsole
+	Banshee.SqlDebugConsole \
+	Banshee.Torrent
 
 MAINTAINERCLEANFILES = Makefile.in



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]