Private GIT
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SickRage-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vlbox
SickRage-1
Commits
badc34bd
Unverified
Commit
badc34bd
authored
Jan 20, 2017
by
miigotu
Browse files
Options
Downloads
Patches
Plain Diff
More work on rtorrent lib
Fixes #2934 Fixes #2936
parent
b9d6d81f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/rtorrent/__init__.py
+51
-24
51 additions, 24 deletions
lib/rtorrent/__init__.py
with
51 additions
and
24 deletions
lib/rtorrent/__init__.py
+
51
−
24
View file @
badc34bd
...
...
@@ -41,7 +41,8 @@ __license__ = "MIT"
MIN_RTORRENT_VERSION
=
(
0
,
8
,
1
)
MIN_RTORRENT_VERSION_STR
=
convert_version_tuple_to_str
(
MIN_RTORRENT_VERSION
)
MAX_RETRIES
=
3
MAX_RETRIES
=
5
class
RTorrent
:
...
...
@@ -243,25 +244,46 @@ class RTorrent:
getattr
(
p
,
func_name
)(
magneturl
)
if
verify_load
:
new_torrent
=
None
# Make sure the torrent was added
for
i
in
range
(
MAX_RETRIES
):
time
.
sleep
(
2
)
new_torrent
=
self
.
find_torrent
(
info_hash
)
if
new_torrent
:
break
# Make sure torrent was added in time
assert
new_torrent
,
"
Adding torrent was unsuccessful after {0} seconds (load_magnet).
"
.
format
(
MAX_RETRIES
*
2
)
# Resolve magnet to torrent, it will stop once has resolution has completed
new_torrent
.
start
()
# Set new_torrent back to None for checks below
new_torrent
=
None
# Make sure the resolution has finished
for
i
in
range
(
MAX_RETRIES
):
time
.
sleep
(
1
)
torrent
=
self
.
find_torrent
(
info_hash
)
if
torrent
:
torrent
.
start
()
time
.
sleep
(
2
)
new_torrent
=
self
.
find_torrent
(
info_hash
)
if
new_torrent
and
str
(
info_hash
)
not
in
str
(
new_torrent
.
name
):
break
assert
find_torrent
(
info_hash
,
self
.
torrents
),
"
Adding torrent was unsuccessful (load_magnet).
"
assert
new_torrent
and
str
(
info_hash
)
not
in
str
(
new_torrent
.
name
),
\
"
Magnet failed to resolve after {0} seconds (load_magnet).
"
.
format
(
MAX_RETRIES
*
2
)
# Skip the find_torrent (slow) below when verify_load
return
new_torrent
time
.
sleep
(
3
)
return
self
.
find_torrent
(
info_hash
)
def
load_torrent
(
self
,
torrent
,
start
=
False
,
verbose
=
False
,
verify_load
=
True
):
# @IgnorePep8
def
load_torrent
(
self
,
new_
torrent
,
start
=
False
,
verbose
=
False
,
verify_load
=
True
):
# @IgnorePep8
"""
Loads torrent into rTorrent (with various enhancements)
@param torrent: can be a url, a path to a local file, or the raw data
@param
new_
torrent: can be a url, a path to a local file, or the raw data
of a torrent file
@type torrent: str
@type
new_
torrent: str
@param start: start torrent when loaded
@type start: bool
...
...
@@ -290,32 +312,37 @@ class RTorrent:
looking for, use load_torrent_simple() instead.
"""
p
=
self
.
_get_conn
()
tp
=
TorrentParser
(
torrent
)
torrent
=
xmlrpclib
.
Binary
(
tp
.
_raw_torrent
)
tp
=
TorrentParser
(
new_
torrent
)
new_
torrent
=
xmlrpclib
.
Binary
(
tp
.
_raw_torrent
)
info_hash
=
tp
.
info_hash
func_name
=
self
.
_get_load_function
(
"
raw
"
,
start
,
verbose
)
# load torrent
getattr
(
p
,
func_name
)(
torrent
)
getattr
(
p
,
func_name
)(
new_
torrent
)
if
verify_load
:
new_torrent
=
None
for
i
in
range
(
MAX_RETRIES
):
time
.
sleep
(
1
)
if
self
.
find_torrent
(
info_hash
):
time
.
sleep
(
2
)
new_torrent
=
self
.
find_torrent
(
info_hash
)
if
new_torrent
:
break
assert
find_torrent
(
info_hash
,
self
.
torrents
),
"
Adding torrent was unsuccessful. (load_torrent)
"
assert
new_torrent
,
"
Adding torrent was unsuccessful after {0} seconds. (load_torrent)
"
.
format
(
MAX_RETRIES
*
2
)
# Skip the find_torrent (slow) below when verify_load
return
new_torrent
return
self
.
find_torrent
(
info_hash
)
def
load_torrent_simple
(
self
,
torrent
,
file_type
,
def
load_torrent_simple
(
self
,
new_
torrent
,
file_type
,
start
=
False
,
verbose
=
False
):
"""
Loads torrent into rTorrent
@param torrent: can be a url, a path to a local file, or the raw data
@param
new_
torrent: can be a url, a path to a local file, or the raw data
of a torrent file
@type torrent: str
@type
new_
torrent: str
@param file_type: valid options:
"
url
"
,
"
file
"
, or
"
raw
"
@type file_type: str
...
...
@@ -344,14 +371,14 @@ class RTorrent:
if
file_type
==
"
file
"
:
# since we have to assume we're connected to a remote rTorrent
# client, we have to read the file and send it to rT as raw
assert
os
.
path
.
isfile
(
torrent
),
\
"
Invalid path:
\"
{0}
\"
"
.
format
(
torrent
)
torrent
=
open
(
torrent
,
"
rb
"
).
read
()
assert
os
.
path
.
isfile
(
new_
torrent
),
\
"
Invalid path:
\"
{0}
\"
"
.
format
(
new_
torrent
)
new_
torrent
=
open
(
new_
torrent
,
"
rb
"
).
read
()
if
file_type
in
[
"
raw
"
,
"
file
"
]:
finput
=
xmlrpclib
.
Binary
(
torrent
)
finput
=
xmlrpclib
.
Binary
(
new_
torrent
)
elif
file_type
==
"
url
"
:
finput
=
torrent
finput
=
new_
torrent
getattr
(
p
,
func_name
)(
finput
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment