Tag Archives: btsync

Mobile music briefcase using BitTorrent Sync

Streaming, cloud, social, …. Nice stuff! But, what if your behind a firewall and have to rely on the local storage on your mobile device? I was thinking on how to solve this situation, a listen later briefcase.

Use Case

  • You want to select music files to listen to on a device.
  • Costs, Security, and bandwidth limitations preclude streaming.
  • Security will not allow use of thumb drives and other ‘attachable’ devices.
  • You should be able to delete these files.
  • Removing them should not delete the original files.
  • These files should be quickly and securely transferred.

This approach is just a modern version of the “CD storage case” we used in the old days to store some tunes for the long drives.

Solution
One way of implementing this is using BitTorrent Sync (BTSync). Basically we create a “briefcase” folder where we will drop copies of what we want to listen to later. To make this easier to follow, I’ll use the origin as being a Desktop PC. We also create a folder on our mobile devices that will be synchronized with the other folder. BTSync will handle the process of keeping these folders in sync. And, since BTSync is so fast, the sync will happen as the files are dropped on the briefcase folder.

    PC                          Device
+--------+     +---------+     +-----+
| Music  | === |Briefcase| ~~~ |Music|
+--------+     +---------+     +-----+

Though mobile example is used here, the device could be anything, even an automobile with advanced music system. While it is parked in front of home, it could be “charging” on some tunes.

How to setup
1. Of course, you have to first have BTSync installed on both the PC and the mobile devices.
2. Then on your PC run BTSync and choose “Add folder”.
3. Click ‘Generate’ button to generate a secret key.
4. Click ‘Browse’ to navigate to the folder to use as the Briefcase. (I used “Music-BTSync” as the name).
5. On mobile devices create a folder that you want to use as the listen later storage. (I created a “Music-BTSync” on my external SDCard).
5a This folder must be accessible to your mobile music player application.
6. On your mobile device run BitTorrent Sync and choose ‘Add Sync folder’.
7. Use the folder created above.
8. Now we have to get the secret read only key from the PC to the mobile device.
8a. On the PC, share the “Briefcase” folder. By using the mobile option, you can generate a QRcode.
8b. On mobile device, scan or enter that key.
9. On the mobile device, on BTSync’s list “MY SYNC”, the new folder should be listed (mine was music-BTSync).
10. Click the settings sprocket to the right of it.
11. Check on “Automatic sync”

Testing
Loading: Just copy an mp3 into the Briefcase folder on the PC. It should immediately be copied to the mobile device. With a File app on the device you should be able to see it in the sync folder.
Deleting on PC: Delete the file from the Briefcase folder on PC. It should be deleted automatically on the device.
Deleting on Mobile: Load another file on PC, it gets copied. Now delete that file on the mobile device only. It should remain on the PC. This is because of the use of the ‘Read only’ secret key. To change this behavior, do the sharing using a regular secret key.

Listening
This where the problems start. The ability to access and automatically refresh a changed folder varies among portable music player apps. Some like Google Music Player, for example, doesn’t even expose the concept of file folders and other nice to know configuration settings. Poweramp is better in this regard, with some prodding it recognized the new synced files. Still looking for a player that will behave with this sync process.

Alternatives
Various music apps have ways of using caching to store music. They also have various sync capabilities. However, these could be difficult to use in this scenario. Plus, the various parties are trying to monetize content, so optimizing the use of your private music collection is not a great concern.

Does it work?
This morning I put gigabytes of music on a folder on my PC, BTSync synced it to my phone. Now I’m listening to Black Sabbath and Barry White at work. How cool and eclectic is that?

Notes
Microsoft Windows used to have a Briefcase feature. It was removed in Windows 8. This was a limited two-way file synchronization process. With BTSync, there can be many folders in sync. For example, multiple mobile devices can sync to the same PC or home folder.

Tested on
Galaxy Note version 1
Android 4.1.2
BitTorrent Sync v1.3.21.0

Windows 7 64bit
BitTorrent Sync 1.3.94

Related links

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Using Git with BitTorrent Sync

The various cloud sync services provide a good way to backup or remote a Git repository for ‘single developer’ situations. The main advantages are that the cost is minimal and no ‘server’ is required. In this post we use something quite different, the new BitTorrent Sync (BTSync) system.

Use Cases
1. Single developer on multiple devices, PC, laptop, mobile. Also see Single Developer Git Workflow, .
2. Easy, fast, and lightweight code sharing setup. See also Sneakernet with Git
3. Ad Hoc Version Control: How to do Ad Hoc Version Control, Ad Hoc Version Control With Git

BTSync is a serverless folder syncing system. Instead of using a remote server storage system, it creates a fast private peer-to-peer file sync system using a P2P protocol. Note it is not necessarily a replacement for a server, backup system, or even other services such as DropBox, more like a welcome addition that covers some limits that others may have, such as file size limitations, speed, and privacy.

Using this type of service is very easy. I took the easy way out and “forked” a very well written blog post by Sergei Shvetsov that did the same thing, only using DropBox. Using Git with Dropbox. In this post, however, I use BTSync and I am running on Windows (most blogs show examples on *nix). Of course, experienced Git users may approach this very differently. The following uses a console shell UI.

Process
1. Create a local repo
2. Create a “bare” repo that lives in the Synced folders
3. Add the bare repo as the origin of the local repo.

Result
Now on another system, the synced folder, which contains the bare repo is available as if it was created locally. During development or other uses, since we are using the working repo and only occasionally the ‘bare’ or origin repo in the synced folder, the synced folder is not constantly transferring data over the network to any other synced locations (there can be many).

