Archive for the ‘download’ category

Creating An Overly Simple RSS downloader in Python

February 16th, 2010

I Wrote this script the other day as I was getting more and more annoyed that my version of uTorrent wouldn’t download torrents from torrentbytes for reasons that I still am not sure of. Because of this I created a new script that fits my purpose.

The script is written for the TorrentBytes tracker but you should be able to modify the code to work on other sites too. Anyway here it is

#!/usr/bin/python

#######################################
# RSS Downloader for torrenbytes
# Programmed by Alan MacGregor
#######################################
import os
import sys
from commands import getoutput

###Get Arguments
option = ""
if len(sys.argv) > 1:
 if sys.argv[1] == "-c":
  option =  "check"
 elif sys.argv[1] == "-d":
  option = "download"
else:
 option = "default"

###User Required Variables
cookie_file   = "/home/alan/rss_downloaders/.lynx_cookies"
search_filter = "TV.Show.*720p|" + \
                "Other.TV.Show"
watch_folder  = "/torrent/watch/"
prev_down_loc = "/home/alan/rss_downloaders/torrentbytes_downloaded"
tb_passkey    = "##########################"
tb_username   = "##########################"

def downloadtorrent(torrent_name, link):
 os.system('wget -q --referer=http://www.torrentbytes.net/login.php --cookies=on --load-cookies="' + cookie_file + '" ' + \
           '--keep-session-cookies --save-cookies="' + cookie_file + '" "' + link + '"  -O ' + watch_folder + torrent_name)
 os.system('echo "' + torrent_name + '" >> "' + prev_down_loc + '"')

if option == "download":

 downloadtorrent("Manually_Downloaded_Torrent_File.torrent", sys.argv[2])
 sys.exit()



###Initialise Variables
listoftorrents = ""
previously_downloaded = getoutput('cat ' + prev_down_loc)
rss_feed              = getoutput('curl "http://www.torrentbytes.net/rss.php?passkey=' + tb_passkey + \
                                  '&username=' + tb_username + '&direct" | grep guid').replace("&amp;","&").split("<link>")



for torrent in rss_feed[1:]:
 torrent = torrent.split("</link>")[0].split("\r")

 #fix issue with curl data
 if len(torrent) > 1:
  torrent = torrent[0] + torrent[1].split("\n")[len(torrent) -1]
 else:
  torrent = torrent[0]

 if option == "check":
  print torrent.split("=")[2]

 episodes = search_filter.split("|")
 for episode in episodes:
  items = episode.split("*")
  found = "true"

  for filter in items:
   if filter not in torrent:
    found = "false"

  # Display torrent if all items are matched
  if found == "true":
   listoftorrents = listoftorrents + "|" + torrent

for link in listoftorrents[1:].split("|"):
 if len(link) > 0:
  torrent_name = link.split("&name=")[1]
  if option == "default":
   if torrent_name not in previously_downloaded:
    downloadtorrent(torrent_name)
    print "Downloaded:         " + torrent_name
   else:
    print "Already Downloaded: " + torrent_name
 else:
  print "No Torrents Found in Query"

All you have to do is modify the “###User Required Variables” section along with the cookie file and you should be set. I’d love to here what sites you’ve gotten this to work on plus if you can see where my code might have tried to join the failbus then please leave comments :)

Modifying Apple Propriety Audio Software

January 26th, 2009

So I’m sitting here in the office during my lunch break watch Hak5 (Mad props) and I’m looking for something to do, this is when I realise all of my mp3s on my server and that I need to get them onto iTunes at home. The disadvantage is that im not at home and I’m on a very slow network connection (500k for the whole office!!) so I’ll need something light preferably over ssh. Thats when I remembered Atomic Parsley.

Atomic Parsley is a little unix application (windows available through cygwin) that allows you to edit the metadata inside of the m4a files (note I convert mp3 to m4a with pacpl and don’t start with ‘quality issues’ the audio is for me and no one else). The website explains that the tags inside are now refered by Apple as Atoms and take 4 bytes for each Atom. With this you can modify almost all of the data needed in your collection.

This is particularly useful if like me you have a strict policy on the content in your Library to allow better workings on it, with this you can just drag’n’drop your m4as into the library an itunes will do the rest

Atomic Parsley can be downloaded at http://atomicparsley.sourceforge.net/