Danj Posted November 5, 2006 Report Share Posted November 5, 2006 Supposing you have an RSS feed where the items are posted in a format like:[Fred-Bloggs]_It's_Totally_Legit_to_Download_this_Show_-_12_[DEADBEEF].aviThis format is not compatible with uTorrent's smart episode filter, and also there's a problem if you only want releases of "It's Totally Legit to Download this Show" from the group "Fred-Bloggs". So, I thought it would be useful to create a PHP script which can rewrite the item titles on the fly to conform better to uTorrent's standards (of course, it would be even more ideal if uTorrent could do this itself, and I am hoping that somebody might pass this on to the uTorrent-developers so that it may be implemented in a future version).<?phpif (isset($_GET['feed'])) { $feedurl = rawurldecode($_GET['feed']); $xmlstr = file_get_contents($feedurl);} else { die("Danger! Danger Will Robinson! Feed URL not found!");}$xml = simplexml_load_string($xmlstr);$theChannel = $xml->channel;foreach ($theChannel->item as $theItem) { $inputstring = $theItem->title; $inputstring = iconv("UTF-8", "ISO-8859-1//IGNORE", $inputstring); $tokens = array(); for ($nextToken = strtok($inputstring, "._ "); $nextToken !== false; $nextToken = strtok("._ ")) { $tokens[] = $nextToken; } $groupname = ""; $groupfound = false; $seriesname = ""; $seriesfound = false; $episode = 0; $episodefound = false; $thisToken = ""; for ($i = 0; $i < count($tokens); $i++) { $thisToken = $tokens[$i]; $sqbstart = strpos($thisToken, "["); if ($sqbstart !== false) { $sqbend = strpos($thisToken, "]", $sqbstart); $sqbcontent = substr($thisToken, $sqbstart, $sqbend - $sqbstart + 1); if (!$groupfound) { $groupname = substr($thisToken, $sqbstart + 1, $sqbend - $sqbstart - 1); $groupfound = true; } $tokens[$i] = str_replace($sqbcontent, "", $thisToken); } if (strtolower($thisToken) == "episode" || strtolower($thisToken) == "ep") { $tokens[$i] = ""; } if (substr(strtolower($thisToken), 0, 2) == "ep") { $thisToken = substr($thisToken, 2); $tokens[$i] = $thisToken; } if (($thisToken[0] == '-') || (is_numeric($thisToken))) { if ($thisToken[0] == '-') { $tokens[$i] = ltrim($thisToken, "-"); } if (is_numeric($thisToken) && !$episodefound) { $episode = $thisToken; $episodefound = true; } if (!$seriesfound) { $seriesname = ""; for ($j = 0; $j < $i; $j++) { $seriesname = $seriesname . $tokens[$j] . " "; } $seriesname = trim($seriesname); $seriesfound = true; } } } if ($groupfound && $seriesfound && $episodefound) { $theItem->title = $seriesname . " 1x" . str_pad($episode, 2, "0", STR_PAD_LEFT); }}echo $xml->asXML();?>There are still some titles for which this script does not work, and I have yet to implement group-filtering, but perhaps this script will be helpful to some users on here. It takes one parameter, feed, which needs to be URL-encoded, so for example http://www.notreallyanactualsite.com/feeds/rss.phpwill become http%3A%2F%2Fwww%2Enotreallyanactualsite%2Ecom%2Ffeeds%2Frss%2Ephp(N.B. any web sites, torrent names, file names or group names in this post either do not exist or are entirely hypothetical legitimate entities, as required in order to comply with the Announcement.). Link to comment Share on other sites More sharing options...
splintax Posted November 12, 2006 Report Share Posted November 12, 2006 Nice work. However.. they way I understand it, shouldn't you just be able to use the feature in µT's RSS reader, "Filter matches original name instead of decoded name"? You can then use ? for the underscores. Sounds like you know what you're doing though, am I missing the reason you couldn't use that option? Link to comment Share on other sites More sharing options...
Danj Posted November 12, 2006 Author Report Share Posted November 12, 2006 shouldn't you just be able to use the feature in µT's RSS reader, "Filter matches original name instead of decoded name"? You can then use ? for the underscores."Filter matches original name" disables the smart episode matching capability, so you would have to update the expression for every single episode. Even if you didn't, and simply used wild cards for the episode number, sometimes the torrent naming format can be different (even from the same releaser!) depending on the RSS source or who uploaded the torrent or whatever - for example it's possible that sometimes there is a dash separating series name and episode number and sometimes there isn't, or sometimes the episode number has a leading zero and sometimes it doesn't. What the code I posted is intended to show is that it really isn't that hard to programmatically deal with such erratic naming schemes, in the hope of persuading the uTorrent authors to include it in a future version. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.