This approach is diagrammed below. (On mobile device this ASCII diagram using <PRE> tag looks horrible.) Two systems with the two Git repos:

+-----------------+                     +----------------+
|     Local       |                     |     Local      |
|     Repo        |                     |     Repo       |
+-----------------+                     +----------------+
      ^ +                                    +   ^
      | |                                    |   |
      | | push/pull                          |   |  push/pull
      | |                                    |   |
      | |                                    +   |
      + v                                    v   +
+-----------------+         BT Sync     +----------------+
|      Bare       | <-----------------+ |      Bare      |
|      repo       | +------------------>|      repo      |
+-----------------+                     +----------------+

Alternatives
Of course whenever possible direct access to remote repos from a clone is preferred, or via a server. For private use and 5 users, Bitbucket offers free code repositories.

Example
Below is a walkthrough of this process using a Windows cmd shell.

Create a local repository

C:\temp\git-on-BTSync>git init new-project
Initialized empty Git repository in C:/temp/git-on-BTSync/new-project/.git/

C:\temp\git-on-BTSync>cd new-project
C:\temp\git-on-BTSync\new-project>echo "" > README.txt

git add .
C:\temp\git-on-BTSync\new-project>git commit -m "Initial Commit"
[master (root-commit) dcb3f2b] Initial Commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.txt

Create a new ‘bare’ repo inside of local BTSynced folder

new-project>mkdir C:\Users\jbetancourt\BTSync\git
C:\new-project>git init --bare C:\Users\jbetancourt\BTSync\git\new-project.git
Initialized empty Git repository in C:/Users/jbetancourt/BTSync/git/new-project.git/

Add this new bare repo as upstream remote to the local repo

new-project>git remote add dropbox C:\Users\jbetancourt\BTSync\git\new-project.git

Push local changes to the bare repo

C:\temp\git-on-BTSync\new-project>git push -u dropbox master
Counting objects: 3, done.
Writing objects: 100% (3/3), 223 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To C:\Users\jbetancourt\BTSync\git\new-project.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from dropbox.

Use another system
On another system that is running BTSync, like a laptop, the bare repository folder is already synced. Now we can clone the repo.

cd \temp
mkdir remote-workspace
cd remote-workspace
git clone -o dropbox \Users\jbetancourt\BTSync\git\new-project.git
Cloning into 'new-project' ...
done.
cd new-project
dir
11/29/2013  10:48 AM      5 README.txt

Now make some changes
On the laptop we modify a file and commit it.

echo "Hello world" > README.txt
C:\temp\remote-workspace\new-project>type README.txt
"Hello world"
C:\temp\remote-workspace\new-project>git add README.txt

C:\temp\remote-workspace\new-project>git commit -m "changed readme"
[master 452b02e] changed readme
1 file changed, 1 insertion(+), 1 deletion(-)

Now push the changes to the local bare repo

C:\temp\remote-workspace\new-project>git push
Counting objects: 5, done.
Writing objects: 100% (3/3), 260 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To \Users\jbetancourt\BTSync\git\new-project.git
   dcb3f2b..452b02e  master -> master

Back to the original repo on the PC
We pull the changes that were automatically synced via BTSync into
the bare repo.

type README.txt
""
C:\temp\git-on-BTSync\new-project&gt;git pull
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From C:\Users\jbetancourt\BTSync\git\new-project
   dcb3f2b..452b02e  master     -> dropbox/master
Updating dcb3f2b..452b02e
Fast-forward
 README.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

C:\temp\git-on-BTSync\new-project>type README.txt
"Hello world"

That was easy!

Issues with syncing git repos with BTSync?

  • BitTorrentSync has been updated and now the process of syncing folders is either easier or harder, depending on you viewpoint. There are also some limitation for the free product, like ten folder limit.
  • The machine having a source sync must be on to allow syncing, of course. Not true with a server based sync solution like Dropbox. This is only required while the local and remote folders are syncing of course. In many BTSync articles and blog posts the wrong impression is given that this is a continuous requirement. In fact, as soon as you see the sync complete, if you have the BTSync app visible you can shut down the source machine.
  • Damage is also synced: If one of the synced repos gets damaged, that damage is reproduced in all correlated syncs. This can be prevented by using BTsync’s read only share feature. This would introduce some limitations or other complexities.
  • Repository ignored files are synced
  • There was a discussion on whether the .git folder should be synced. Not sure I follow the rational.
  • I don’t know if there are any issues with BitTorrent Sync for long term work with a Git repo. People have complained of such issues with Dropbox. See the link for Mercurial use on DropBox below. In the comments of that blog post, robhamilton posts: “… found that it would break the Mercurial repo. Mercurial locks files and creates temp journal files which get sync’d by the dropbox daemon. My advice is to stop dropbox, perform your push/commit, then restart dropbox. Pulls and clones are readonly.” Is this an issue with Git? I don’t think so since we are using the bare repo approach.

Updates

    Mobile Git

  • Dec 24, 2013: I did not investigate the mobile Git use with BTSync as shown above. BTSync has a mobile app that allows the sync to mobile devices. On that device a mobile Git client can access the synced bare repo to clone into a mobile local repo. There are now a few mobile Git clients, for example, SGit.
  • June 26, 2015: Bittorrent Sync has an API: BitTorrent Gives Developers A Cloud-Free Alternative.

Some links

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.