for example
content equals
item in your code equals
and if you use: thumb=content.xpath('//img').get('src')
then thumb should equal
for example
content equals
thanks on all the help.
i was able to parse it.
i ended up writing it as: drc = content.xpath(’//td[@colspan=“2”]/a’)[1].text
and then later its:
dir.Append(Function(DirectoryItem(PTPTorrent, subtitle=None, summary=“Director: %s” % (drc), title=title, thumb=thumb), thumb=thumb, url=url))
it’s the director name that i just put there.
however, mysteriously now every single item features the same, f.ex. “Director: Roger Rabbit” (bad example i know lol)
it seems to take just the first one and continue to use the same one on all next items in the list that’s created.
…
also i found a bug my mod of the transmission plugin, therefore i need to be able to download a file that is located in the name torrenturl.
what would the code be to make plex download the file to a custom location on the computer? (lets say to a folder called “/torrents” on MacintoshHD.
something like
download def():
………………………
any help?
sorry, i don’t quite understand how to put that into code :blink:
i tried drc = content.xpath(’.//td[@colspan=“2”]/a’)[1].text
with the .//td but i still get always the same result.
for item in content.xpath('.......'):<br />
drc = item.xpath('.//td[@colspan="2"]/a')[1].text<br />
got it to work.
thank you!
do you maybe know if there is a possibiility to download a file inside an url ( is it the variable “print”?)
Can’t you let Transmission handle the .torrent download using the AddTorrent function that’s already present?
https://github.com/plexinc-plugins/Transmission.bundle/blob/master/Contents/Code/init.py#L366
there’s a bug in the transmission webserver where it ignores custom download locations. therefore i wanna just download the .torrent file to a specific folder. can you tell me how?
thanks!
no actually everything works. it’s this Transmission bug (and supposedly there is already a ticket on it)
in transmission you can create groups to download files to certain folders depending on their filename/extension.
this is not funcitonal yet using the webserver.
https://forum.transmissionbt.com/viewtopic.php?f=4&t=11269
i wanna be able to go to the next page of the search results, because only 50 are displayed in each page.
it should appear at the bottom of the search results.
the page links are here in the html:
<div class="linkbox"><a href="torrents.php?page=1"><strong><< First</strong></a> <a href="torrents.php?page=2"><strong>< Prev</strong></a> | <a href="torrents.php?page=1"><strong>1-50</strong></a> | <a href="torrents.php?page=2"><strong>51-100</strong></a> | <strong>101-150</strong> | <a href="torrents.php?page=4"><strong>151-200</strong></a> | <a href="torrents.php?page=5"><strong>201-250</strong></a> | <a href="torrents.php?page=6"><strong>251-300</strong></a> | <a href="torrents.php?page=7"><strong>301-350</strong></a> | <a href="torrents.php?page=8"><strong>351-400</strong></a> | <a href="torrents.php?page=9"><strong>401-450</strong></a> | <a href="torrents.php?page=10"><strong>451-500</strong></a> | <a href="torrents.php?page=11"><strong>501-550</strong></a> | <a href="torrents.php?page=4"><strong>Next ></strong></a> <a href="torrents.php?page=605"><strong> Last >></strong></a></div><br />
for item in content.xpath('//tr[@class="group"]'):<br />
Log(item)<br />
title = item.xpath('./td[contains(@id,"large_groupid_")]/a/img')[0].get('title')<br />
Log(title)<br />
thumb = item.xpath('./td[contains(@id,"large_groupid_")]/a/img')[0].get('src')<br />
url = item.xpath('./td[contains(@id,"large_groupid_")]/a')[0].get('href')<br />
Log(url)<br />
nxt = content.xpath('//a/strong[contains(@text,"Next")]')[0].get('href')<br />
dir.Append(Function(DirectoryItem(PTPTorrent, subtitle=None, title=title, thumb=thumb), thumb=thumb, url=url))<br />
dir.Append(Function(DirectoryItem(PTPTorrent, subtitle=None, title=title, thumb=thumb), thumb=thumb, url= PTPBASE_URL + nxt))<br />
return dir<br />
The right XPath to grab those “Next” link(s) is:
//a/strong[contains(text(), "Next")]/parent::a
yea it shouldn’t be in there, but how else do i do it?
2/22/11 11:28:37 PM com.plexapp.mediaserver[181] TypeError: cannot concatenate ‘str’ and ‘list’ objects
def SearchPassthePopcorn(sender, query, genre):<br />
dir = MediaContainer()<br />
Log("Success!")<br />
if genre != "1" or "2":<br />
pageUrl2 = "http://passthepopcorn.me/torrents.php?order_by=year&" + genre + "searchstr=%s" % (String.Quote(query, usePlus=True))<br />
if genre == "1":<br />
pageUrl2 = "http://passthepopcorn.me/torrents.php?order_by=year&artistname=%s" % (String.Quote(query, usePlus=True))<br />
if genre == "2":<br />
pageUrl2 = "http://passthepopcorn.me/torrents.php?year=%s" % (String.Quote(query, usePlus=True))<br />
Log("Success!")<br />
webpage = HTTP.Request(pageUrl2)<br />
content = XML.ElementFromString(webpage, isHTML=True)<br />
for item in content.xpath('//tr[@class="group"]'):<br />
Log(item)<br />
title = item.xpath('./td[contains(@id,"large_groupid_")]/a/img')[0].get('title')<br />
Log(title)<br />
thumb = item.xpath('./td[contains(@id,"large_groupid_")]/a/img')[0].get('src')<br />
url = item.xpath('./td[contains(@id,"large_groupid_")]/a')[0].get('href')<br />
Log(url)<br />
dir.Append(Function(DirectoryItem(PTPTorrent, subtitle=None, title=title, thumb=thumb), thumb=thumb, url=url))<br />
for item in content.xpath('//div[@class="linkbox"]'):<br />
nxt = item.xpath('./a/strong[contains(text(), "Next")]/parent::a')<br />
dir.Append(Function(DirectoryItem(PTPnextpage, "More Results", subtitle=None, thumb=None), thumb=None, url=PTPBASE_URL + nxt))<br />
return dir<br />
How about something like:
<br />
content = XML.ElementFromString(webpage, isHTML=True)<br />
for item in content.xpath('//tr[@class="group"]'):<br />
Log(item)<br />
title = item.xpath('./td[contains(@id,"large_groupid_")]/a/img')[0].get('title')<br />
Log(title)<br />
thumb = item.xpath('./td[contains(@id,"large_groupid_")]/a/img')[0].get('src')<br />
url = item.xpath('./td[contains(@id,"large_groupid_")]/a')[0].get('href')<br />
Log(url)<br />
dir.Append(Function(DirectoryItem(PTPTorrent, subtitle=None, title=title, thumb=thumb), thumb=thumb, url=url))<br />
next = content.xpath('//div[@class="linkbox"]/a/strong[contains(text(), "Next")]/parent::a')<br />
if len(next) > 0:<br />
dir.Append(Function(DirectoryItem(PTPnextpage, "More Results", subtitle=None, thumb=None), thumb=None, url=PTPBASE_URL + next[0].get('href')))<br />
return dir<br />
thank you! worked!
2 more questions
1. i’m having a lil bit of trouble with replacing in here.
year = item.xpath('./td[@colspan="2"]/child::text()[position()=2]')
[' [1964] by ']
1964
<td colspan="2"><br />
<a href="torrents.php?id=2057" title="View Torrent">MOVIE TITLE</a> [1961] by <a href="artist.php?id=784">DIRECTOR</a> <br />
<br />
<td colspan="2"><br />
<a href="torrents.php?id=2057" title="View Torrent">MOVIE TITLE</a> [1961] by <a href="artist.php?id=784">DIRECTOR</a> <br />
<br />
<td colspan="2"><br />
<a href="torrents.php?id=2057" title="View Torrent">MOVIE TITLE</a> [1961] <br />
<br />
<td colspan="2"><br />
<a href="torrents.php?id=2057" title="View Torrent">MOVIE TITLE</a> [1961] by <a href="artist.php?id=17153">DIRECTOR 1</a> and <a href="artist.php?id=17344">DIRECTOR 1</a> <br />
Quickly, I’m running out.
For 1. use the xpath you have and the python string split commands to extract the data you want.
For 2. use the same xpath but loop through the results and build whatever string you need to represent all the directors.
You don’t have to use xpath for everything, python has a lot of powerful string processing functions
Jonny
that sounds great, only that i have even less knowledge of python than of xpath.
could you give me an example code?
pooplooser,
Google some stuff. You’re being given a huge leg up over a lot of people when they first program their first plugins. If someone mentions some command you don’t know, try typing it in google. Maybe even add the word “example” to your search, like this. While I understand it is a lot easier to ask for a more specific example on the boards, there are a lot of well thought out and written examples of some things you are asking on the web. Don’t be afraid to search, or that you may not understand what is out there. That’s ok. Give it a go though, and you’ll gain a better understanding of what you’re writing and be able to make plugins faster.
3. An Informal Introduction to Python — Python 3.12.1 documentation
http://www.devshed.com/c/a/Python/String-Manipulation/
<br />
year = item.xpath('./td[@colspan="2"]/child::text()[position()=2]').strip()<br />
tokens = year.split()<br />
actualYearWithBrackets = tokens[0]<br />
actualYear = actualYearWithBrackets [1:-1]<br />